Skip to content

Access-Control-Allow-Origin header missing in dev server for assets #29549

Closed

Description

@vkennke

Command

serve

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

@angular-devkit/build-angular 19.1.4

Description

Starting with Angular 19.1.5, when running the development server using ng serve, the Access-Control-Allow-Origin header is no longer included in responses when accessing assets. In version 19.1.4, this header was still being sent with the value '*'.

This affects cross-origin requests to static assets served by the development server.

Minimal Reproduction

Repository for minimal reproduction:
[Link to Git Repository]

Steps to reproduce:

  1. Clone repository and install dependencies:
git clone https://github.com/vkennke/angular-cors.git
cd angular-cors
npm install
  1. Start dev server:
ng serve
  1. Access http://localhost:4200/assets/test.txt and check response headers

Expected behavior:
Response headers include Access-Control-Allow-Origin: *

Actual behavior:
Access-Control-Allow-Origin header is missing from response

To verify this is a regression:

  1. Edit package.json to set @angular-devkit/build-angular to 19.1.4:
"@angular-devkit/build-angular": "19.1.4"
  1. Repeat steps 2-3
  2. Observe that the Access-Control-Allow-Origin: * header is present

Exception or Error

No error is thrown, but the missing header prevents cross-origin requests from succeeding.

Your Environment

Angular CLI: 19.1.5
Node: 20.18.0
Package Manager: npm 10.8.2
OS: win32 x64

Angular: 19.1.4
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1901.5
@angular-devkit/build-angular   19.1.5
@angular-devkit/core            19.1.5
@angular-devkit/schematics      19.1.5
@angular/cli                    19.1.5
@schematics/angular             19.1.5
rxjs                            7.8.1
typescript                      5.7.3
zone.js                         0.15.0

Anything else relevant?

No response

Activity

  1. changed the title [-]Access-Control-Allow-Origin header missing in dev server for assets starting with Angular 19.1.5[/-] [+]Access-Control-Allow-Origin header missing in dev server for assets[/+] on Jan 31, 2025
  2. alan-agius4 commented on Feb 10, 2025

    @alan-agius4
    Collaborator

    Can you explain why you need this header? If you're accessing resources from a different host, this behavior is expected. For more details, see: #29471.

  3. added
    needs: more info
    on Feb 10, 2025
  4. AndreKoepke commented on Feb 10, 2025

    @AndreKoepke

    Can you explain why you need this header?

    Longer answer

    In our case: We have a multi-frontend-system. The "main"-system runs somewhere in cloud (for example under "example.com") and loads its configured subsystems from various different domains ("exampleA.com", "exampleB.com", and so on).
    Each subsystem has a defined entrypoint - the asset-file "manifest.json". Have a look at scion-workbench for more details.

    For developing-purposes it is necessary that we can use the "manifest.json" from our local environment. We can say at domain "example.com" that one manifest can be found at localhost. Then the system tries to load the "localhost:4200/assets/manifest.json" file while the webpage is running under "example.com".

    I will have a look at #29471 tomorrow. Maybe it solves our problems.
    For us, it was a big surprise that jumping to the next patch release causing these kinds of troubles.

  5. vkennke commented on Feb 11, 2025

    @vkennke
    Author

    Patch versions should never introduce breaking changes.

    Our workaround is to set the header manually.

    "serve": {
              "builder": "@angular-devkit/build-angular:dev-server",
              "options": {
                "headers": {
                  "Access-Control-Allow-Origin": "*"
                },
  6. AndreKoepke commented on Feb 11, 2025

    @AndreKoepke

    Can you explain why you need this header? If you're accessing resources from a different host, this behavior is expected. For more details, see: #29471.

    I tried to set

    "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "allowedHosts": ["example.com"]
          },

    but it won't work. I got a warning "The "allowedHosts" option will not be used because it is not supported by the "@angular-devkit/build-angular:application" builder.", is it already released?

    The workaround of @vkennke works well.

  7. alan-agius4 commented on Feb 11, 2025

    @alan-agius4
    Collaborator

    The warning is no longer relevant and should be removed, setting the allowedHosts. I did some further digging and indeed the Access-Control-Allow-Origin is not added in this case.

    @vkennke, you're right that patch updates should avoid breaking changes. However, in this case, it was necessary to address a security vulnerability in Vite.

  8. self-assigned this
    on Feb 11, 2025
  9. added
    freq1: low
    and removed
    needs: more info
    on Feb 11, 2025
  10. added 3 commits that reference this issue on Feb 11, 2025
    8349508
    5d3cc6b
    eefbeed
  11. added a commit that references this issue on Feb 12, 2025
    df1d388
  12. added a commit that references this issue on Feb 12, 2025
    be15b88
  13. AndreKoepke commented on Feb 13, 2025

    @AndreKoepke

    Confirmed. In 19.1.7 is all fine again. Thanks @alan-agius4. 👍

  14. angular-automatic-lock-bot commented on Mar 16, 2025

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  15. locked and limited conversation to collaborators on Mar 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions