Skip to content

feat: mask sensitive keys in events - #62

Merged
naji247 merged 2 commits into
mainfrom
feat/mask-sensitive-keys
Nov 26, 2026
Merged

naji247 merged 2 commits into
mainfrom
feat/mask-sensitive-keys

Conversation

@naji247

@naji247 naji247 commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Summary

EventQueue._process_event()                    src/agentcat/modules/event_queue.py
├── redact_event / apply_event_redaction      customer hooks
├── sanitize_event()
├── _mask_event(event)                        NEW: parameters, response, error
│   ├── pydantic_core.to_jsonable_python()    same conversion as truncation
│   └── mask_sensitive_keys()                 NEW src/agentcat/modules/sensitive_keys.py
└── truncate_event()
→ AgentCat API (publish_event) and every telemetry exporter

Evidence

  • Before: the e2e test test_redaction_can_scrub_authorization_header_in_extra showed that the sent event carried parameters.extra.requestInfo.headers.authorization as received unless a redaction hook rewrote it, and test_http_simulated_path_populates_headers asserted the raw _meta.progressToken (tok-7).
    After: test_pipeline_masks_request_headers_and_typed_values sends a real Starlette Request through the queue. The API body and the exporter both carry [redacted] for authorization, cookie and x-api-key, keep user-agent, x-anthropic-client and mcp-session-id, and the Request keeps 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 clean origin/main.

  • Before: tests/test_server_info.py::test_v10_the_build_gives_the_loop_a_turn_before_each_page failed on Python 3.10 and 3.11, also on main: the turns were other, other, page, other, page, page. Before 3.12, asyncio.wait_for runs 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 -q on 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 the asyncio.sleep(0) in _collect is 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 as pageToken, api_key or auth_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.

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.
@naji247
naji247 merged commit bcdeef9 into main Nov 26, 2026
56 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants