Skip to content

Conversation

@matthewp
Copy link
Contributor

Changes

  • Fully sanitizes X-Forwarded-Host, Host, X-Forwarded-Proto and X-Forwarded-Port to prevent manipulation of Astro.url that could cause cache poisoning.

Testing

New tests added

Docs

N/A, bug fix

- Sanitize hostnames to reject paths and prevent path injection
- Validate X-Forwarded-Proto, X-Forwarded-Host, X-Forwarded-Port headers
- Add strict rejection for invalid hostnames (those with path separators)
- Implement single sanitizeHost() function in App class, used by both validateForwardedHeaders() and node.ts
- Add comprehensive security tests for header validation
- Reject both forward and backward slashes in hostnames using single regex
- Fix allowedDomains port matching by validating full hostname:port combo instead of just hostname
- Add test for X-Forwarded-Host with embedded port in allowedDomains pattern
@changeset-bot
Copy link

changeset-bot bot commented Nov 10, 2025

🦋 Changeset detected

Latest commit: 5273707

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 pkg: integration Related to any renderer integration (scope) pkg: astro Related to the core `astro` package (scope) labels Nov 10, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 10, 2025

CodSpeed Performance Report

Merging #14743 will not alter performance

Comparing xforwardedstuff (5273707) with main (91780cf)1

Summary

✅ 6 untouched

Footnotes

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

Fixes protocol validation to accept http/https when allowedDomains exist but lack protocol patterns. Restructures port/host validation to validate port first, then include it when validating host against patterns. Properly extracts hostname without port to avoid duplication when combining with X-Forwarded-Port.
@matthewp matthewp marked this pull request as ready for review November 10, 2025 19:06
@matthewp matthewp merged commit dafbb1b into main Nov 10, 2025
26 checks passed
@matthewp matthewp deleted the xforwardedstuff branch November 10, 2025 20:18
@astrobot-houston astrobot-houston mentioned this pull request Nov 10, 2025
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) pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants