Skip to content

fix: X-Forwarded-Proto rejected when allowedDomains includes protocol field#15560

Merged
matthewp merged 1 commit intowithastro:mainfrom
z0mt3c:fix/forwarded-proto-allowed-domains
Feb 18, 2026
Merged

fix: X-Forwarded-Proto rejected when allowedDomains includes protocol field#15560
matthewp merged 1 commit intowithastro:mainfrom
z0mt3c:fix/forwarded-proto-allowed-domains

Conversation

@z0mt3c
Copy link
Copy Markdown
Contributor

@z0mt3c z0mt3c commented Feb 17, 2026

The protocol validation in validateForwardedHeaders() passed the full pattern object to matchPattern(), which also checked hostname against the hardcoded test URL (example.com). Pass only { protocol } to matchPattern() so that only the protocol field is validated; the host+proto combination is already checked in the host validation block below.

Fixes #15559

Changes

  • Pass { protocol: pattern.protocol } instead of the full pattern to matchPattern() in the protocol validation block
  • Changeset included

Testing

Added 4 unit tests in node.test.js covering the reverse proxy case (socket.encrypted: false):

  • Accepts forwarded https when allowedDomains has protocol + hostname
  • Rejects forwarded http when only https is allowed
  • Accepts forwarded https with wildcard hostname pattern
  • Constructs correct URL behind reverse proxy with all forwarded headers

Docs

No docs changes needed — this restores the documented behavior of security.allowedDomains.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 17, 2026

🦋 Changeset detected

Latest commit: 31af714

The changes in this PR will be included in the next version bump.

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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Feb 17, 2026
… and hostname

The protocol validation in validateForwardedHeaders() passed the full pattern
object to matchPattern(), which also checked hostname against the hardcoded
test URL (example.com). Pass only { protocol } to matchPattern() so that only
the protocol field is validated; the host+proto combination is already checked
in the host validation block below.

Fixes withastro#15559
@z0mt3c z0mt3c force-pushed the fix/forwarded-proto-allowed-domains branch from f48a3f6 to 31af714 Compare February 17, 2026 20:35
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Feb 17, 2026

Merging this PR will improve performance by 32.87%

⚡ 2 improved benchmarks
✅ 7 untouched benchmarks

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation Build: hybrid site (static + server) 8.5 s 7.7 s +10.59%
Simulation Rendering: streaming [false], .md file 1.5 ms 1.1 ms +32.87%

Comparing z0mt3c:fix/forwarded-proto-allowed-domains (31af714) with main (7be3308)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (55c568c) during the generation of this report, so 7be3308 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@matthewp matthewp merged commit 170ed89 into withastro:main Feb 18, 2026
57 of 59 checks passed
qzio pushed a commit to qzio/astro that referenced this pull request Feb 20, 2026
… and hostname (withastro#15560)

The protocol validation in validateForwardedHeaders() passed the full pattern
object to matchPattern(), which also checked hostname against the hardcoded
test URL (example.com). Pass only { protocol } to matchPattern() so that only
the protocol field is validated; the host+proto combination is already checked
in the host validation block below.

Fixes withastro#15559
louisescher added a commit that referenced this pull request Feb 24, 2026
#15594)

Co-authored-by: Timo Behrmann <timo.behrmann@gmail.com>
Co-authored-by: Louis Escher <66965600+louisescher@users.noreply.github.com>
fix: X-Forwarded-Proto rejected when allowedDomains includes protocol and hostname (#15560)
Fixes #15559
@louisescher louisescher mentioned this pull request Feb 25, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security.allowedDomains with protocol breaks X-Forwarded-Proto validation in 5.17.2

2 participants