-
Notifications
You must be signed in to change notification settings - Fork 26.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: correctly set x-forwarded-*
in Middleware
#57815
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
187a8e0
add test
balazsorban44 75a4c49
cleanup stripping internal headers
balazsorban44 4d7cbe5
move injecting `x-forwarded-*` headers higher up
balazsorban44 c5de9f8
fix host
balazsorban44 10831a9
fix lint
balazsorban44 edb14ba
fix lint
balazsorban44 dc30aeb
Merge branch 'canary' into fix/x-forwarded-headers-middleware
balazsorban44 94649b2
cleanup
balazsorban44 9eaa2a1
use original request for all x-forwarded-* header values
balazsorban44 c4a9b76
stop double setting x-forwarded-headers by proxy
balazsorban44 8552ef7
Merge branch 'fix/x-forwarded-headers-middleware' of https://github.c…
balazsorban44 dd8ccef
add comment
balazsorban44 b1038c2
use `this.hostname` and `this.port`
balazsorban44 72972bb
manually set `x-forwarded-host` header on `http-proxy`
balazsorban44 bfc8458
revert `x-forarded-proto` changes in `resolve-routes.ts`
balazsorban44 52f7021
allow reading `remoteAddress` from socket
balazsorban44 964c185
Merge branch 'canary' into fix/x-forwarded-headers-middleware
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,11 +24,13 @@ export async function proxyRequest( | |
target, | ||
changeOrigin: true, | ||
ignorePath: true, | ||
xfwd: true, | ||
ws: true, | ||
// we limit proxy requests to 30s by default, in development | ||
// we don't time out WebSocket requests to allow proxying | ||
proxyTimeout: proxyTimeout === null ? undefined : proxyTimeout || 30_000, | ||
headers: { | ||
'x-forwarded-host': req.headers.host || '', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still set this header to respect #17557, but without concating without adding a comma |
||
}, | ||
}) | ||
|
||
await new Promise((proxyResolve, proxyReject) => { | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { NextResponse } from 'next/server' | ||
|
||
export function middleware(req: Request) { | ||
return NextResponse.next({ | ||
headers: { | ||
'middleware-x-forwarded-host': | ||
req.headers.get('x-forwarded-host') ?? 'wrong', | ||
'middleware-x-forwarded-port': | ||
req.headers.get('x-forwarded-port') ?? 'wrong', | ||
'middleware-x-forwarded-proto': | ||
req.headers.get('x-forwarded-proto') ?? 'wrong', | ||
}, | ||
}) | ||
} |
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With
xfwd: true
,http-proxy
attempts to setx-forwarded-*
headers. Since we are setting these headers higher up inbase-server.ts
, this should not be necessary to set here anymore, to avoid double setting them, as reported in #52266See: https://github.com/http-party/node-http-proxy/blob/9b96cd725127a024dabebec6c7ea8c807272223d/lib/http-proxy/passes/web-incoming.js#L58-L86