Skip to content

server.fs.strict 'extended' returns 403 for SPA routes that match a root directory #24240

Backlog

Description

@mfroembgen

Describe the bug

With server.fs.strict: 'extended', an extensionless URL like /home, /Users or /tmp returns 403 when a directory of that name exists at the filesystem root, unless the request sends Sec-Fetch-Dest: document. The log says The request id "/home" is outside of Vite serving allow list. With strict: true the same request gets the SPA fallback (200).

Browsers send Sec-Fetch-Dest: document on navigation, so they are unaffected. Scripted smoke checks (curl -H 'Accept: text/html') and other non-browser clients get 403 for SPA routes whose first path segment happens to match a root directory, such as /home on macOS and Linux.

Reproduction

https://github.com/mfroembgen/vite-strict-extended-dir-403

Steps to reproduce

npm install
STRICT=extended npx vite --port 5199 &
curl -s -o /dev/null -w '%{http_code}\n' -H 'Accept: text/html' http://localhost:5199/tmp                             # 403
curl -s -o /dev/null -w '%{http_code}\n' -H 'Accept: text/html' -H 'Sec-Fetch-Dest: document' http://localhost:5199/tmp  # 200
curl -s -o /dev/null -w '%{http_code}\n' -H 'Accept: text/html' http://localhost:5199/some-route                       # 200

Without STRICT=extended (strict: true), all three return 200.

System Info

System:
  OS: macOS 27.2.1
  CPU: (18) arm64 Apple M5 Pro
Binaries:
  Node: 26.13.1
  npm: 12.2.3
npmPackages:
  vite: 8.4.0

Used Package Manager

npm

Logs

The request id "/home" is outside of Vite serving allow list.

Validations

Activity

  1. moonlorddev commented on Nov 27, 2026

    @moonlorddev

    I'd like to take this one. Reproduced on Windows too (/Users → 403 with strict: 'extended', 200 with strict: true).

    The extensionless URL is treated as a JS request (isJSRequest), resolves to the absolute path /home, and with 'extended' isServerAccessDeniedForTransform runs checkLoadingAccess on it. That returns 'denied' because isFileReadable is also true for directories, so the transform middleware sends 403 instead of letting the request fall through to the SPA fallback.

    My fix makes checkLoadingAccess return 'fallback' instead of 'denied' when the path is a directory, since a directory can't be loaded or served anyway. A directory with an index.js still resolves to the file, which is still denied. I added a test in dev.spec.ts that requests the first segment of the temp dir (e.g. /tmp, /var, /Users) and expects the HTML fallback. Does this approach look OK?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions