Skip to content

fix: security and correctness hardening (request smuggling, path/method ACL bypass, crashes, leaks) - #7

Merged
jkyberneees merged 6 commits into
masterfrom
fix/eloquent-feynman-caioe5
Nov 25, 2026
Merged

jkyberneees merged 6 commits into
masterfrom
fix/eloquent-feynman-caioe5

Conversation

@jkyberneees

Copy link
Copy Markdown
Contributor

Summary

A full review of the proxy core for security, correctness and performance. Every issue below was reproduced against 1.1.3 before being fixed, and each fix has a regression test. A second, independent adversarial review of the fixed code found seven further issues, which are included here.

  • 165 tests (78 existing + 87 new) pass on Node 18, 20, 22 and 24; standard is clean; coverage is 99%.
  • Throughput is on par with 1.1.3 in a local closed-loop benchmark (about 13k req/s GET, 11k req/s POST).

Security fixes

Request smuggling

  • HTTP/2 source without content-length on DELETE/OPTIONS: the payload was written unframed on a keep-alive connection, so the remote server parsed it as a second request.
  • Custom stream payloads (req.body = Stream) were framed with the client's content-length, which does not describe them (e.g. a decompressed payload). Exceeding bytes were parsed as a second request.
  • Chunked requests re-serialized after a body parser were sent with both content-length and transfer-encoding.
  • The framing of the remote request is now always defined by the proxy.

