Skip to content

Vite 8 regression: cross-origin classic script request to /src/*.ts returns 403 #21849

@Denis6902

Description

@Denis6902

Describe the bug

Vite 8 dev server returns 403 Forbidden for cross-origin classic script requests to /src/*.ts files, while the same setup works in Vite 7.3 and in rolldown-vite.

This was reproduced with a minimal setup using only the vanilla-ts template.

Reproduction setup:

  • Project A: plain Vite vanilla-ts app
  • Project B: plain Vite vanilla-ts app
  • Project A loads a source file from Project B using a classic script tag:
<script src="http://localhost:5174/src/counter.ts"></script>

Observed behavior:

  • If Project B uses vite@7.3.x, the script loads correctly
  • If Project B uses vite@8.x, the request returns 403 Forbidden
  • If Project B uses rolldown-vite, it also works correctly

Additional notes:

  • The failure only happens when the file is loaded via <script src="..."> from a different origin. Directly opening the same URL in the browser works.
  • This does not appear to be a Rolldown issue, because the same reproduction works with rolldown-vite.

Reproduction

https://github.com/Denis6902/vite8-cross-origin-script-403-repro

Steps to reproduce

  1. Create two separate Vite projects using the vanilla-ts template
  2. Run Project A on one port, for example 5173
  3. Run Project B on another port, for example 5174
  4. In Project A, add this to index.html:
<script src="http://localhost:5174/src/counter.ts"></script>
  1. Start both dev servers
  2. Open Project A in the browser

System Info

System:
    OS: Windows 11 10.0.26200
    CPU: (16) x64 Intel(R) Core(TM) i5-14400
    Memory: 9.91 GB / 31.77 GB
  Binaries:
    Node: 22.22.0 - C:\nvm4w\nodejs\node.EXE
    npm: 10.9.4 - C:\nvm4w\nodejs\npm.CMD
  Browsers:
    Chrome: 145.0.7632.160
    Edge: Chromium (145.0.3800.58)
  npmPackages:
    vite: ^8.0.0 => 8.0.0

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions