Skip to content

security: token-leak bug in canonical redaction package (Z-050) #922

Closed

Description

@PierrunoYT

Description

There is a logic gap in the canonical redaction package's
ormalizeKey function that leads to sensitive tokens leaking into logs and other outputs. The current normalization logic splits keys only on non-alphanumeric characters.

As a result, keys using camelCase (e.g., �ccessToken,
efreshToken, �piKey) are normalized to a lowercase string without delimiters (e.g., �ccesstoken,
efreshtoken). If the sensitiveKeys list—which the package uses to identify what needs redaction—expects a different normalization or uses specific matches that don't align with this simplistic alphanumeric split, these tokens are not flagged for redaction.

Impact

High-entropy secrets (API keys, OAuth tokens) may be written to disk in logs or displayed in the TUI/CLI output. This exposes credentials to any process or user with access to the logs, significantly increasing the risk of credential theft.

Recommended Fix

The normalization logic needs to be more sophisticated to recognize common programming naming conventions:

  1. CamelCase Splitting: Modify
    ormalizeKey to treat transitions from lowercase to uppercase as delimiters (e.g., �ccessToken $\rightarrow$ �ccess_token).
  2. Unified Registry: Unify the normalization logic between the code that detects keys in the stream and the registry of sensitiveKeys to ensure a consistent match.
  3. Broaden Heuristics: Consider adding specific high-confidence patterns for common token formats if normalization proves insufficient.

Activity

  1. gnanam1990 commented on Aug 24, 2026

    @gnanam1990
    Collaborator

    Reproduced locally on main. Confirmed, and the end-to-end impact is worse than the report claims — an opaque refresh token leaks verbatim.

    The mechanism, verified

    normalizeKey (internal/redaction/redaction.go:406-422) splits only on non-alphanumeric runes, so a camelCase boundary produces no delimiter. The registry (redaction.go:33-58) stores the underscored spellings. They cannot meet:

    normalizeKey("accessToken" ) = "accesstoken"    IsSensitiveKey=false
    normalizeKey("access_token") = "access_token"   IsSensitiveKey=true
    normalizeKey("refreshToken") = "refreshtoken"   IsSensitiveKey=false
    normalizeKey("clientSecret") = "clientsecret"   IsSensitiveKey=false
    normalizeKey("idToken"     ) = "idtoken"        IsSensitiveKey=false
    normalizeKey("authToken"   ) = "authtoken"      IsSensitiveKey=false
    normalizeKey("githubToken" ) = "githubtoken"    IsSensitiveKey=false
    

    Seven of eight camelCase spellings are unrecognised. apiKey is the sole survivor, and only by accident — apikey happens to be in the registry as a delimiter-free entry, so it is not evidence the mechanism works.

    The leak, end to end

    RedactValue on the shape an OAuth provider actually returns:

    camelCase  -> {"accessToken":"[REDACTED]",
                   "clientSecret":"cs_live_abcdef0123456789",
                   "idToken":"header.payload.signature",
                   "refreshToken":"1//0eXaMpLeOpaqueRefreshTokenValue0123456789"}
    
    snake_case -> {"access_token":"[REDACTED]","client_secret":"[REDACTED]",
                   "id_token":"[REDACTED]","refresh_token":"[REDACTED]"}
    

    Identical data. The only difference is the key spelling.

    The part that makes this worse than "some keys are missed"

    accessToken came out redacted — but not because the key was recognised. Its value was sk-ant-api03-…, which the shape matcher catches on its own. The refreshToken value is opaque (1//0eXaMpLe…, the Google refresh-token shape) and has no matchable structure, so with the key unrecognised there was nothing left to save it.

    That inverts the usual reasoning about defence in depth here: key-based redaction matters most for exactly the secrets shape-matching cannot see. The current gap fails on the class it is most needed for, and the passing accessToken case makes the failure look narrower than it is.

    camelCase is not an unusual spelling — it is what OAuth and OIDC responses use, and what Go's encoding/json produces from an unannotated struct.

    What I did not check

    Which call sites actually feed provider payloads through RedactValue, so I cannot say how far a leaked token travels in practice — only that redaction does not stop it. I also did not survey ExtraSensitiveKeys usage, which would mask this for any caller that happens to pass camelCase spellings explicitly.

    The report's suggested fix (splitting on lower→upper transitions) resolves all seven above; the registry then needs no new entries, which also avoids the two-lists-that-must-agree problem.

  2. added
    issue-approved
    on Aug 24, 2026
  3. added a commit that references this issue on Sep 12, 2026
    08fbea7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue-approved

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions