Skip to content

fix(@angular/build): allow configuring Access-Control-Allow-Origin via headers option#32976

Open
alan-agius4 wants to merge 1 commit intoangular:mainfrom
alan-agius4:cors-setting
Open

fix(@angular/build): allow configuring Access-Control-Allow-Origin via headers option#32976
alan-agius4 wants to merge 1 commit intoangular:mainfrom
alan-agius4:cors-setting

Conversation

@alan-agius4
Copy link
Copy Markdown
Collaborator

Removes the default Vite CORS origin: true configuration, allowing custom Access-Control-Allow-Origin header configurations to take effect when using the development server.

BREAKING CHANGE: The development server (ng serve) no longer automatically mirrors the request origin in the Access-Control-Allow-Origin response header by default. If your application relies on cross-origin requests during local development, you must now explicitly configure the required CORS headers using the headers option in your angular.json configuration.

Fixes #32923

…a headers option

Removes the default Vite CORS origin: true configuration, allowing custom Access-Control-Allow-Origin header configurations to take effect when using the development server.

BREAKING CHANGE: The development server (ng serve) no longer automatically mirrors the request origin in the Access-Control-Allow-Origin response header by default. If your application relies on cross-origin requests during local development, you must now explicitly configure the required CORS headers using the headers option in your angular.json configuration.

Fixes angular#32923
@alan-agius4 alan-agius4 requested review from clydin and dgp1130 April 9, 2026 14:39
@alan-agius4 alan-agius4 added the target: minor This PR is targeted for the next minor release label Apr 9, 2026
@angular-robot angular-robot bot added detected: breaking change PR contains a commit with a breaking change area: @angular/build labels Apr 9, 2026
@alan-agius4 alan-agius4 added the action: review The PR is still awaiting reviews from at least one requested reviewer label Apr 9, 2026
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 modifies the Angular dev server's Vite configuration to remove the default Access-Control-Allow-Origin: true setting, meaning the Access-Control-Allow-Origin header will no longer be automatically mirrored. A new test case was added to verify that when the header is explicitly configured, it is correctly applied. The reviewer suggests adding another test to explicitly confirm that the Access-Control-Allow-Origin header is not set by default when no headers option is provided, to fully cover the breaking change in behavior.

expect(await response?.headers.get('x-custom')).toBe('foo');
});

it('should include configured Access-Control-Allow-Origin header', async () => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Consider: Should we add a test that the CORS header is not returned by default?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: @angular/build detected: breaking change PR contains a commit with a breaking change target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Permissive CORS policy in Dev Server enables cross-origin source code exfiltration

2 participants