Mask one-time OAuth values in FastMCP OAuth proxy logs (0.1.1-dev.4) #108

Merged
john merged 1 commit from fix/oauth-proxy-log-redaction into main 2026-11-26 03:52:23 +00:00
Owner

0.1.1-dev.3 redacted the access log, but a live test callback (fake code/state) still showed the state in the server log:

ERROR    IdP callback with invalid transaction ID: <state value>   proxy.py:2724

FastMCP 4.1.3's OAuth proxy logs the transaction ID (= the returned state) at ERROR for stale or forged callbacks, and authorization codes/transactions at DEBUG.

  • OAuthProxySecretFilter on fastmcp.server.auth.oauth_proxy.proxy masks the arguments of exactly those messages (IdP callback with invalid transaction ID, Transaction %s missing consent_token, Authorization code not found/expired) and the f-string Forwarding to client callback for transaction …. Other messages (refresh-token prefixes, upstream errors) unchanged.
  • Installed at server start next to the uvicorn access filter; logger-level, so it runs before FastMCP's rich handler and survives its handler reconfiguration.
  • Tests: per-message masking, untouched messages, and the real FastMCP logger object. 7 new tests fail without the filter; full suite 554 passed, host tests OK.

0.1.1-dev.4, no API change.

0.1.1-dev.3 redacted the access log, but a live test callback (fake `code`/`state`) still showed the `state` in the server log: ``` ERROR IdP callback with invalid transaction ID: <state value> proxy.py:2724 ``` FastMCP 4.1.3's OAuth proxy logs the transaction ID (= the returned `state`) at ERROR for stale or forged callbacks, and authorization codes/transactions at DEBUG. - `OAuthProxySecretFilter` on `fastmcp.server.auth.oauth_proxy.proxy` masks the arguments of exactly those messages (`IdP callback with invalid transaction ID`, `Transaction %s missing consent_token`, `Authorization code not found/expired`) and the f-string `Forwarding to client callback for transaction …`. Other messages (refresh-token prefixes, upstream errors) unchanged. - Installed at server start next to the uvicorn access filter; logger-level, so it runs before FastMCP's rich handler and survives its handler reconfiguration. - Tests: per-message masking, untouched messages, and the real FastMCP logger object. 7 new tests fail without the filter; full suite 554 passed, host tests OK. 0.1.1-dev.4, no API change.
fix(log): mask one-time OAuth values in FastMCP OAuth proxy records (0.1.1-dev.4)
All checks were successful
Corn CI / host (pull_request) Successful in 13s
Corn CI / release-check-1 (pull_request) Successful in 12s
Corn CI / release-check (pull_request) Successful in 0s
Security / scan (pull_request) Successful in 29s
Security / security (pull_request) Successful in 0s
Corn CI / test (pull_request) Successful in 2m37s
Corn CI / release (pull_request) Has been skipped
Review / change impact (pull_request_target) Successful in 3m9s
4f05af8c74
After 0.1.1-dev.3 a forged or stale callback still logged the returned state at ERROR:
FastMCP 4.1.3 oauth_proxy logs "IdP callback with invalid transaction ID: %s" with the raw
value (seen live after a test request). A logger-level filter on
fastmcp.server.auth.oauth_proxy.proxy masks the arguments of exactly the messages that carry a
one-time value (transaction ID, authorization code) at any level, plus the f-string forwarding
debug line. Logger filters run before FastMCP's own handlers and survive its handler setup.

Change review · efa7e987759c → 4f05af8c74a9

Call paths changed by this PR

Caller → changed symbol → callee. Each edge labels the line in the caller. One detected entry path (up to 3 hops) is included when found. Static evidence, not a runtime stack trace.

After

flowchart LR
    n0["OAuthProxySecretFilter.filter - added"]
    n1["_attach - added"]
    n2["test_install_is_idempotent - modified"]
    n3["install - modified"]
    n4["test_real_fastmcp_logger_is_filtered_before_its_handlers"]
    n5["run_server - modified"]
    n6["create_http_app"]
    n7["test_oauth_proxy_one_time_values_are_masked - added"]
    n3 -->|L78| n1
    n5 -->|L556| n6
    n2 -->|L70| n3
    n4 -->|L110| n3

