#11880: fix: guard decodeURIComponent against malformed percent-encoding in browser relay
stale
Cluster:
Gateway Error Handling Improvements
## Summary
- `decodeURIComponent` throws `URIError` on malformed percent-encoded input (e.g. `%E0%A4%A`)
- In `extension-relay.ts`, `decodeURIComponent` is called inside a bare `createServer` request handler with no surrounding try-catch — a crafted URL like `/json/activate/%E0%A4%A` crashes the HTTP server
- In `dispatcher.ts`, `decodeURIComponent` is called before the route handler's try-catch block (line 108), so the error propagates as an unhandled rejection
- Wraps all three callsites in try-catch blocks that return appropriate 400 error responses
## Test plan
- [x] All 169 browser tests pass (28 test files)
- [x] Minimal change — only adds error handling around existing `decodeURIComponent` calls
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR hardens the browser-side routing/relay code against `decodeURIComponent` throwing `URIError` on malformed percent-encoded path segments.
- In `src/browser/extension-relay.ts`, the `/json/activate/:id` and `/json/close/:id` handlers now wrap `decodeURIComponent(...)` in a `try/catch` and return an HTTP 400 with a clear error message instead of letting a crafted URL crash the HTTP server.
- In `src/browser/routes/dispatcher.ts`, route param decoding is now guarded similarly; malformed path parameters return a `{ status: 400, body: { error: ... } }` response before the route handler runs.
These changes fit cleanly into the existing request/dispatch flow and are localized to the existing decode callsites.
<h3>Confidence Score: 5/5</h3>
- This PR appears safe to merge with minimal risk.
- Changes are tightly scoped to guarding `decodeURIComponent` callsites with `try/catch` and returning 400s on invalid percent-encoding; no control-flow regressions were found in the edited handlers/dispatcher path and behavior is consistent with existing response patterns.
- No files require special attention
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#14197: fix(security): harden browser API auth, token comparisons, and hook...
by leecarollyn-gif · 2026-02-11
77.9%
#11101: fix: handle AbortError and WebSocket 1006 in unhandled rejection ha...
by Nipurn123 · 2026-02-07
75.9%
#19726: Fix HTML entity decoding for astral code points and surrogate-safe ...
by Clawborn · 2026-02-18
74.4%
#18907: Fix: Improve browser error messages to avoid misleading agents
by jriff · 2026-02-17
74.4%
#3921: fix: sanitize fetch headers to prevent ByteString crash on Unicode ...
by nexiouscaliver · 2026-01-29
74.3%
#16962: fix: make auth error detection contextual to prevent false positives
by StressTestor · 2026-02-15
73.9%
#13960: fix(ui): preserve structured config validation error details
by constansino · 2026-02-11
73.8%
#4036: fix: include cause detail in agent connection error diagnostic
by anajuliabit · 2026-01-29
73.6%
#10745: feat: Security improvements and Windows compatibility fixes
by lluviaoscuradeldoce-design · 2026-02-06
73.5%
#23772: fix(ci): unblock repo-wide check gate type regressions
by SmithLabsLLC · 2026-02-22
73.5%