* Restrict X-Forwarded-Proto and X-Forwarded-Port
* Fix X-Forwarded header security vulnerabilities
- 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
* Fix path injection and port matching bugs in 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 and build
* fix: validate X-Forwarded headers with port pattern matching
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.
* Update .changeset/secure-headers.md
Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
---------
Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
* [ci] release
* Skip yarn test that fails with unpublished dependencies
The yarn test packs astro and attempts to install it, which fails when
workspace dependencies like @astrojs/internal-helpers have been bumped
but not yet published to npm. Skip this test to allow the release to proceed.
---------
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matthew Phillips <matthew@skypack.dev>
* fix(security): require allowedDomains config for X-Forwarded-Host validation
Fixes X-Forwarded-Host header injection vulnerability by requiring explicit
allowedDomains configuration. When not configured, X-Forwarded-Host headers
are ignored to prevent manipulation of Astro.url by malicious requests.
- Add security.allowedDomains configuration using RemotePattern format
- Validate X-Forwarded-Host against allowedDomains patterns in both App and NodeApp
- Ignore untrusted headers when no allowedDomains configured (secure by default)
- Update tests to verify security behavior with and without configuration
* Address PR review feedback on allowedDomains implementation
- Remove pathname field from allowedDomains schema (not applicable to host headers)
- Clarify documentation that protocol, hostname, and port are all validated if provided
- Add test demonstrating port validation behavior when port not specified in pattern
* add changeset
* make it a patch
* explain the breaking change
* Update secure-forwarded-host-validation.md
* feat: add support for specifying a prerendered error page host
* Remove console
* Validate config
* Update test
* Apply suggestions from code review
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
* Clean up test better
* Move into separate fixture
* Check protocol
* Lock
---------
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>