Skip to content

feat(hub): trust the dev-server builder's allowedHosts, host and allowedOrigins - #513

Open
guiomesch wants to merge 2 commits into
pangular-inspector:mainfrom
guiomesch:feat/builder-allowed-hosts
Open

guiomesch wants to merge 2 commits into
pangular-inspector:mainfrom
guiomesch:feat/builder-allowed-hosts

Conversation

@guiomesch

@guiomesch guiomesch commented Dec 3, 2026 •

Copy link
Copy Markdown

What and why

With @pangular-inspector/devtools:dev-server, an app opened on a custom hostname that resolves to 127.0.0.1 (for example https://myapp.dev.example.test:4200 with --ssl) gets a blank panel. POST /__devframes/__sse returns 403, and ng serve prints:

[pangular] Refused a devtools request from https://myapp.dev.example.test:4200. Add it to allowedOrigins, or its host to server.allowedHosts, to allow it.

The builder started the hub with initPangularHub({ ws: false }), so neither the dev server's allowedHosts nor any origin reached the hub's gate. The GET requests pass because they carry no Origin. The POST is refused.

Changes:

  • initPangularHub() takes allowedHosts (string[] | true), read like Vite's server.allowedHosts. It applies in the request gate and in the origin check of the hub's transports. devframe's SSE transport checks Origin on its own, so the gate alone wasn't enough. It gets the same gated registry the Vite plugin uses. It shows in the Dashboard's security status, and true prints the same warning as in Vite.
  • The dev-server builder passes the dev server's allowedHosts, its host when that is a name (not loopback or a wildcard), and a new allowedOrigins option. It keeps allowedOrigins out of the options it hands to the Angular dev server, since Angular's schema doesn't know it.
  • The gate reads :authority under HTTP/2. With --ssl the dev server speaks HTTP/2 and browsers send no Host. With allowedHosts: true the gate then refused same-origin pages, and the Host check against DNS rebinding was skipped.
  • Docs: the builder's options table and a custom-hostname example in the installation guide, allowedHosts in the Express hub options, and the security page.

How it was verified

  • pnpm commit:check (commit messages follow the guidelines)
  • pnpm format:check
  • pnpm typecheck (includes the ngc template checks)
  • pnpm test:devtools: all pass except source-file-index.test.ts > rescans a component once its missing templateUrl file appears, which fails the same way on main on my machine
  • pnpm skills:check (when .claude/ changed): not needed
  • Docs in apps/docs updated and pnpm docs:build passes
  • pnpm extension:build and extension/ui committed (when app/ changed): not needed
  • Checked in the browser with axe (when the UI changed): not needed

New tests:

  • hub-express-gate.test.ts: a request with Origin: https://myapp.dev.example.test:4200 gets through, and the SSE POST gets past the 403, with allowedHosts or allowedOrigins set. Without them it gets 403. Without the transport registry the POST assertion fails, which confirms devframe's own check.
  • hub-gate.test.ts: an HTTP/2-style request (:authority, no Host).
  • dev-server-builder.test.ts: the hub options built from angular.json, run through the real @angular/build dev server schema.

Notes for reviewers

  • Hosts are trusted per name, so ssl and port don't matter.
  • The refusal and allowedHosts: true warnings still name Vite's server.allowedHosts. Rewording them for the builder and the hub can come in a follow-up.

Summary by CodeRabbit

  • New Features
    • Dev-server users can configure trusted origins and hosts for the Inspector hub. Hostnames configured in the dev server are also recognized, and allowedHosts: true remains available for broader access.
    • HTTP/2 requests using :authority are now checked using the same host rules as requests using Host.
  • Documentation
    • Updated setup and security guidance to explain trusted-host behavior, defaults, and the risks of allowing all hosts.

The request gate read only the Host header. Under HTTP/2, which the
Angular dev server uses with --ssl, browsers send :authority and no Host.
With allowedHosts: true the gate then refused a same-origin page, and the
Host check against DNS rebinding was skipped. Fall back to :authority
when Host is missing.
…wedOrigins

The dev-server builder started the hub with its defaults, so a page opened
on a custom hostname that points to this machine got 403 on the panel's
SSE POST, even with the name in allowedHosts.

initPangularHub() takes an allowedHosts option, read like Vite's
server.allowedHosts, in its request gate and in the origin check of its
transports. The builder forwards the dev server's allowedHosts, its host
when it is a name, and a new allowedOrigins option, which it keeps from
the Angular dev server's own options.
@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The hub now supports configured allowed hosts and origins. The dev-server builder derives and passes these settings to the hub. The request gate uses HTTP/2 :authority when Host is absent.

Changes: Hub Host and Origin Trust

Layer / File(s) Summary
Hub trust policy and request checks
packages/devtools/src/hub.ts, packages/devtools/src/hub-gate.ts, packages/devtools/src/__tests__/hub-gate.test.ts, packages/devtools/src/__tests__/hub-express-gate.test.ts, apps/docs/src/content/getting-started/express.md, apps/docs/src/content/security.md
The hub accepts allowedHosts and applies it to its request policy. Host checks use Host or HTTP/2 :authority. Tests and security documentation describe host and origin handling.
Dev-server options passed to the hub
packages/devtools/src/builders/dev-server/index.ts, packages/devtools/src/builders/dev-server/schema.json, packages/devtools/src/__tests__/dev-server-builder.test.ts, apps/docs/src/content/getting-started/installation.md
The builder adds allowedOrigins, derives trusted hub options from the serve configuration, and passes them to the hub. Tests and installation documentation cover these options.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant DevServerBuilder
  participant runDevServer
  participant devServerHubOptions
  participant initPangularHub
  DevServerBuilder->>runDevServer: Provide allowedOrigins and serve options
  runDevServer->>devServerHubOptions: Derive trusted hub options
  devServerHubOptions-->>runDevServer: Return normalized origins and allowed hosts
  runDevServer->>initPangularHub: Pass hub options
Loading

Possibly related PRs

Merge Risk: Minimal · up to 5e973

This change lets the dev-server builder and hub trust configured hostnames and origins, and checks HTTP/2 :authority when Host is absent. No concrete merge-blocking problem was established, and tests cover the gate, the SSE POST and the builder options.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the feature in the change: the dev-server builder now forwards allowedHosts, host and allowedOrigins to the Pangular hub. The raw summary and objectives confirm this is the main change…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the feature in the change: the dev-server builder now forwards allowedHosts, host and allowedOrigins to the Pangular hub. The raw summary and objectives confirm this is the main change. The title is specific and matches the changeset, so it passes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2fe3701f-fb9b-4198-b1b4-689e5f458252
Commits

Reviewing files that changed from the base of the PR and between 3e49a8b and 5e9734b.

Files selected for processing: 10

  • apps/docs/src/content/getting-started/express.md
  • apps/docs/src/content/getting-started/installation.md
  • apps/docs/src/content/security.md
  • packages/devtools/src/__tests__/dev-server-builder.test.ts
  • packages/devtools/src/__tests__/hub-express-gate.test.ts
  • packages/devtools/src/__tests__/hub-gate.test.ts
  • packages/devtools/src/builders/dev-server/index.ts
  • packages/devtools/src/builders/dev-server/schema.json
  • packages/devtools/src/hub-gate.ts
  • packages/devtools/src/hub.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@erkamyaman

Copy link
Copy Markdown
Member

@guiomesch thank you! i will have a look ASAP!

@guiomesch

Copy link
Copy Markdown
Author

Thanks a lot @erkamyaman ! I find Pangular Inspector amazing, it has become part of my daily Angular workflow. I ran into an issue with the host part: with the dev-server builder, opening the app on a custom hostname (with --ssl) left the panel blank because the hub refused the requests, so I put this fix together. Thanks again for the tool, and I'm looking forward to your feedback!

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.

2 participants