Repository navigation
feat: mask sensitive keys in events - #62
Merged
Merged
Conversation
Add sensitive_keys.py, a port of the shared reference, and call it once in the event queue after redaction and sanitization and before truncation. It masks the values of secret keys in parameters, response and error, so request headers such as authorization and cookie leave the server as [redacted]. A field that cannot be masked is dropped and the event is sent without it.
The test asserted the exact order of loop turns, which holds only on Python 3.12 and later. Before 3.12, asyncio.wait_for runs the awaited coroutine in a task of its own, and that costs one more turn of the loop per page. The test now asserts the property itself: other work runs right before each page. CI runs Python 3.12 only, so it never showed the failure.
kashishhora
approved these changes
Nov 26, 2026
Merged
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.
Summary
Evidence
Before: the e2e test
test_redaction_can_scrub_authorization_header_in_extrashowed that the sent event carriedparameters.extra.requestInfo.headers.authorizationas received unless a redaction hook rewrote it, andtest_http_simulated_path_populates_headersasserted the raw_meta.progressToken(tok-7).After:
test_pipeline_masks_request_headers_and_typed_valuessends a real StarletteRequestthrough the queue. The API body and the exporter both carry[redacted]forauthorization,cookieandx-api-key, keepuser-agent,x-anthropic-clientandmcp-session-id, and theRequestkeeps the raw values. The vectors test checks all 233 key cases and 17 tree cases.uv run --no-sync pytest: modern (mcp 2.3.0) 1262 passed, 27 skipped, 1 failed; legacy (mcp 1.30.0) 1410 passed, 17 skipped, 1 failed. The one failure,test_server_info.py::test_v10_the_build_gives_the_loop_a_turn_before_each_page, fails the same way on a cleanorigin/main.Before:
tests/test_server_info.py::test_v10_the_build_gives_the_loop_a_turn_before_each_pagefailed on Python 3.10 and 3.11, also onmain: the turns wereother, other, page, other, page, page. Before 3.12,asyncio.wait_forruns the fetch in a task of its own, which costs one more turn of the loop. CI runs 3.12 only.After: the second commit changes the test to assert the property (other work runs right before each page).
uv run --no-sync pytest -qon Python 3.11: 1263 passed, 27 skipped, 0 failed. The same logic passes on 3.10, 3.11, 3.12 and 3.13, and on 3.12 and 3.13 it still fails when theasyncio.sleep(0)in_collectis removed.Merge Danger
Door: one-way
Events sent before the merge keep their raw headers, and masked values cannot come back.
Blast Radius: wide
Every event now shows
[redacted]for credential headers,_meta.progressToken, and tool arguments or results under secret key names such aspageToken,api_keyorauth_type. A dashboard view or customer query that read those values gets[redacted]. If a field cannot be masked, the event arrives without that field. No option turns the mask off.