Resolve X-Forwarded-* headers inside FetchState#16811
Draft
matthewp wants to merge 6 commits into
Draft
Conversation
Previously, X-Forwarded-Proto/Host/Port headers were resolved before the Fetchable handler's fetch() method was called, so headers set by user code in src/app.ts had no effect on Astro.url. Move the forwarded header resolution into FetchState's constructor so it reads from request.headers at the right time. This lets custom fetch handlers set or modify forwarded headers before creating FetchState. Also removes the now-redundant forwarded header processing from the dev server's handleRequest() in vite-plugin-app/app.ts. Closes #16797
🦋 Changeset detectedLatest commit: 3e8badd The changes in this PR will be included in the next version bump. This PR includes changesets to release 415 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
e18e dependency analysisNo dependency warnings found. |
Merging this PR will degrade performance by 20.34%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
6ace448 to
50bb21d
Compare
…alidation Internal call sites that go through app.render() (which creates a FetchState) no longer duplicate the X-Forwarded-* validation work. The public createRequest is preserved for external adapters.
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.
Changes
FetchState's constructor, so headers set by user code insrc/app.tsbefore creatingFetchStateare reflected inAstro.urlandAstro.clientAddress. Previously these headers were resolved before the Fetchable handler'sfetch()was called, making user modifications invisible.handleRequest()invite-plugin-app/app.ts. The production-sidecreateRequest()innode.tsis kept as-is for backward compatibility with third-party adapters that call it directly without going throughFetchState.clientAddressis also resolved fromX-Forwarded-ForinsideFetchStatewhen the host is trusted, unless already provided via render options.Closes #16797
Testing
test/units/fetch/index.test.tscovering: ignored headers withoutallowedDomains, proto/host/port applied individually and together, rejected untrusted hosts,clientAddressfromX-Forwarded-For(trusted/untrusted/pre-set), the core issue scenario (headers set infetch()beforeFetchState), and a full pipeline render with forwarded headers.Docs
experimental.advancedRouting.