fix(redirect): strip authorization header on cross-origin 307/308 redirects (#1844) - #1856
Open
vaibhavmashal wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new behavior also strips Cookie, but the added tests only assert Authorization, leaving part of the security behavior unverified.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR addresses a security issue in the Node redirect implementation by ensuring sensitive credentials are not forwarded when following cross-origin redirects, specifically covering 307/308 behavior that previously preserved headers.
Changes:
- Update redirect origin-change detection to compare full URL origins (scheme/host/port).
- Strip
authorizationandcookieheaders on cross-origin 307/308 redirects. - Add unit tests asserting
Authorizationis stripped on cross-origin 307/308 POST redirects.
File summaries
| File | Description |
|---|---|
src/node/index.js |
Computes changesOrigin via URL.origin and strips credential headers on cross-origin 307/308 redirects. |
test/node/redirects-other-host.js |
Adds tests for 307/308 POST redirects to ensure Authorization is not retained across origins. |
Review details
Suppressed comments (1)
test/node/redirects-other-host.js:219
- This test verifies Authorization stripping but doesn’t cover the newly added behavior to also strip Cookie on cross-origin 308 redirects, so a regression on Cookie stripping would go unnoticed.
const request_ = request
.post(`${base}/test-308`)
.set('Authorization', 'Bearer secret-token')
.redirects(1);
request_.end((error, res) => {
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+185
to
+197
| const request_ = request | ||
| .post(`${base}/test-307`) | ||
| .set('Authorization', 'Bearer secret-token') | ||
| .redirects(1); | ||
| request_.end((error, res) => { | ||
| const headers = request_.req.getHeaders | ||
| ? request_.req.getHeaders() | ||
| : request_.req._headers; | ||
| assert.strictEqual(headers.authorization, undefined); | ||
| res.status.should.eql(200); | ||
| res.text.should.eql('POST'); | ||
| done(); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1844
Description
Per RFC 9110 Section 15.4, credentials such as \Authorization\ and \Cookie\ headers must not be forwarded to a different origin on HTTP redirects.
Previously, while 301, 302, and 303 redirects stripped sensitive headers via \cleanHeader(headers, changesOrigin), 307 and 308 redirects preserved the method and headers without stripping credentials on cross-origin redirects.
Solution
ew URL(url).origin !== new URL(this.url).origin\ across protocol, host, and port.