Skip to content

Fix Codespaces host rejection in Angular SSR host check#17

Merged
sis0k0 merged 1 commit into
mainfrom
fix-codespaces-allowed-host
Jul 24, 2026
Merged

Fix Codespaces host rejection in Angular SSR host check#17
sis0k0 merged 1 commit into
mainfrom
fix-codespaces-allowed-host

Conversation

@sis0k0

@sis0k0 sis0k0 commented Jul 24, 2026

Copy link
Copy Markdown
Member

Problem

Running the client in Codespaces still fails with:

Header "x-forwarded-host" with value "…-4200.app.github.dev" is not allowed.

Root cause

@angular/ssr's isHostAllowed only treats an allowedHosts entry as a wildcard when it starts with *.:

for (const allowedHost of allowedHosts) {
  if (!allowedHost.startsWith('*.')) continue;   // ".app.github.dev" is skipped
  if (hostname.endsWith(allowedHost.slice(1))) return true;
}

The existing entry .app.github.dev (leading dot) is therefore ignored, and the forwarded Codespaces host is rejected. Also, ng serve (what Codespaces runs) validates against the serve target's allowedHosts, not the build target's security.allowedHosts, which had no entry at all.

Fix

  • build.security.allowedHosts: .app.github.dev*.app.github.dev.
  • serve.options.allowedHosts: add *.app.github.dev.

Verification

  • ng build succeeds; angular.json is valid.
  • Reproduced @angular/ssr's matcher: *.app.github.dev allows …-4200.app.github.dev and localhost, and rejects unrelated hosts.

@angular/ssr's isHostAllowed only treats an allowedHosts entry as a
wildcard when it starts with '*.', so the previous '.app.github.dev'
entry was ignored and the forwarded Codespaces host was rejected with
'Header "x-forwarded-host" ... is not allowed'.

- Use '*.app.github.dev' (the form @angular/ssr matches) in the build
  target's security.allowedHosts.
- Add allowedHosts to the serve target too, since 'ng serve' validates
  against the dev-server's list (not the build security list).
@sis0k0
sis0k0 merged commit e9428be into main Jul 24, 2026
3 checks passed
@sis0k0
sis0k0 deleted the fix-codespaces-allowed-host branch July 24, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant