Skip to content

feat: add allowedOrigins option - #5770

Open
bjohansebas wants to merge 3 commits into
mainfrom
fix/allowed-origins
Open

bjohansebas wants to merge 3 commits into
mainfrom
fix/allowed-origins

Conversation

@bjohansebas

@bjohansebas bjohansebas commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Add devServer.allowedOrigins to configure which HTTP(S) origins may access resources, HMR connections (WebSocket/SSE), and WebSocket proxies, independently of allowedHosts and client.webSocketURL.

The default allows the same origin. Additional origins must match their scheme, hostname, and port; "all" explicitly allows any origin while preserving host validation. The server supplies CORS headers for authorized origins.

HMR on a separate port also accepts pages from this dev server's HTTP(S) listener on the same hostname. It uses the actual bound port, including with port: 0. This exception is limited to HMR; other HTTP endpoints and WebSocket proxies retain their origin checks.

Cross-origin frontends and reverse proxies that change the public origin must configure allowedOrigins. Script and image elements loading resources across origins should use crossorigin="anonymous" so the browser sends Origin. Response headers alone no longer authorize an origin, and loopback aliases and different ports are treated as distinct origins. Webpack-generated lazy chunks and hot-update scripts need output.crossOriginLoading: "anonymous", with output.publicPath resolving to the dev server.

Includes CLI support, generated schema and types, documentation with an example, HTTP/browser/HMR/proxy coverage, and a minor changeset.

Validation:

  • 177 affected tests passed after these updates, covering HTTP, HMR, SSE, HTTPS, and proxied WebSockets. The new separate-port HMR cases fail before the fix and pass afterward.
  • ESLint, spelling, Prettier, TypeScript, schema generation, and changeset validation passed. Generated types are reproducible.
  • A previous full-suite run encountered two CLI color assertions that also fail on clean main.

Summary by CodeRabbit

  • New Features
    • Added independent origin controls for development-server HTTP and WebSocket requests. Origins default to same-origin access; explicitly configure full HTTP(S) origins, including protocol and port, to allow cross-origin frontends.
    • Added --allowed-origins and --allowed-origins-reset CLI options. Setting origins to all disables origin checks without disabling host validation.
  • Documentation
    • Added configuration guidance and a runnable example for serving a frontend from another origin, including CORS requirements and migration notes.

@changeset-bot

changeset-bot Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c6467d1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
webpack-dev-server Minor

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

@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 59b6038c-0be6-4d01-bd59-40e7da6a6bde
📥 Commits

Reviewing files that changed from the base of the PR and between 390f797 and c6467d1.

📒 Files selected for processing: 7
  • .changeset/independent-origin-authorization.md
  • examples/allowed-origins/README.md
  • examples/allowed-origins/webpack.config.js
  • lib/Server.js
  • test/e2e/allowed-origins.test.js
  • test/e2e/proxy-web-socket-origin.test.js
  • test/e2e/web-socket-server-url.test.js
💤 Files with no reviewable changes: 1
  • test/e2e/web-socket-server-url.test.js
🚧 Files skipped from review as they are similar to previous changes: 3
  • examples/allowed-origins/webpack.config.js
  • test/e2e/proxy-web-socket-origin.test.js
  • lib/Server.js

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

Walkthrough

The change adds allowedOrigins, with normalization for auto, all, and explicit HTTP(S) origins. The server applies origin authorization separately from host validation to HTTP requests, hot endpoints, and proxied WebSocket upgrades. The change also adds CLI support, an example, documentation, and tests for origin matching, CORS headers, Fetch Metadata, HMR, and server-sent events.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to c6467

The change adds an independent origin authorization option with documentation and tests. No unresolved merge-blocking issue was identified in the supplied review context.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 18 files. (2 skipped: 2… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
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.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely identifies the primary change: adding the allowedOrigins option.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 18 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • 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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a770a2e0-d86a-4f33-90f4-0fa076fe7c75
📥 Commits

Reviewing files that changed from the base of the PR and between 9915359 and 390f797.

📒 Files selected for processing: 27
  • .changeset/independent-origin-authorization.md
  • README.md
  • examples/allowed-origins/README.md
  • examples/allowed-origins/app.js
  • examples/allowed-origins/webpack.config.js
  • lib/Server.js
  • lib/options.check.js
  • lib/options.json
  • test/__snapshots__/normalize-options.test.js.snap.webpack5
  • test/__snapshots__/validate-options.test.js.snap.webpack5
  • test/cli/__snapshots__/basic.test.js.snap.webpack5
  • test/cli/allowedOrigins-option.test.js
  • test/e2e/__snapshots__/allowed-hosts.test.js.snap.webpack5
  • test/e2e/allowed-hosts.test.js
  • test/e2e/allowed-origins.test.js
  • test/e2e/cross-origin-request.test.js
  • test/e2e/event-source.test.js
  • test/e2e/options-middleware.test.js
  • test/e2e/proxy-web-socket-origin.test.js
  • test/e2e/web-socket-server-url.test.js
  • test/normalize-options.test.js
  • test/ports-map.js
  • test/schema-check.test.js
  • test/server/allowed-origins.test.js
  • test/server/proxy-option.test.js
  • test/validate-options.test.js
  • types/lib/Server.d.ts

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

Comment thread lib/Server.js
Comment thread lib/Server.js
@codecov

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.81481% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.29%. Comparing base (9915359) to head (c6467d1).

Files with missing lines Patch % Lines
lib/Server.js 94.81% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5770      +/-   ##
==========================================
+ Coverage   95.14%   95.29%   +0.14%     
==========================================
  Files           6        6              
  Lines        5009     5032      +23     
==========================================
+ Hits         4766     4795      +29     
+ Misses        243      237       -6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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