fix(agent): redact secrets in request_dump_*.json files#18750
Open
Tranquil-Flow wants to merge 2 commits into
Open
fix(agent): redact secrets in request_dump_*.json files#18750Tranquil-Flow wants to merge 2 commits into
Tranquil-Flow wants to merge 2 commits into
Conversation
Collaborator
Collaborator
8d59465 to
0b2c834
Compare
0b2c834 to
3bc64fc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
_dump_api_request_debug()writes~/.hermes/sessions/request_dump_*.jsoncontaining the live request body, headers, and provider error response. Two leak channels existed:_mask_api_key_for_logs(), which keepskey[:8]andkey[-4:]visible — enough to recognise ansk-proj-*prefix in a shared bug report. Tightened toBearer ***.error.body,error.response_textwere written raw. Pasted credentials in user messages, keys quoted back in 401 bodies, and any other in-payload secret survived to disk unredacted.The agent already ships
agent/redact.pywith regex coverage for every known provider key prefix andENV=value/ JSON-field assignment patterns — it just wasn't wired into this path.This PR walks
dump_payloadrecursively and appliesredact_sensitive_text(value, force=True)to leaf string values before serialisation. Walking the structure (rather than the serialised text) is important:_ENV_ASSIGN_RE's greedy\S+value group can otherwise consume past a JSON string's closing quote and corrupt the file. Operating on individual values keeps every regex bounded to a single string.force=Truebecause this is a security boundary, not a logging preference: the dump must be safe regardless of the user's globalsecurity.redact_secretssetting.This makes
request_dump_*.jsonsafe to attach to a GitHub issue or include in atar -czf hermes.tar.gz ~/.hermessupport bundle.Related Issue
Fixes #18707
Type of Change
Changes Made
run_agent.py::_dump_api_request_debug— drop the_mask_api_key_for_logs(api_key)Authorization construction (and the now-unusedapi_keyextraction); hard-codeBearer ***; recursively scrub leaf string values viaredact_sensitive_text(force=True)beforejson.dumps; reuse the serialised string for both file write and the optional stdout echotests/run_agent/test_run_agent_codex_responses.py— add 5 redaction tests:test_dump_redacts_sk_proj_key_in_authorization_headertest_dump_redacts_keys_embedded_in_request_bodytest_dump_redacts_keys_in_error_response_texttest_dump_preserves_non_secret_metadatatest_dump_remains_valid_json_after_redaction(regression for theOPENAI_API_KEY=sk-proj-...in body case that, with text-level redaction, would have produced unparseable JSON)How to Test
python -m pytest tests/run_agent/test_run_agent_codex_responses.py -k dump -q— 7/7 pass (5 new + 2 existing URL tests)python -m pytest tests/run_agent/test_run_agent_codex_responses.py -q— full file 64/64 passOPENAI_API_KEYto a valid-format-but-revoked key, send any chat message; inspect the resultingrequest_dump_*.json— Authorization showsBearer ***, message bodies with embeddedsk-...strings show masked tokens, andjson.loads(open(dump_file).read())succeedsChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs