Skip to content

fix(security): output masking reads the prose 'token: <word>' as a secret and rewrites error text #2613

Closed

Description

@dan-petty

Problem Description

The output masking of devops-cli rewrites prose that has the word token followed by a colon and a word of 8 or more characters. It reads the prose as a secret assignment and replaces the word with token=<masked-token>, which changes the message and hides its cause.

The rule is the token|auth_token pattern of src/devops_cli/security/sanitizer.py (\b(?:token|auth_token)\s*[:=]\s*["']?(?P<value>[^\s"',;]{8,})). It matches the error text of a registry client: buildx writes failed to fetch oauth token, then a colon, then unexpected status from GET request to https://ghcr.io/...: 403 Forbidden. The pattern takes unexpected as the value.

Reproduction Steps

  1. Run a devops command whose output holds that buildx error, for example devops k8s image-pins (test(k8s): every image pin under k8s/ resolves in its registry before the merge #1994) with a stored Docker credential that GHCR refuses.
  2. Read the printed error.

Expected vs Actual Behavior

  • Expected: the error prints as the tool wrote it, with the colon and the word unexpected. The text holds no secret.
  • Actual: the colon and the word unexpected are replaced with an equals sign and the masked-token marker, and the printed message no longer says what failed.

Environment Diagnostics

origin/main a95992aa (2026-10-29).

Logs, Traces, or Terminal Output

The ✗ line of devops k8s image-pins in the #1994 measurement, for 5 GHCR images. The same detection also refused the first draft of this issue in devops roadmap intake ("The candidate's body holds what looks like a secret"), because the draft quoted the buildx error.

Existing Tool Considered

The masking already falls back to a literal match. A secret scanner's rule set (detect-secrets or gitleaks keyword rules with entropy) tells a prose word from a token by entropy; the fix may require entropy or a value shape for this one pattern, as the rules for keys already do.

Proposed design

Problem statement

The output masking in devops-cli rewrites prose that contains the word "token" followed by a colon and a common English word of 8 or more characters. The token|auth_token regex in src/devops_cli/security/sanitizer.py matches this prose as a secret assignment and replaces the word with a masked-token marker. This corrupts error messages and hides their cause. The same defect exists in the password|passwd|pwd pattern, which shares the same replacement function.

Acceptance criteria

Requirement: Prose word after token colon is not masked

The token|auth_token pattern SHALL not rewrite a value that does not look like a credential.

Scenario: prose word after token colon

  • WHEN the input text contains "token: unexpected"
  • THEN the output preserves "token: unexpected" unchanged

Requirement: Credential after token colon is still masked

The token|auth_token pattern SHALL rewrite a value that looks like a credential.

Scenario: credential after token colon

  • WHEN the input text contains "token: abc123def456ghi789jkl012"
  • THEN the output replaces the value with "token="

Requirement: Prose word after password colon is not masked

The password|passwd|pwd pattern SHALL not rewrite a value that does not look like a credential.

Scenario: prose word after password colon

  • WHEN the input text contains "password: unexpected"
  • THEN the output preserves "password: unexpected" unchanged

Requirement: Other secret patterns are unaffected

The fix SHALL not change the masking behavior of other secret patterns.

Scenario: GitHub token is still masked

  • WHEN the input text contains "ghp_abc123def456ghi789jkl012"
  • THEN the output replaces it with ""

Existing Tool Considered

No check has run. The fix is a bug fix in the project's own sanitizer. The project already has the _looks_like_a_credential heuristic in src/devops_cli/security/sanitizer.py. The fix applies that heuristic to the token|auth_token and password|passwd|pwd patterns. The written cost is changing two replacement lambdas and adding test cases.

Key questions

  • How should the token|auth_token pattern distinguish a prose word from a credential?: Apply the existing _looks_like_a_credential check to the pattern's replacement. A value is a credential if it is 24 or more characters, contains a digit or a separator, or has an internal capital. A prose word like "unexpected" matches none of these and is left unchanged. (best practice) [sources: src/devops_cli/security/sanitizer.py]
    • Chosen: Apply _looks_like_a_credential to the pattern. The heuristic already exists in the codebase and is used by the last pattern in the list. It correctly distinguishes prose words from tokens.
    • Rejected: Add entropy calculation to the pattern. More complex than needed. The existing heuristic already handles the reported case and is simpler to test.
    • Rejected: Increase the minimum value length in the regex. Would miss short but valid tokens that contain digits or separators. The heuristic is more precise.
  • Should the password|passwd|pwd pattern also be fixed?: Yes. It uses the same _mask_literal function and has the same false positive. The fix applies the same _looks_like_a_credential check to both patterns. (best practice) [sources: src/devops_cli/security/sanitizer.py]
    • Chosen: Fix both patterns. They share the same replacement function and the same false positive. Fixing one without the other leaves the same bug.
    • Rejected: Fix only the token pattern. The issue names the token pattern, but the password pattern has the same defect. Leaving it unfixed would require a second issue.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-04: none.
Tool: none found.

Activity

  1. added
    source/agent
    type/bug
    status/new
    value/medium
    effort/low
    on Oct 29, 2026
  2. dan-petty commented on Oct 29, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. A defect in existing security masking code that corrupts legitimate error text.
    • Priority: P2-Medium. It hides the cause of a failure in printed errors, which slows debugging, but does not expose secrets or break the tool.
    • Value: Medium. Users lose the real error message, which reduces their ability to diagnose buildx or registry failures.
    • Effort: Low. The fix is a constraint on one regex pattern, possibly adding an entropy or shape check already used by other rules.
    • Related: fix(security): a credential keyword at the end of a line no longer masks the first word of the next line #2450, which asks for a different change. Both are false-positive bugs in the token keyword pattern in sanitizer.py, but #2450 is about a line-break in \s+ and the candidate is about the [:=] separator matching a colon in prose.
  3. added
    priority/p2-medium
    scope/security
    on Oct 29, 2026
  4. added
    status/ready
    and removed
    status/new
    on Oct 30, 2026
  5. devops-cli-service commented on Oct 30, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 07fb4c2 (see proposed design in issue body).

  6. devops-cli-service commented on Nov 4, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Tool: none found

    Lacks:

    • detect-secrets scans code and configuration for secret candidates and reports findings; it does not mask or rewrite a program's runtime or error output
    • detect-secrets' keyword plugins use entropy and value-shape rules to decide whether a candidate is a secret, but they return a verdict/finding rather than a redacted string, so it would not replace the sanitizer's replacement step
    • gitleaks scans git repositories, commits and files for leaked secrets; it does not redact arbitrary text at runtime
    • neither tool provides the specific token:/password: prose-versus-credential decision that the sanitizer's patterns need, so the fix remains in the project's own sanitizer using its existing credential heuristic

    Searches run:

    • python library detect secrets in text with entropy keyword rules
    • redact mask secrets in log text python library
    • library that redacts secrets from arbitrary text output preserving non-secret words

    Sources:

    Checked on 2026-11-04. A person decides what this means for the item. The check changes no label and closes no issue.

  7. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 5, 2026
  8. removed
    status/in-review
    on Nov 5, 2026
  9. devops-cli-service commented on Nov 5, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-05 16:42 UTC

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

    effort/lowpriority/p2-mediumscope/securitysource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions