Repository navigation
fix(headers): stop crashes from non-ASCII headers in proxy-capture and image responses - #156192
YangManBOBO wants to merge 1 commit into
Conversation
The secret egress proxy crash (issue openclaw#154685, PR openclaw#156166) came from forwarding an upstream Content-Disposition with a non-Latin-1 filename into writeHead. The same unguarded pattern exists at two other response boundaries that forward or build header values from dynamic data: - src/proxy-capture/proxy-server.ts forwards upstream response headers verbatim into writeHead, same ERR_INVALID_CHAR crash risk. - src/gateway/http-image-response.ts builds an attachment filename Content-Disposition and setHeader's it directly; this was the crash point the issue notes surfaced on 2026.9.4 before the code path moved to the egress proxy. Reuse a shared helper (src/shared/http-header-sanitize.ts) that makes header values writable: Content-Disposition filenames get an ASCII fallback plus RFC 5987 filename*=UTF-8'' and other non-Latin-1 values are scrubbed, matching the encoding the Gateway's media responses already use. Covers both setHeader and writeHead. Complements openclaw#156166; related to openclaw#154685.
|
Codex review: needs real behavior proof before merge. What this changesThe PR sanitizes response headers in the debug capture proxy and encodes Unicode attachment filenames in Gateway image responses. Review scores
Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 10 items remain Useful work remains outside the merged egress-proxy fix, but all three earlier findings remain unresolved and the changed production paths lack real behavior proof. Priority: P2 Before merge
Findings
Agent review detailsHow this fits togetherThe debug capture proxy forwards upstream HTTP responses while recording diagnostic traffic. Gateway image routes separately construct response headers for authenticated image downloads; both paths ultimately write headers through Node’s HTTP server. flowchart TD
A[Upstream HTTP response] --> B[Debug capture proxy]
C[Authenticated image request] --> D[Gateway image response]
B --> E[Response header sanitization]
D --> E
E --> F[Node HTTP header validation]
F --> G[Client response]
Technical reviewBest possible solution: Use one maintained filename serializer for generated responses and a narrowly scoped received-header adapter that preserves legal upstream headers. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the debug-proxy trigger: raw UTF-8 filename bytes following a positive Content-Length pass this sanitizer but fail Node’s later validation. No runtime reproduction was executed, and the inspected image-route callers currently use fixed ASCII names. Is this the best way to solve the issue? No. The proposed fast path misses received-byte behavior, mutates legal headers, and duplicates an existing filename serializer; a narrow forwarding adapter plus reuse of the existing serializer is safer. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 218501fc6957. Merge-risk optionsMaintainer options:
SecurityNeeds attention: The introduced sanitizer can weaken forwarded CSP directives; no dependency or supply-chain changes were introduced. EvidenceSecurity concerns:
What I checked:
PR surfaceSource +171, Tests +162. Total +333 across 5 files. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed October 7, 2026, 8:10 PM ET / October 8, 2026, 00:10 UTC (Revision 2). |
Related: #154685
Complements: #156166
What Problem This Solves
Fixes: the Gateway can crash (and crash-loop under systemd) when a response boundary forwards or builds a
Content-Dispositionheader from a non-ASCII filename. PR #156166 fixes the primary egress-proxy site from #154685; this change closes the same class of crash at the two other write sites it does not cover.User Impact
User impact: attachments with non-ASCII filenames served through the debug capture proxy, and image responses carrying a caller-supplied non-ASCII filename, no longer risk taking down the Gateway with an uncaught
ERR_INVALID_CHAR. Filenames are preserved with an ASCII fallback plus RFC 5987filename*=UTF-8''….Why This Change Was Made
Node requires header values to be Latin-1 and throws
ERR_INVALID_CHARat the write boundary. Two response paths were still unguarded:src/proxy-capture/proxy-server.tsforwards upstream response headers verbatim intowriteHead— the same pattern as the egress-proxy crash in [Bug]: Non-ASCII (CJK) filename in a forwarded response header crashes the Gateway — uncaught TypeError [ERR_INVALID_CHAR] in writeHead → crash loop #154685.src/gateway/http-image-response.tsbuildsattachment; filename="<name>"and callssetHeaderdirectly. This is the crash point the issue notes surfaced on 2026.9.4 before the code path moved to the egress proxy.This change centralizes the encoding in a shared helper (
src/shared/http-header-sanitize.ts):Content-Dispositionfilenames get an ASCIIfilename=fallback plusfilename*=UTF-8''…(the same encoding the Gateway's media responses already use), and any other non-Latin-1 header value is scrubbed, covering bothsetHeaderandwriteHead. Safe headers pass through unchanged.Evidence
src/gateway/http-image-response.test.tsregression: a CJK filename is re-encoded toattachment; filename="__.png"; filename*=UTF-8''%E9%99%84%E4%BB%B6.png; before the fix the test fails withERR_INVALID_CHAR.tsgocore typecheck, oxlint on changed files, andgit diff --checkall pass. 202 existing image-route consumer tests pass unchanged.Scope boundary
This change touches only the two additional write sites and the new shared helper. The egress-proxy fix remains in #156166; no duplication of that logic is introduced here.
AI-assisted contribution
This change was authored with AI assistance.