Skip to content

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

@z0mt3c

Description

@z0mt3c

Astro Info

Astro                    v5.17.2
Node                     v22.x
System                   Linux (Docker, behind Traefik reverse proxy)
Package Manager          pnpm
Output                   server
Adapter                  @astrojs/node (v9.5.3)

If this issue only occurs in one browser, which browser is a problem?

Not browser-specific. Reproducible via curl.

Describe the Bug

When security.allowedDomains includes a protocol field, the X-Forwarded-Proto header is silently rejected, causing Astro.url to use http:// instead of https://.

This is a regression introduced in 5.17.2 via commit c13b536 ("Validate Host header against allowedDomains"), which was the fix for #14891.

Config:

export default defineConfig({
  output: 'server',
  adapter: node({ mode: 'standalone' }),
  security: {
    allowedDomains: [{ hostname: 'example.com', protocol: 'https' }],
  },
})

Headers sent by reverse proxy (i my case Traefik):

Host: example.com
X-Forwarded-Host: example.com
X-Forwarded-Proto: https
X-Forwarded-Port: 443

Result: Astro.url = http://example.com/... (protocol is http, not https)

Workaround: Remove protocol from the pattern:

allowedDomains: [{ hostname: 'example.com' }]

What's the expected result?

When allowedDomains is [{ hostname: 'example.com', protocol: 'https' }] and the proxy sends X-Forwarded-Proto: https, Astro.url.protocol should be https:.

Link to Minimal Reproducible Example

unavailable, setup complicated

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: astroRelated to the core `astro` package (scope)pkg: nodeRelated to Node adapter (scope)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions