Repository navigation
fix(secrets): preserve protected egress for non-ASCII attachment filenames - #156166
Conversation
…SCII filename The secret egress proxy passed upstream response headers straight into writeHead. Node exposes received header bytes as latin1 strings, and once Content-Length is stored a later non-Latin-1 Content-Disposition throws ERR_INVALID_CHAR. That throw happened in the upstream response callback, outside any try block, so it exited the Gateway and systemd restarted it into the same attachment. Forward only ASCII header values: Content-Disposition filenames become an ASCII filename= fallback plus RFC 6266 filename*=UTF-8'' so the original name survives, and other non-ASCII characters are replaced. Any remaining writeHead failure now stays on that request as a 502 (or a closed socket for bodyless 1xx/204/304 heads) instead of crashing the process. Closes openclaw#154685
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
✅ Maintainer security changes approvedA maintainer approved this revision with an explicit security approval comment.
A later push requires a fresh approval comment for an external contributor's PR. |
|
Codex review: needs maintainer review before merge. Reviewed September 23, 2026, 8:55 AM ET / 12:55 UTC (Revision 7). ClawSweeper reviewWhat this changesThe PR preserves international attachment filenames through the secret egress proxy and contains rejected response headers to the affected request. Merge readiness✅ Ready for maintainer review The fix remains necessary on current main. Prior findings are resolved, real behavior proof is sufficient, and security approval now covers the reviewed head; no blocking defect was found. Priority: P0 Review scores
Verification
How this fits togetherThe secret egress proxy forwards HTTPS requests from Gateway-hosted commands while protecting destination-bound credentials. Its response forwarding determines whether downloaded attachments reach those commands and whether the proxy remains available. flowchart LR
A[Gateway-hosted command] --> B[Authenticated secret proxy]
B --> C[HTTPS upstream]
C --> D[Response header normalization]
D --> E{Header accepted?}
E -->|Yes| F[Stream attachment to command]
E -->|No| G[Request-local error or disconnect]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +108, Tests +274. Total +382 across 5 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep filename normalization and request-local failure containment at the egress response boundary while preserving unrelated header bytes and existing authorization. Do we have a high-confidence way to reproduce the issue? Yes: raw UTF-8 Content-Disposition following Content-Length reaches an unguarded Node writeHead on current main. Source inspection and the supplied production-path negative control establish the trigger; this review did not execute it. Is this the best way to solve the issue? Yes: the repair belongs at the forwarding boundary, preserves unrelated headers and upstream filename*, and avoids modifying Node's private response state. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against bb8aea886bfd. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
|
Thanks for the thorough egress-proxy fix — that is the primary crash site from #154685 and the loopback + containment coverage is solid. While validating this independently I found the same unguarded write pattern in two other response paths that this PR does not cover:
I have an independent, complementary implementation of the same RFC 6266/RFC 5987 approach ( Happy to either (a) open a small separate PR for the two additional sites so this one can land on its own, or (b) fold the two sites + shared helper into this PR if you prefer one change. Let me know which you'd like — no intention to race your fix. |
|
Follow-up: I've opened a small separate PR for the two additional write sites this one does not cover — #156192 (proxy-capture proxy-server writeHead + gateway http-image-response setHeader, reusing the same shared RFC 5987 sanitizer). It is scoped to those sites only, so it should not conflict with this PR. Happy to rebase or adjust if you prefer a different shape. |
…ilename* Node forwards other latin1 header values byte-for-byte after Content-Length; only Content-Disposition is revalidated as UTF-8. Leave every other header untouched so opaque values such as ETag keep working with If-Match and If-None-Match. When rewriting Content-Disposition, keep an existing ASCII filename* verbatim and preserve the other ASCII parameters. Add an end-to-end test through the real proxy and a real TLS upstream that sends Content-Length before a UTF-8 filename, then a rejected head, then a normal request.
|
/allow-security-sensitive-change |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
/allow-security-sensitive-change |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in b6b4524. Thanks @siri1410 for the fix! Verified through a built Gateway and real agent/exec → CONNECT/TLS forwarding: current main lost the attachment and stopped protected egress, while this revision preserved the filename and delivered both the attachment and the next request. All 62 focused tests passed; required CI and exact-head hosted review were green. |
…names (openclaw#156166) Closes openclaw#154685 ## What Problem This Solves Fixes: downloading a forwarded attachment with a non-ASCII filename stops the secret egress proxy Worker and leaves protected egress unavailable until the Gateway restarts. Before openclaw#156354 moved forwarding off the main thread, the same defect crashed the Gateway itself. ## User Impact User impact: attachments with non-ASCII filenames download with their original name preserved in `filename*`, and one bad upstream response head no longer stops protected egress. A rejected ordinary response gets a request-local 502 (or a closed connection for an already-bodyless response), while the proxy keeps serving. ## Why This Change Was Made The secret egress proxy passes upstream response headers straight into `writeHead`. Node exposes received header bytes as latin1 strings and forwards them byte-for-byte, with one exception. Once `Content-Length` is stored, Node revalidates `Content-Disposition` as UTF-8, and a raw UTF-8 filename throws `ERR_INVALID_CHAR`. The throw happens in the upstream response callback, outside any `try`. On current main it terminates the proxy Worker: the Gateway remains live, but protected egress stops until restart. This change: - **Rewrites only `Content-Disposition`, and only when it contains non-ASCII bytes.** The legacy `filename=` becomes an ASCII fallback. An upstream `filename*` is kept verbatim; otherwise one is generated as `filename*=UTF-8''…` from the decoded name, so the original name survives. Other ASCII parameters (for example `size=`) are kept. - **Leaves every other header untouched.** I checked this on Node 26.8.1: after `Content-Length`, the same raw UTF-8 bytes in `ETag`, `Link`, `Content-Type`, or a custom header forward fine, and only `Content-Disposition` throws. So opaque values such as `ETag` still work with `If-Match`/`If-None-Match`. - **Contains any remaining `writeHead` failure to the one request.** The upstream response is destroyed and the client gets a 502. For 1xx/204/304 heads, where Node may already have marked the response bodyless, the socket is closed instead of framing a 502 body. - Applies the same `Content-Disposition` handling to the forwarded `101` upgrade head. There is no global `ServerResponse` patch, and request-side behavior is unchanged. openclaw#155121 took a similar approach and was closed by its author while awaiting review; this is an independent implementation that doesn't touch Node's private `_hasBody` flag. Security note: this touches `src/secrets/egress-proxy/**`, so it needs `/allow-security-sensitive-change` from a maintainer. ## Evidence **Real proxy and real upstream transport.** New test in `proxy-server.test.ts`: `forwards a CJK attachment filename from a real upstream and keeps serving`. It starts the actual `startSecretEgressProxyServer`, sends requests through an authenticated CONNECT tunnel with TLS to the proxy, and forwards them over real HTTPS to a real TLS upstream. The upstream writes raw bytes to its socket, because Node's own server cannot emit this header order. In sequence: 1. `Content-Length: 4` followed by `Content-Disposition: attachment; filename="附件_2026-09-21.log"` as raw UTF-8. The client receives `200`, body `file`, and `content-disposition: attachment; filename="___2026-09-21.log"; filename*=UTF-8''%E9%99%84%E4%BB%B6_2026-09-21.log`. 2. A head that Node rejects mid-write (`Trailer` on a non-chunked response). The client receives `502 Secret egress proxy could not forward the upstream response.` 3. A normal request on the same proxy returns `200 ok`, so the proxy is still serving. No `uncaughtException` is raised at any point. On `main`'s `proxy-forward.ts`, step 1 gets no HTTP response at all and the test fails. **Focused tests.** - `proxy-forward.test.ts` loopback tests, with the upstream response emitted on a later tick as the real client does: - A CJK filename after `Content-Length`. Without the fix this fails with the production error, `TypeError: Invalid character in header content ["content-disposition"]`. - A real mid-`writeHead` rejection returns a `502` on a 200 head. On a 304 head the connection closes with no status line; with an unconditional 502 instead, the client would get a `502` head and then an aborted body, and the test catches that. - `response-headers.test.ts` covers: - non-`Content-Disposition` headers, including a non-ASCII `ETag`, forwarded unchanged; - an upstream `filename*` and `size=` kept; - received UTF-8 bytes vs. decoded characters, and quoted vs. unquoted filenames; - non-UTF-8 Latin-1 input; - unparseable values. ``` ✓ proxy-server.test.ts > secret egress proxy > forwards a CJK attachment filename from a real upstream and keeps serving 240ms ✓ proxy-forward.test.ts > secret egress forwarded response heads > forwards a CJK attachment filename that follows Content-Length 2ms ✓ proxy-forward.test.ts > secret egress forwarded response heads > answers 502 instead of crashing when the forwarded head is rejected 1ms ✓ proxy-forward.test.ts > secret egress forwarded response heads > answers 502 after Node rejects a forwarded head mid-write 1ms ✓ proxy-forward.test.ts > secret egress forwarded response heads > closes a rejected bodyless head instead of framing a 502 body 1ms ✓ response-headers.test.ts > toForwardableResponseHeaders > forwards non-ASCII bytes in other headers unchanged 0ms ✓ response-headers.test.ts > toForwardableResponseHeaders > keeps an upstream filename* and other ASCII parameters 1ms … (6 more response-headers cases) Test Files 6 passed (6) Tests 115 passed (115) Duration 6.70s ``` **Checks.** - `pnpm check:changed` passed on the first revision. For this revision: - `pnpm tsgo:core` and the `agents-tools` core test shard typecheck (which includes `src/secrets/**` tests) are clean. - The gate's `scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json` and `oxfmt --check` are clean. - CI note: the two failing Node shards on the first revision were unrelated to this change. They were `src/gateway/session-lifecycle-state.persistence.test.ts` and `src/gateway/server.sessions.abort-authorization.test.ts` ("Matcher did not succeed in time"), and both pass locally on this branch. ## Maintainer verification At head `2ec35def5c3fc9cb3ca4c2c9241491880b01ed49`, all three focused files passed (58 tests). Each file was run separately with `OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/secrets/egress-proxy/<file>`; measured command wall time, including startup: | File | Wall time | | --- | ---: | | `proxy-server.test.ts` | 7.14s | | `proxy-forward.test.ts` | 1.39s | | `response-headers.test.ts` | 1.32s | Negative control: replacing only `proxy-forward.ts` with merge-base `0bad6eeb100097e0822e1a5d49c236824d0ee8fe` made the real authenticated CONNECT/TLS CJK-attachment test fail: no HTTP status was received (`NaN`, expected `200`). Restoring the candidate made the complete server suite pass, including the attachment, rejected-head 502, subsequent 200, and secret destination/authentication checks. Available CI timing: initial `checks-node-compact-large-10` job ran 05:12:53–05:19:20 UTC (6m27s), with its failing owner-claim shard reporting 327.06s. The authorized failed-job rerun still failed that same unrelated owner-claim case. Current main was merged without rebasing the contributor commits; new CI is required. ### Built Gateway end-to-end proof At candidate `1261c0851e317ca70a2286f398aa05e1d01e78fe` (main `b638129b2461184c916d3318e673fae2af9fe8b3` merged, including openclaw#156354), `pnpm openclaw gateway run` rebuilt the CLI and started an isolated Gateway with `secrets.egressProxy.enabled=true`. A normal `pnpm openclaw agent` turn used the supported OpenClaw runtime and a synthetic local Chat Completions provider to issue an actual Gateway-hosted `exec` command. Curl used the process-owned authenticated proxy and TLS to download a raw-byte HTTPS attachment response with `Content-Length` preceding the UTF-8 `Content-Disposition`. Both sides used fresh isolated state. - Candidate: the exec tool result contained `200 OK`, body `file`, ASCII `filename="___2026-09-21.log"` plus RFC 6266 `filename*=UTF-8''%E9%99%84%E4%BB%B6_2026-09-21.log`. A second request returned `200 OK` / `ok`, and the agent turn completed through the still-running Gateway. - Current-main negative control: rebuilt the same checkout with only `proxy-forward.ts` replaced by its `b638129b246` version (the only changed production caller; the candidate helper was then unused). The identical agent flow received curl error 52 / empty reply for the attachment, then curl error 7 / connection refused for the next request. Gateway logs reported `secret egress proxy Worker stopped; restart the Gateway to restore protected egress`. `/healthz` still returned `{"ok":true,"status":"live"}`: openclaw#156354 contains the process crash, but does not fix attachment delivery or the protected-egress outage. Candidate source was restored afterward. - The HTTPS fixture used localhost port 19443 because binding privileged port 443 was denied, and a certificate signed by the isolated Gateway's process CA. This proves the built Gateway/proxy/exec path, not Feishu delivery or general non-443 compatibility. No product callback or transport was mocked; only the model and upstream service responses were synthetic. Co-authored-by: Ayaan Zaidi <[email protected]>
Backport #156166: b6b4524 Selected backport #156207: 741a1c8 Retain request-local response-head failure handling and use the shared stream writer for Fleet output. Remove the retired Fleet-local owner. The unrelated Crabbox protected-credential feature is not included. Targeted transport/registered-handler proof and independent review pass. Full release qualification remains separate. Co-authored-by: siri1410 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]> Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vyctorbrzezowski <[email protected]> Co-authored-by: steipete <[email protected]> Co-authored-by: jalehman <[email protected]>
…ed PR (#160305) The release-notes verifier now records exact GraphQL NOT_FOUND results and omits a reference only when it appears solely as contextual commit-body text and lies below the highest resolved number, reporting it as manifest unavailableReferences without credit. Every other unresolved reference stays fatal. Unblocks 2026.9.7 notes regeneration (#155121 mentioned in #156166).
…ed PR (openclaw#160305) The release-notes verifier now records exact GraphQL NOT_FOUND results and omits a reference only when it appears solely as contextual commit-body text and lies below the highest resolved number, reporting it as manifest unavailableReferences without credit. Every other unresolved reference stays fatal. Unblocks 2026.9.7 notes regeneration (openclaw#155121 mentioned in openclaw#156166).
Closes #154685
What Problem This Solves
Fixes: downloading a forwarded attachment with a non-ASCII filename stops the secret egress proxy Worker and leaves protected egress unavailable until the Gateway restarts. Before #156354 moved forwarding off the main thread, the same defect crashed the Gateway itself.
User Impact
User impact: attachments with non-ASCII filenames download with their original name preserved in
filename*, and one bad upstream response head no longer stops protected egress. A rejected ordinary response gets a request-local 502 (or a closed connection for an already-bodyless response), while the proxy keeps serving.Why This Change Was Made
The secret egress proxy passes upstream response headers straight into
writeHead. Node exposes received header bytes as latin1 strings and forwards them byte-for-byte, with one exception. OnceContent-Lengthis stored, Node revalidatesContent-Dispositionas UTF-8, and a raw UTF-8 filename throwsERR_INVALID_CHAR. The throw happens in the upstream response callback, outside anytry. On current main it terminates the proxy Worker: the Gateway remains live, but protected egress stops until restart.This change:
Content-Disposition, and only when it contains non-ASCII bytes. The legacyfilename=becomes an ASCII fallback. An upstreamfilename*is kept verbatim; otherwise one is generated asfilename*=UTF-8''…from the decoded name, so the original name survives. Other ASCII parameters (for examplesize=) are kept.Content-Length, the same raw UTF-8 bytes inETag,Link,Content-Type, or a custom header forward fine, and onlyContent-Dispositionthrows. So opaque values such asETagstill work withIf-Match/If-None-Match.writeHeadfailure to the one request. The upstream response is destroyed and the client gets a 502. For 1xx/204/304 heads, where Node may already have marked the response bodyless, the socket is closed instead of framing a 502 body.Content-Dispositionhandling to the forwarded101upgrade head.There is no global
ServerResponsepatch, and request-side behavior is unchanged. #155121 took a similar approach and was closed by its author while awaiting review; this is an independent implementation that doesn't touch Node's private_hasBodyflag.Security note: this touches
src/secrets/egress-proxy/**, so it needs/allow-security-sensitive-changefrom a maintainer.Evidence
Real proxy and real upstream transport. New test in
proxy-server.test.ts:forwards a CJK attachment filename from a real upstream and keeps serving. It starts the actualstartSecretEgressProxyServer, sends requests through an authenticated CONNECT tunnel with TLS to the proxy, and forwards them over real HTTPS to a real TLS upstream. The upstream writes raw bytes to its socket, because Node's own server cannot emit this header order. In sequence:Content-Length: 4followed byContent-Disposition: attachment; filename="附件_2026-09-21.log"as raw UTF-8. The client receives200, bodyfile, andcontent-disposition: attachment; filename="___2026-09-21.log"; filename*=UTF-8''%E9%99%84%E4%BB%B6_2026-09-21.log.Traileron a non-chunked response). The client receives502 Secret egress proxy could not forward the upstream response.200 ok, so the proxy is still serving. NouncaughtExceptionis raised at any point.On
main'sproxy-forward.ts, step 1 gets no HTTP response at all and the test fails.Focused tests.
proxy-forward.test.tsloopback tests, with the upstream response emitted on a later tick as the real client does:Content-Length. Without the fix this fails with the production error,TypeError: Invalid character in header content ["content-disposition"].writeHeadrejection returns a502on a 200 head. On a 304 head the connection closes with no status line; with an unconditional 502 instead, the client would get a502head and then an aborted body, and the test catches that.response-headers.test.tscovers:Content-Dispositionheaders, including a non-ASCIIETag, forwarded unchanged;filename*andsize=kept;Checks.
pnpm check:changedpassed on the first revision. For this revision:pnpm tsgo:coreand theagents-toolscore test shard typecheck (which includessrc/secrets/**tests) are clean.scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.jsonandoxfmt --checkare clean.src/gateway/session-lifecycle-state.persistence.test.tsandsrc/gateway/server.sessions.abort-authorization.test.ts("Matcher did not succeed in time"), and both pass locally on this branch.Maintainer verification
At head
2ec35def5c3fc9cb3ca4c2c9241491880b01ed49, all three focused files passed (58 tests). Each file was run separately withOPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/secrets/egress-proxy/<file>; measured command wall time, including startup:proxy-server.test.tsproxy-forward.test.tsresponse-headers.test.tsNegative control: replacing only
proxy-forward.tswith merge-base86d353b7485df33811774618af23252555e19f62made the real authenticated CONNECT/TLS CJK-attachment test fail: no HTTP status was received (NaN, expected200). Restoring the candidate made the complete server suite pass, including the attachment, rejected-head 502, subsequent 200, and secret destination/authentication checks.Available CI timing: initial
checks-node-compact-large-10job ran 05:12:53–05:19:20 UTC (6m27s), with its failing owner-claim shard reporting 327.06s. The authorized failed-job rerun still failed that same unrelated owner-claim case. Current main was merged without rebasing the contributor commits; new CI is required.Built Gateway end-to-end proof
At candidate
1261c0851e317ca70a2286f398aa05e1d01e78fe(main0864fb6f86c9a5080f23b3125dba29d0db38427emerged, including #156354),pnpm openclaw gateway runrebuilt the CLI and started an isolated Gateway withsecrets.egressProxy.enabled=true. A normalpnpm openclaw agentturn used the supported OpenClaw runtime and a synthetic local Chat Completions provider to issue an actual Gateway-hostedexeccommand. Curl used the process-owned authenticated proxy and TLS to download a raw-byte HTTPS attachment response withContent-Lengthpreceding the UTF-8Content-Disposition. Both sides used fresh isolated state.200 OK, bodyfile, ASCIIfilename="___2026-09-21.log"plus RFC 6266filename*=UTF-8''%E9%99%84%E4%BB%B6_2026-09-21.log. A second request returned200 OK/ok, and the agent turn completed through the still-running Gateway.proxy-forward.tsreplaced by its0864fb6f86cversion (the only changed production caller; the candidate helper was then unused). The identical agent flow received curl error 52 / empty reply for the attachment, then curl error 7 / connection refused for the next request. Gateway logs reportedsecret egress proxy Worker stopped; restart the Gateway to restore protected egress./healthzstill returned{"ok":true,"status":"live"}: perf(secrets): move egress forwarding off the main thread #156354 contains the process crash, but does not fix attachment delivery or the protected-egress outage. Candidate source was restored afterward.