Skip to content

fix(security): a credential value is masked also when the next line starts with a parenthesis #2471

Description

@dan-petty

Problem Description

redact_text in src/devops_cli/security/sanitizer.py does not mask a credential value when the line after it starts with (. The api_key, access_token, bearer_token and auth_token rule ends with the call check (?!\s*\(). In Python, \s also matches a line break. Thus, the check reads past the end of the line, and the first character of the next line (or of a later line, after blank lines) decides the result for the current line. When that character is (, the rule does not match, and the secret stays in clear text.

The requirement "A credential keyword and its value sit on one line" of the secret-masking spec says that the value comes only from the same line. #2450 changed the other keyword-to-value patterns, but kept this check as it was.

The review of #2461 also found gaps in the tests of #2450:

  • No test puts a line break between a keyword and its separator, such as password on one line and : <value> on the next line. Each of the five rules for password, token, aws_secret_access_key, client_secret and api_key can go back to \s before the separator, and all tests still pass. The same is true for the \btoken alternative of the secret_ rule.
  • No test joins a one-line pair with a tab or a no-break space. If each [^\S\r\n] becomes [ ], all tests still pass, but password: followed by a no-break space and a value is no longer masked.
  • The one-line test does not compare the whole result with an expected value (docs/TESTING.md). A change to the replacement text of a rule still passes.

Reproduction Steps

  1. Run uv run python -c 'from devops_cli.security.sanitizer import redact_text; print(repr(redact_text("api_key: " + "Zq8xW2mN" * 3 + "\n(rotated monthly)")))'.
  2. Run the same command with "\nrotated monthly" in place of "\n(rotated monthly)".

Expected vs Actual Behavior

Expected: the two commands give api_key=<masked-api-key> on the first line, and keep the second line unchanged.

Actual: step 2 masks the value. Step 1 returns the input unchanged, with the 24-character value in clear text. The same occurs with access_token= and two line breaks before (next paragraph), in data and code syntax.

Environment Diagnostics

  • DevOps CLI version: 0.9.0 (main at 8b650a6)
  • Python version: 3.14
  • OS: Linux x86_64
  • Execution environment: DevContainer

Pre-Submission Checklist

  • I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
  • I have checked existing issues and pull requests to ensure this is not a duplicate.

Source: #2461

Activity

  1. added
    source/agent
    type/security
    status/new
    value/medium
    effort/low
    on Oct 28, 2026
  2. dan-petty commented on Oct 28, 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/security. A credential value is left unmasked in output, which is a security gap.
    • Priority: P2-Medium. A real credential leak, but only when the next line starts with a parenthesis.
    • Value: Medium. Prevents a narrow but real credential leak in masked output.
    • Effort: Low. A single regex lookahead needs to stop at line boundaries instead of matching \s.
    • 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 fix line-break leakage in the same sanitizer regex, but #2450 fixed the keyword-to-value separator and this fixes the negative lookahead after the value.
  3. added
    priority/p2-medium
    on Oct 28, 2026
  4. added 2 commits that reference this issue on Oct 28, 2026
    ece25ca
    5064f31
  5. removed
    status/new
    on Oct 30, 2026
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-mediumsource/agenttype/securityvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions