Skip to content

fix(@angular-devkit/build-angular): remove unconditional CORS wildcard from webpack dev-server#33250

Open
filbertsaputro wants to merge 1 commit into
angular:mainfrom
filbertsaputro:fix/devserver-cors-wildcard
Open

fix(@angular-devkit/build-angular): remove unconditional CORS wildcard from webpack dev-server#33250
filbertsaputro wants to merge 1 commit into
angular:mainfrom
filbertsaputro:fix/devserver-cors-wildcard

Conversation

@filbertsaputro
Copy link
Copy Markdown

@filbertsaputro filbertsaputro commented May 26, 2026

PR Checklist

Please check to confirm your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe: Security hardening (aligning legacy webpack dev-server defaults with the modern @angular/build builder)

What is the current behavior?

The legacy webpack-based dev-server bundled with @angular-devkit/build-angular:dev-server unconditionally sets Access-Control-Allow-Origin: * on every response in packages/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 existing headers option in angular.json:

"serve": {
  "options": {
    "headers": { "Access-Control-Allow-Origin": "*" }
  }
}

Alignment with the modern builder

The newer @angular/build dev-server (Vite-based) already does not set Access-Control-Allow-Origin by default. Its existing test contract asserts this explicitly in packages/angular/build/src/builders/dev-server/tests/options/headers_spec.ts:

it('should not include Access-Control-Allow-Origin header by default', async () => {
  harness.useTarget('serve', { ...BASE_OPTIONS });
  const { result, response } = await executeOnceAndFetch(harness, '/main.js');
  expect(result?.success).toBeTrue();
  expect(await response?.headers.has('access-control-allow-origin')).toBeFalse();
});

Changes

  • packages/angular_devkit/build_angular/src/tools/webpack/configs/dev-server.ts — remove the unconditional 'Access-Control-Allow-Origin': '*' entry; pass user-provided headers through 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?

  • Yes
  • No

Other information

@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 26, 2026

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.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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": "*" }
    }
  }
@filbertsaputro filbertsaputro force-pushed the fix/devserver-cors-wildcard branch from 927103f to 5e3e4b0 Compare May 26, 2026 03:16
@alan-agius4 alan-agius4 added target: patch This PR is targeted for the next patch release action: merge The PR is ready for merge by the caretaker labels May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular-devkit/build-angular target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants