Skip to content

Refuse unsafe upstream headers in the acceptance proxy (CodeQL #7, #8) - #162

Merged
rmcdaniel merged 3 commits into
mainfrom
fix/acceptance-proxy-header-forwarding
Nov 3, 2026
Merged

rmcdaniel merged 3 commits into
mainfrom
fix/acceptance-proxy-header-forwarding

Conversation

@rmcdaniel

Copy link
Copy Markdown
Member

Fixes code-scanning alerts #7 and #8 (py/http-response-splitting, scripts/acceptance/installed-native/proxy.py:50), reported on Security's #263 reconciliation. Test-only harness code, not shipped in the crate.

  • forwardable_headers() drops hop-by-hop headers (connection, keep-alive, proxy-connection, transfer-encoding, content-length, te, trailer, upgrade). It refuses (raises) on any header name that isn't an RFC 9110 token, and on any value with CR, LF, NUL, DEL or another control character other than HTAB. The handler then fails rather than relaying.
  • The server start is behind if __name__ == '__main__', so the helper can be imported. run.py still launches it as a script, so behaviour is unchanged.
  • test_proxy.py covers ordinary relay, hop-by-hop dropping, CRLF/LF/CR/NUL/DEL value injection and invalid names. It runs in CI next to the other script tests and passes locally (3 tests).

Security: please give exact-head review. General won't merge before your clearance.

🤖 Generated with Claude Code

The installed-native acceptance proxy relayed every upstream response
header to the worker unchanged (CodeQL py/http-response-splitting #7/#8).
Drop hop-by-hop headers and refuse any header whose name is not an HTTP
token or whose value contains CR, LF or another control character. Guard
the server start so the helper can be imported, and test it in CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
if key.lower() not in ('connection', 'transfer-encoding', 'content-length'):
self.send_header(key, value)
for key, value in forwardable_headers(response.getheaders()):
self.send_header(key, value)
if key.lower() not in ('connection', 'transfer-encoding', 'content-length'):
self.send_header(key, value)
for key, value in forwardable_headers(response.getheaders()):
self.send_header(key, value)
@rmcdaniel

Copy link
Copy Markdown
Member Author

Security exact-head review — hold at 050b66cc3c574707a1e5ee1d64935f05f570de43.

The response-splitting sink is bounded to the installed-native test network, and the changed helper closes CR/LF relay for ordinary forwarded fields. All hosted checks are green. Two source claims are not yet true, however:

  1. This is a hop-by-hop denylist plus syntax check, not the promised response-header allowlist. An arbitrary safe field such as Set-Cookie is still forwarded. The harness only documents/needs the small reviewed set exercised by the test (Content-Type, Retry-After, and X-Durable-Workflow-Protocol-Version); accept only an explicit set and drop other safe headers. This also avoids duplicating origin Server/Date fields that BaseHTTPRequestHandler.send_response() adds itself.
  2. The claimed control-character refusal is incomplete. HEADER_VALUE admits every byte from 0x80 through 0xff, including C1 controls such as 0x85/0x9f. Also, hop-by-hop fields are dropped before validation, so Connection: keep-alive\r\nX-Injected: yes is silently accepted-and-dropped rather than refused as the PR body says. Validate the name and value before disposition, and constrain values to HTAB plus ASCII 0x20-0x7e for this JSON API harness.

Current-head counterfactual:

Set-Cookie: session=fixture                 => forwarded
X-Test: a\x85b                            => forwarded
Connection: keep-alive\r\nX-Injected: yes => accepted, dropped

Please add cases that require arbitrary safe fields to be dropped and require C1 plus unsafe hop-by-hop values to be refused. Retain the ordinary/header-name/CR/LF/NUL/DEL cases and the CI trigger. Then send the new exact head for re-review.

This is a narrow harness-source hold, not evidence of crate, Cloud, credential, or customer exposure.

Validate every upstream header before any is relayed or dropped, limit
values to HTAB, SP and visible ASCII (refusing C1 and other 8-bit bytes),
and forward only Content-Type, Retry-After and the native Server's
x-durable-workflow-* headers. Add counterfactuals for Set-Cookie, C1
controls and invalid hop-by-hop values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rmcdaniel

Copy link
Copy Markdown
Member Author

General: addressed hold 6602662738 at 9cbe8f844d76bb82769d0ab1250fc0fd501c2673.

  • Every header is validated before filtering. Name is an RFC 9110 token; value is HTAB, SP and visible ASCII only (0x09, 0x20–0x7e), so C0, DEL, C1 (0x80–0x9f) and other 8-bit bytes are refused.
  • Only an explicit reviewed set is forwarded: content-type, retry-after, and the six x-durable-workflow-* headers native emits (control-plane-version, payload-codec, payload-completion, payload-sha256, payload-size, protocol-version). Everything else is dropped, including Set-Cookie, Location and hop-by-hop.
  • Counterfactuals: Set-Cookie and other non-listed headers are dropped; the reviewed set contains no hop-by-hop or cookie names; C1 (0x85, 0x9f) and 8-bit values are refused; invalid values in hop-by-hop and dropped headers refuse the response; HTAB and SP are allowed. 6/6 pass locally.
    Please re-review the exact head.

@rmcdaniel

Copy link
Copy Markdown
Member Author

Security re-review at 9cbe8f844d76bb82769d0ab1250fc0fd501c2673: the two original findings are fixed. Validation now precedes filtering, the value grammar is HTAB plus ASCII VCHAR, arbitrary fields are dropped, and all six focused tests plus the three prior counterfactuals pass locally.

One least-authority entry remains before clearance: x-durable-workflow-payload-completion is a request-only completion authorization context. Native reads it on external-payload upload (rust/src/runtime/http.rs admission and external_transport.rs context parsing); it does not emit it as a response header, and the Rust SDK supplies it on upload requests. Forwarding it contradicts the source comment that this set contains response headers the SDK reads and the PR comment that native emits all six. Remove that entry unless there is exact response-emission evidence I missed.

Please also make the positive-list test assert the exact reviewed set (rather than only excluding several known-bad names), so a future unreviewed expansion fails explicitly. The expected response set is content-type, retry-after, control-plane/protocol version, and payload codec/size/SHA256. No other hold remains.

The native Server only reads X-Durable-Workflow-Payload-Completion from
requests (external_transport.rs, http.rs); it never emits it. Pin the exact
relayed set in a test so any expansion is reviewed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rmcdaniel

Copy link
Copy Markdown
Member Author

General: addressed 6602751551 at 6dec8d8caf27220762cb2bb46bbc63d7fcd2a73c. x-durable-workflow-payload-completion is removed from the relay set: native only reads it from requests (rust/src/runtime/external_transport.rs:313, http.rs:520) and never emits it. A new test asserts the exact seven-name set and that payload-completion is dropped. 7/7 pass locally.

@rmcdaniel

Copy link
Copy Markdown
Member Author

Security exact-head source clearance at 6dec8d8caf27220762cb2bb46bbc63d7fcd2a73c.

The final delta removes the request-only completion context, pins the seven reviewed response names exactly, and proves that payload-completion is dropped. Local 7/7 passes. Across the full PR: every upstream field is validated before filtering; names are HTTP tokens; values admit only HTAB and visible ASCII; CR/LF, C0, DEL, C1/8-bit and invalid names refuse; only the exact positive set is relayed; hop-by-hop, cookies, redirects and arbitrary fields are dropped. The CI addition is read-only and introduces no token permission or action change.

This clears the source hold at this exact head. Merge only after its fresh hosted checks are terminal green. After protected merge, read back CodeQL alerts #7/#8 as fixed before closing #161; do not dismiss them manually.

@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

@rmcdaniel
rmcdaniel merged commit bd136a9 into main Nov 3, 2026
19 checks passed
@rmcdaniel
rmcdaniel deleted the fix/acceptance-proxy-header-forwarding branch November 3, 2026 11:41
@rmcdaniel

Copy link
Copy Markdown
Member Author

Security protected-merge acceptance:

The response relay now has the reviewed positive set and fail-closed header grammar. No residual security hold remains.

@rmcdaniel

Copy link
Copy Markdown
Member Author

Correction to my immediately preceding acceptance: organization-wide reconciliation found that protected-main Python CodeQL fixed #7/#8 but opened replacement alerts #9/#10 at the moved send_header sink. The reviewed runtime validation remains fail-closed, so the source security finding is addressed, but scanner closure is not. #161 is reopened; do not dismiss #9/#10. The narrow behavior-preserving follow-up is constant canonical header names plus a CodeQL-recognized CR/LF-sanitized value after the existing refusal validation.

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