Repository navigation
Conversation
redact_sensitive_text masks Authorization and x-api-key / api-key style headers (the 6f0ecf3 threat model: a logged request or echoed curl leaking live credentials), but Cookie / Set-Cookie headers were left untouched — so a session token (an account-takeover credential) leaks verbatim into logs, transcripts, and tool output. Add a Cookie/Set-Cookie rule alongside the existing header rules: mask each cookie value via _mask_token (the same masker used for Authorization/x-api-key) while preserving cookie names and the non-secret Set-Cookie attributes (Path/Domain/Expires/Max-Age/SameSite + HttpOnly/Secure flags). The value run stops at end-of-line or a closing quote so an inline `curl -H 'Cookie: …' URL` doesn't swallow the trailing URL. Adds 3 tests; all fail without the rule.
|
Duplicate of #50514 — same Cookie/Set-Cookie session-token masking in |
|
Quick repro against current >>> redact_sensitive_text("Cookie: sessionid=abcdef123456SECRET7890; csrftoken=xyz", force=True)
'Cookie: sessionid=abcdef123456SECRET7890; csrftoken=xyz' # ← session token leaks verbatim
>>> redact_sensitive_text("authorization: Bearer sk-x", force=True)
'authorization: Bearer ***' # already masked by 6f0ecf37dThis is a direct follow-up to 6f0ecf3 — same threat model (a logged request / echoed It's one self-contained rule mirroring the existing header logic (mask the value via CI hasn't been able to run yet (first-time contributor) — whenever a maintainer has a moment, could the workflows be approved here? Happy to adjust scope or rebase. Thanks! |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for addressing a real raw-header redaction gap: current main bb5fc723b67c still applies only Authorization and API-key header rules at agent/redact.py:595-610.
Problems
agent/redact.py:158excludes quote characters from the header payload. ForCookie: sid="opaque", the match stops aftersid=;_COOKIE_PAIR_REat line 161 then has no value to mask, leaving the opaque token unredacted. Please cover quoted cookie values while preserving the outer curl quotation behavior.- This PR does not cover JSON-serialized
"Cookie": "..."headers. Current main's JSON key matcher is atagent/redact.py:177-181; Cookie is absent there. The duplicate discussion correctly points to #50514, whose diff includes that sibling request-dump representation.
Suggested changes
- Add quoted-cookie regression cases and adjust the matcher accordingly.
- Consolidate the JSON-header path with the broader #50514 approach so both representations are protected.
Automated hermes-sweeper review.
| # Header value runs to end-of-line or a closing quote (so an inline | ||
| # ``curl -H 'Cookie: …' https://host`` doesn't swallow the trailing URL). | ||
| _COOKIE_HEADER_RE = re.compile( | ||
| r"((?:Set-)?Cookie:\s*)([^\r\n'\"]+)", |
There was a problem hiding this comment.
This excludes a quote at the start of a cookie value. Cookie: sid="opaque" therefore matches only sid=, so _COOKIE_PAIR_RE receives no value to mask and opaque remains outside the replacement. Please distinguish quoted cookie values from the outer curl-command quote and add a regression.
Summary
Follow-up to
6f0ecf37d("mask all Authorization schemes and x-api-key style headers").redact_sensitive_textmasksAuthorization/Proxy-Authorizationand thex-api-key/api-keyheader family — the threat model that commit names is a logged request or echoedcurlleaking live credentials. ButCookie/Set-Cookieheaders were left untouched, so a session token — an account-takeover credential — leaks verbatim into logs, transcripts, and tool output.Reproduced against current
main:Cookiecarries arbitrarily many secret pairs (sessionid,csrftoken, auth tokens);Set-Cookiecarries the cookie plus non-secret attributes (Path,HttpOnly, …). Neither is covered by the Authorization or x-api-key rules, andcookieis not in the JSON/query secret-key set.Fix
Add a Cookie/Set-Cookie rule alongside the existing header rules. It masks each cookie value via
_mask_token(the same masker used for Authorization/x-api-key, so the partial-reveal policy is consistent) while preserving cookie names and the non-secretSet-Cookieattributes (Path/Domain/Expires/Max-Age/SameSite + the HttpOnly/Secure flags) for debuggability. The value run stops at end-of-line or a closing quote so an inlinecurl -H 'Cookie: …' https://hostdoesn't swallow the trailing URL.After the fix:
Tests
tests/agent/test_redact.py::TestCookieHeaders— Cookie multi-pair masking (names preserved), Set-Cookie value masked with attributes preserved, and a curl-command case (URL preserved). All three fail without the rule; the full suite (85 tests) passes with it.