Changed symbols:

  • added OAuthProxySecretFilter.filter — src/corn/access_log.py:58
  • added _attach — src/corn/access_log.py:66
  • modified install — src/corn/access_log.py:72
  • modified run_server — src/corn/server.py:550
  • modified test_install_is_idempotent — tests/test_access_log.py:69
  • added test_oauth_proxy_one_time_values_are_masked — tests/test_access_log.py:86
    Bounded view: 6 more changed symbols and 0 neighbour references omitted.
Overall architecture after this change

Source: 4f05af8c74a9 · code-review 0.1.0-dev.1.

Generated from resolved static calls between reviewed code areas. Numbers are call sites, not request counts.
Framework registration, dynamic dispatch, and unresolved calls are not shown. This is not a deployment map.
Showing 6 of 6 inter-area edges. Edit the reviewed source instead of this generated page.

flowchart LR
    n1["Console"]
    n2["Identity"]
    n3["NSW integrations"]
    n4["Persistence"]
    n5["REST handlers"]
    n6["Server composition"]
    n7["Shared contracts"]
    n8["Shopping"]
    n4 -->|"9"| n2
    n6 -->|"5"| n5
    n6 -->|"2"| n7
    n1 -->|"1"| n3
    n1 -->|"1"| n8
    n6 -->|"1"| n2

This diagram is for the linked commit. It refreshes after required checks pass for a new head.

<!-- john/release:architecture-review:v1 --> # Change review · `efa7e987759c` → [`4f05af8c74a9`](https://code.yawn.dev/john/corn/commit/4f05af8c74a9db8601cab658edfa01e8f961ce9b) ## Call paths changed by this PR Caller → changed symbol → callee. Each edge labels the line in the caller. One detected entry path (up to 3 hops) is included when found. Static evidence, not a runtime stack trace. ### After ```mermaid flowchart LR n0["OAuthProxySecretFilter.filter - added"] n1["_attach - added"] n2["test_install_is_idempotent - modified"] n3["install - modified"] n4["test_real_fastmcp_logger_is_filtered_before_its_handlers"] n5["run_server - modified"] n6["create_http_app"] n7["test_oauth_proxy_one_time_values_are_masked - added"] n3 -->|L78| n1 n5 -->|L556| n6 n2 -->|L70| n3 n4 -->|L110| n3 ``` Changed symbols: - **added** `OAuthProxySecretFilter.filter` — `src/corn/access_log.py:58` - **added** `_attach` — `src/corn/access_log.py:66` - **modified** `install` — `src/corn/access_log.py:72` - **modified** `run_server` — `src/corn/server.py:550` - **modified** `test_install_is_idempotent` — `tests/test_access_log.py:69` - **added** `test_oauth_proxy_one_time_values_are_masked` — `tests/test_access_log.py:86` Bounded view: 6 more changed symbols and 0 neighbour references omitted. <details><summary>Overall architecture after this change</summary> Source: [4f05af8c74a9](https://code.yawn.dev/john/corn/commit/4f05af8c74a9db8601cab658edfa01e8f961ce9b) · `code-review 0.1.0-dev.1`. Generated from resolved static calls between reviewed code areas. Numbers are call sites, not request counts. Framework registration, dynamic dispatch, and unresolved calls are not shown. This is not a deployment map. Showing 6 of 6 inter-area edges. Edit the reviewed source instead of this generated page. ```mermaid flowchart LR n1["Console"] n2["Identity"] n3["NSW integrations"] n4["Persistence"] n5["REST handlers"] n6["Server composition"] n7["Shared contracts"] n8["Shopping"] n4 -->|"9"| n2 n6 -->|"5"| n5 n6 -->|"2"| n7 n1 -->|"1"| n3 n1 -->|"1"| n8 n6 -->|"1"| n2 ``` </details> This diagram is for the linked commit. It refreshes after required checks pass for a new head.
john merged commit f334709cc7 into main 2026-11-26 03:52:23 +00:00
john deleted branch fix/oauth-proxy-log-redaction 2026-11-26 03:52:24 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
john/corn!108
No description provided.