Skip to content

fix(redact): preserve code syntax around auth header redaction (#33801) - #52172

Closed
Tranquil-Flow wants to merge 1 commit into
NousResearch:mainfrom
Tranquil-Flow:fix/33801-auth-redact-syntax-corruption
Closed

fix(redact): preserve code syntax around auth header redaction (#33801)#52172
Tranquil-Flow wants to merge 1 commit into
NousResearch:mainfrom
Tranquil-Flow:fix/33801-auth-redact-syntax-corruption

Conversation

@Tranquil-Flow

Copy link
Copy Markdown
Contributor

What

The \S+ greedy capture in _AUTH_HEADER_RE and _SECRET_HEADER_RE was consuming trailing code delimiters (quotes, braces, brackets, parens) when masking credential tokens. When _mask_token replaced the match, those delimiters vanished, corrupting surrounding code syntax in tool output.

Fix

Replace \S+ with _TOKEN_CHARS = r"[^\s\"'<>{}\[\]()\\,;]+" — matches everything \S+ would except common code-syntax delimiters, so redaction stops at the delimiter and the credential is still masked.

Layers addressed (all tested)

  1. Bearer token closing-quote corruption
  2. Basic auth closing-quote corruption
  3. Proxy-Authorization closing-quote corruption
  4. x-api-key / api-key header closing-quote corruption
  5. Dict-literal brace corruption ({X: "Authorization: Bearer <tok>"})
  6. code_file=True mode still redacts but preserves delimiters

Verification

  • Fail-without-fix: 7 of 10 new tests fail on unpatched code (closing quotes consumed by \S+)
  • With fix: all 92 tests pass (10 new + 82 existing)
  • Redaction still works correctly in plain log lines (no surrounding delimiters)

Competitor PRs

This PR fixes the root regex cause; the competitor approaches address different symptoms (ENV-assignment and JSON-field corruption).

Auto-published by Moonsong via Path B automated pipeline.

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data labels Jun 24, 2026
…esearch#33801)

The \S+ greedy capture in _AUTH_HEADER_RE and _SECRET_HEADER_RE
consumed trailing code delimiters (quotes, braces, brackets, parens)
along with credential tokens. When _mask_token replaced the entire
match with ***, those delimiters vanished, corrupting surrounding code
and causing SyntaxError in generated code.

Fix: replace \S+ with a _TOKEN_CHARS character class that matches
everything except common code-syntax delimiters, so redaction stops
cleanly at quotes, braces, brackets, etc.

10 new regression tests cover short/long tokens, Bearer/Basic/Proxy-Auth
schemes, api-key/x-api-key headers, dict braces, and code_file mode.
All 92 existing redact tests still pass.
@teknium1

Copy link
Copy Markdown
Contributor

Closing as part of the #33801 secret-redaction-corrupts-code cluster, fixed at the root in #54061 (merged: 674e16e).

The real defect was _DB_CONNSTR_RE's password group matching greedily across newlines, corrupting displayed tool output (read_file/terminal/execute_code) for any source containing a postgresql:// f-string template. The fix forbids whitespace in the userinfo/password groups so the match can't span a line, preserves brace-only template passwords under code_file=True, and passes code_file=True at the terminal/execute_code output sites. Thanks for the contribution to this area.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants