fix(@angular-devkit/build-angular): remove unconditional CORS wildcard from webpack dev-server#33250
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request removes the default 'Access-Control-Allow-Origin: *' header from the Webpack dev-server configuration, allowing headers to be fully controlled by the user's configuration. It also introduces a comprehensive set of unit tests to verify that custom headers are correctly applied and that the default CORS header is no longer present unless explicitly configured.
…d from webpack dev-server
The legacy webpack-based dev-server unconditionally sets
`Access-Control-Allow-Origin: *` on every response. This overrides
webpack-dev-server v5's cross-origin protections and leaves the local
dev server readable by any web page the developer visits in the same
browser session.
The modern `@angular/build` dev-server (Vite-based) already does not
set this header by default; its test contract explicitly asserts that
`Access-Control-Allow-Origin` is absent unless the user configures it.
This change brings the legacy webpack dev-server in line with that
contract.
Users who relied on the previous behavior can opt back in explicitly
via the existing `headers` option in `angular.json`:
"serve": {
"options": {
"headers": { "Access-Control-Allow-Origin": "*" }
}
}
927103f to
5e3e4b0
Compare
PR Checklist
Please check to confirm your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
@angular/buildbuilder)What is the current behavior?
The legacy webpack-based dev-server bundled with
@angular-devkit/build-angular:dev-serverunconditionally setsAccess-Control-Allow-Origin: *on every response inpackages/angular_devkit/build_angular/src/tools/webpack/configs/dev-server.ts. This overrides webpack-dev-server cross-origin protections (added in 5.2.1 to address CVE-2025-30359 / CVE-2025-30360) and allows any web page a developer visits to read the full content of the local dev server cross-origin.Background and ecosystem retrospective: https://green.sapphi.red/blog/addressing-source-code-leaks-across-the-ecosystem-a-retrospective
Issue Number: N/A
What is the new behavior?
The unconditional
Access-Control-Allow-Origin: *header is removed. Developers who relied on the previous behavior can opt back in explicitly via the existingheadersoption inangular.json:Alignment with the modern builder
The newer
@angular/builddev-server (Vite-based) already does not setAccess-Control-Allow-Originby default. Its existing test contract asserts this explicitly inpackages/angular/build/src/builders/dev-server/tests/options/headers_spec.ts:Changes
packages/angular_devkit/build_angular/src/tools/webpack/configs/dev-server.ts— remove the unconditional'Access-Control-Allow-Origin': '*'entry; pass user-providedheadersthrough unchanged.packages/angular_devkit/build_angular/src/builders/dev-server/tests/options/headers_spec.ts— new test file mirroring the contract in@angular/build.Does this PR introduce a breaking change?
Other information