Access control bypass

  • /public/../admin (also %2e encoded, or using backslashes) matched a /public/* route but reached /admin on the remote server. Now 400.
  • //admin was collapsed to /admin, bypassing an /admin rule at the gateway. Now 400.
  • HTTP/2 accepts delete as a method name and the HTTP client sent it as DELETE. Methods that are not upper case are now 400.

Process crashes (remote DoS)

  • Absolute-form request with an unsupported protocol when base is not set.
  • Remote server returning an invalid status code (099 for HTTP/1 clients, >= 600 for HTTP/2 clients).
  • Errors thrown by rewriteHeaders, onResponse and onClientConnectionTerminated. They are now answered with 500 and reported with process.emitWarning.

Hangs and leaks

  • Forwarding upgrade made the request hang forever when the remote server switched protocols. CONNECT is rejected with 405.
  • Remote connections were never released when the client disconnected before the response, or before proxy() was invoked. The remote request is now aborted, and unconsumed responses are destroyed.

Response corruption

  • When the remote server failed after sending the headers, Gateway Timeout was appended to the payload of a seemingly successful response. The request callback now runs at most once, and the client connection (HTTP/2: the stream) is terminated instead.

Other

  • Request hop-by-hop headers are no longer forwarded.
  • Response headers nominated by the remote connection header, plus trailer and proxy-authenticate, are stripped.
  • URL cache keys of different (base, source) pairs could collide.

Correctness fixes

  • Buffer/typed array payloads were forwarded as their JSON representation.
  • Form payloads were forwarded as JSON when the content-type had parameters (e.g. ; charset=UTF-8); nested values and arrays were mangled.
  • Payloads not handled by the body parsers (req.body = {}) were replaced by {}.
  • IPv6 literal hosts kept their brackets in the connection hostname (verified with a mocked client only).
  • Stale content-encoding is dropped when a body parser decoded the payload.
  • Payloads that can't be serialized are rejected with 400 instead of throwing.
  • Fragments are never forwarded; mixed-case response headers from custom request clients keep their values.
  • Proxy options (base, cacheURLs, requests) are no longer passed down to the HTTP agents.
  • Typings: requests was typed as an Agent, the stream type came from an undeclared pump types dependency, queryString only allowed strings.

Behavior changes

  • Generic remote failures are answered with 502 instead of 500 (the body already said "Bad Gateway").
  • Sources starting with // are rejected instead of collapsed. Three existing tests asserting the collapse were updated.
  • A client disconnect aborts the remote request, so onClientConnectionTerminated usually receives an ECONNRESET error and no response.
  • A POST without payload is forwarded with content-length: 0 instead of an empty chunked payload.
  • expect and proxy-authorization are no longer forwarded.
  • CI runs on Node 18, 20, 22 and 24 with current action versions (was Node 16 with v1 actions).

Not changed

  • There is still no default remote timeout. The README now recommends setting timeout; a default would break long-polling users.
  • ECONNRESET still maps to 504.
  • Paths such as /public/..;/admin or /public/..%2fadmin are forwarded untouched. A remote server that normalizes further could still be reached that way; this is documented in the README.
  • The version is still 1.1.3. Given the behavior changes, a minor release (1.2.0) seems more fitting than a patch.

Test plan

  • npx standard
  • npm test on Node 18, 20, 22 and 24
  • New regression suite: test/14.hardening.test.js
  • CI workflow on the updated Node matrix (could not be run locally)

Generated by Claude Code

Security
- Request smuggling: the framing of the remote request is now always
  defined by the proxy. A payload received without content-length
  (HTTP/2 source, DELETE/OPTIONS...) was written unframed on a keep-alive
  connection and parsed as a second request by the remote server. Parsed
  payloads of chunked requests were sent with both content-length and
  transfer-encoding.
- Route prefix escape: targets containing dot segments (also %2e
  encoded), backslashes, tabs or line breaks are rejected with 400. The
  URL parser resolved them, so "/public/../admin" matched a "/public/*"
  route but reached "/admin" on the remote server.
- Denial of service: unsupported protocols (absolute-form requests when
  no base is set), invalid remote status codes and invalid header values
  crashed the process with an uncaught exception.
- Hop-by-hop request headers are not forwarded anymore. "upgrade" made
  the request hang forever when the remote switched protocols,
  "connection: close" disabled remote connection reuse.
- Remote connections were leaked when the client disconnected before the
  remote response was received. The remote request is now aborted, and
  unconsumed responses are destroyed.
- A remote failure after the response headers were sent appended an
  error message to the payload of a seemingly successful response. The
  request callback is now guaranteed to run once, and the client
  connection is terminated instead.
- URL cache keys of different (base, source) pairs could collide.
- Response headers nominated by the remote "connection" header, plus
  "trailer" and "proxy-authenticate", are stripped.

Correctness
- Buffer/typed array payloads were forwarded as their JSON representation.
- Form payloads were forwarded as JSON when the content-type had
  parameters (e.g. charset), nested values and arrays were mangled.
- Payloads not handled by the body parsers (req.body = {}) were replaced
  by "{}".
- IPv6 literal hosts could not be reached.
- Generic remote failures are reported as 502 instead of 500, timeouts
  have a dedicated error code.
- Fragments are never forwarded, mixed case response headers of custom
  request clients keep their values.
- Proxy options are not passed down to the http agents anymore.

Also: typings fixes, documentation of the proxy behavior, CI running on
supported Node.js versions.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Px3ETB9QhGQ9rSwjGpEcH
- Requests of clients that disconnected before proxy() was invoked (e.g.
  while asynchronous middlewares were running) are not forwarded anymore.
  The 'close' event was already emitted, so the remote request was never
  aborted and its connection could be held forever.
- Methods that are not upper case are rejected. HTTP/2 servers accept
  "delete" as a method name, the http client sent it as "DELETE",
  bypassing method based access control at the gateway.
- CONNECT is rejected with 405, tunnels are not supported and the request
  was never settled.
- Remote status codes not allowed in HTTP/2 (>= 600) crashed the process
  when the source was an HTTP/2 request.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Px3ETB9QhGQ9rSwjGpEcH
- Request smuggling: custom stream payloads (req.body = Stream) were
  framed using the content-length of the client request, which does not
  describe them (e.g. a decompressed payload). Exceeding bytes were parsed
  as a second request by the remote server. They are now always sent
  using chunked transfer encoding.
- Access control bypass: sources starting with "//" were collapsed to a
  single slash, "//admin" did not match an "/admin" rule at the gateway
  but reached "/admin" on the remote server. They are rejected with 400,
  as well as targets containing any control character, or starting or
  ending with a space.
- Errors thrown by rewriteHeaders, onResponse and
  onClientConnectionTerminated were uncaught exceptions leaking the remote
  connection. They are answered with 500 and reported as process warnings.
- When rewriteRequestHeaders returns both framing headers, content-length
  is dropped.
- content-encoding is not forwarded when the payload was decoded by a body
  parser.
- Payloads that can not be serialized are rejected with 400 instead of
  throwing.
- HTTP/2 streams are reset when the remote response fails midway, a
  truncated chunked response was ended gracefully.
- Dates are serialized in form urlencoded payloads.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Px3ETB9QhGQ9rSwjGpEcH
Comment thread test/14.hardening.test.js Fixed
Comment thread test/14.hardening.test.js Fixed
Comment thread test/14.hardening.test.js Fixed
claude and others added 3 commits November 25, 2026 08:18
The test servers echoing the request URL had no content type, which code
scanning reports as reflected cross-site scripting. They are only used by
the test suite, the responses are now explicitly served as plain text.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Px3ETB9QhGQ9rSwjGpEcH
When onResponse threw, the 500 error was sent with the headers of the
remote response already copied to the client response. A stale
content-length desynchronized keep-alive client connections, and
content-encoding/cache-control described a payload that was never sent.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jkyberneees
jkyberneees merged commit 1805ca1 into master Nov 25, 2026
11 checks passed
@jkyberneees
jkyberneees deleted the fix/eloquent-feynman-caioe5 branch November 25, 2026 08:39
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.

3 participants