Skip to content

Keep HTTP and WebSocket redirect credentials within the same origin - #658

Open
bsergean wants to merge 1 commit into
masterfrom
fix/http-redirect-credentials
Open

bsergean wants to merge 1 commit into
masterfrom
fix/http-redirect-credentials

Conversation

@bsergean

Copy link
Copy Markdown
Collaborator

Automatic HTTP and WebSocket redirects forwarded caller-supplied Authorization and Cookie headers to different origins. A redirect between two local server ports reproduces the credential leak on master in both clients.

Remove those headers when a redirect changes scheme, hostname or effective port. A shared UrlParser::isSameOrigin() comparison handles scheme/hostname case and default ports. Credentials remain removed throughout that redirect chain, including a subsequent return to the original origin. Same-origin redirects retain them, and the caller's configuration stays unchanged for future requests or connections. Other custom headers retain their existing behavior, which is documented.

This follows the redirect credential guidance in RFC 9110 §15.4.

Validation:

  • Reproduced failing tests before the fix for all five HTTP redirect statuses and for WebSocket redirects.
  • Tests cover same-origin retention, cross-origin removal, case-insensitive header names, unchanged caller configuration, and multi-hop HTTP/WebSocket chains. Origin comparison tests cover scheme/host changes, explicit/default ports, IPv6 and malformed URLs.
  • Complete plain HTTP suite: 30/30 passed. Complete OpenSSL ThreadSanitizer suite: 32/32 passed. HTTP response, async/cancellation and URL suites each passed five consecutive runs, both plain and under ThreadSanitizer.
  • New regression cases use local sockets without sleeps and run in milliseconds. Production builds with strict C++11 and warnings as errors. git clang-format and git diff --check pass.

This branch has not been deployed

No deployments
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.

1 participant