Skip to content

Path-traversal in k8s/iam/cloudflare sanitizeFilename — replace with safeSlug whitelist #23

@rafeegnash

Description

@rafeegnash

Problem

The sanitizeFilename helpers in k8s/iam/cloudflare history map slashes, backslashes, colons, glob chars, quotes, angle brackets, pipes, and spaces to _ — but they let . through. A clusterName/accountID/zone of .. (or controlled via a flag like --cluster ../../etc/passwd) resolves through filepath.Join to a path outside ~/.clanker/conversations. Sentry/Linear/Notion use the right model: a whitelist [A-Za-z0-9_-] via their safeSlug helper.

Where

  • internal/k8s/conversation.go:245
  • internal/iam/conversation.go:214
  • internal/cloudflare/conversation.go:219

Fix

Replace the replacer with the whitelist pattern from sentry/linear/notion safeSlug:

func safeSlug(s string) string {
    out := make([]byte, 0, len(s))
    for i := 0; i < len(s); i++ {
        c := s[i]
        switch {
        case c >= 'a' && c <= 'z',
            c >= 'A' && c <= 'Z',
            c >= '0' && c <= '9',
            c == '-' || c == '_':
            out = append(out, c)
        }
    }
    if len(out) == 0 {
        return "default"
    }
    return string(out)
}

Better: extract into internal/convhistory.SafeSlug (separate issue) — this ticket should just port the existing one.

Acceptance criteria

  • Test cases:
    • ..default
    • ../../etc/passwdetcpasswd
    • my-cluster.devmy-clusterdev
    • empty → default
  • All three call sites use the same helper (consider a small shared package)
  • An attempt to use --cluster ../foo does NOT write outside ~/.clanker/

Labels

bug, security

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: criticalMust fix immediately - security or data loss risksecuritySecurity vulnerability

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions