NewNode 26.14: mockResolvedValue and Friends in node:test →
w3/w3-tutorials

Vite 8.4: Lock Down the Dev Server With an Allow-List

Vite 8.4 can serve only the files your app references. Turn it on in two lines, see what breaks, and pick up CSS subpath imports and duplicate-server detection on the way.

Updated Nov 27, 20268 min readIntermediatevite 8.4.0 · node 22.22.3 · typescript 7.0.2

Vite 8.4 came out on November 26, 2026. The headline change is a stricter way to decide which files the dev server will hand out. By default, Vite serves almost any file inside your project to anyone who can reach the dev server. With two config lines it can now serve only the files your app actually references.

This guide upgrades a fresh project, turns that allow-list on, and shows what it breaks. It then covers the other changes you can use today: subpath imports in CSS url(), a guard against running the same dev server twice, a new hook for plugin authors, and two deprecations. Every command below was run against Vite 8.4.0 on Node 22.22.3.

1. Upgrade

Start from a new vanilla TypeScript project, or run the second command in an existing one:

terminal
npm create vite@latest vite84-demo -- --template vanilla-ts --no-interactive
cd vite84-demo && npm install
npm install -D [email protected]
npx vite --version
text
vite/8.4.0 darwin-arm64 node-v22.22.3

Vite 8.4 is a minor release, so existing configs keep working. The allow-list is opt-in. Two changes apply straight away: duplicate dev servers now fail to start (step 7), and CSS url() now resolves subpath imports (step 6).

2. See what the dev server serves today

Add a file that should never reach a browser, plus a module that nothing imports:

terminal
mkdir internal && echo '{"dbPassword":"hunter2"}' > internal/config.json
echo 'export const unused = 1' > src/unused.ts

Start the dev server with npx vite --port 3000 and ask for the file from another terminal:

terminal
curl -s http://localhost:3000/internal/config.json
text
{"dbPassword":"hunter2"}

That's the default. server.fs.strict stops requests for files outside the workspace root, and server.fs.deny blocks a short list of known secrets such as .env and *.pem. Anything else inside the project is fair game.

That's fine on localhost. It's a problem when the server is reachable from elsewhere: --host on shared Wi-Fi, a dev container with a forwarded port, or a tunnel. The Vite 8.4 announcement explains that the block-list kept needing patches for bypasses that exploit file system and HTTP parsing quirks. The allow-list is the fix.

3. Turn on the allow-list

vite.config.ts
import { defineConfig } from 'vite'

export default defineConfig({
  server: {
    fs: {
      strict: 'extended',
      allow: [],
    },
  },
})

You need both lines. strict: 'extended' also runs the access check on modules that plugins load. allow: [] drops the default "whole workspace" entry from server.fs.allow. With only strict: 'extended', internal/config.json still returned 200.

Restart the server and request a few files before opening the page:

terminal
for p in /src/main.ts /src/counter.ts /src/unused.ts /internal/config.json; do
  echo "$p $(curl -s -o /dev/null -w '%{http_code}' http://localhost:3000$p)"
done
text
/src/main.ts 403
/src/counter.ts 403
/src/unused.ts 403
/internal/config.json 403

Everything is blocked, even your own entry file. Vite builds the allow-list as it serves your app: index.html references /src/main.ts, which imports counter.ts, and so on. Load the page, which is what a browser does, and run the same loop again:

terminal
curl -s http://localhost:3000/ > /dev/null
curl -s http://localhost:3000/src/main.ts > /dev/null
text
/src/main.ts 200
/src/counter.ts 200
/src/unused.ts 403
/internal/config.json 403

Now only files reachable from the entry point are served. unused.ts sits in src/, but nothing imports it, so it stays blocked. The dev terminal logs each refusal:

text
The request id "…/vite84-demo/internal/config.json" is outside of Vite serving allow list.

4. Know what the allow-list breaks

Vite only allows what it can see in your code. Imports, CSS url() and HTML references count. A path in a plain string does not. Here are three ways to point at a file:

src/extras.ts
declare const __RUNTIME_URL__: string

// Vite can see this reference: new URL(..., import.meta.url)
export const menuUrl = new URL('./data/menu.json', import.meta.url).href

// Vite can't see this one: a plain string you later pass to fetch()
export const plainUrl = '/src/data/plain.json'

// A plugin swaps this placeholder for a URL (see vite.config.ts)
export const runtimeUrl = __RUNTIME_URL__

Create the files it points to and import it from src/main.ts:

terminal
mkdir -p src/data
echo '{"items":["home","docs"]}' > src/data/menu.json
echo '{"items":["a"]}' > src/data/plain.json
echo 'export function start() { return "runtime ok" }' > internal/runtime.js
src/main.ts
import { menuUrl, plainUrl, runtimeUrl } from './extras.ts'

console.log(menuUrl, plainUrl, runtimeUrl)

After loading the page and /src/extras.ts, these were the results:

text
/src/data/menu.json 200
/src/data/plain.json 403
/internal/runtime.js 200

The new URL(..., import.meta.url) form passes because Vite rewrites it and records the reference. The plain string fails: your fetch('/src/data/plain.json') worked yesterday and returns 403 today. Move files like that into public/, which the allow-list doesn't cover, or switch to new URL().

5. For plugin authors: addSafeModule

The /internal/runtime.js request above passed because the plugin that inserts that URL registers it. This is the full config:

vite.config.ts
import { fileURLToPath } from 'node:url'
import { defineConfig, normalizePath, type Plugin } from 'vite'

const runtimeId = normalizePath(
  fileURLToPath(new URL('./internal/runtime.js', import.meta.url)),
)

function runtimePlugin(): Plugin {
  return {
    name: 'inject-runtime-url',
    transform: {
      filter: { code: '__RUNTIME_URL__' },
      handler(code) {
        if (this.environment.mode === 'dev') {
          this.environment.addSafeModule(runtimeId)
        }
        return code.replaceAll('__RUNTIME_URL__', '"/internal/runtime.js"')
      },
    },
  }
}

export default defineConfig({
  plugins: [runtimePlugin()],
  server: {
    fs: {
      strict: 'extended',
      allow: [],
    },
  },
})

With the if block removed and the same requests repeated, the runtime file was refused:

text
/internal/runtime.js 403

Pass a normalized absolute path, and register it in the same transform call that adds the reference. The Environment API docs cover IDs with query strings. If your plugin injects URLs, ship this now. The Vite team says the allow-list will become the default in the next major.

6. Use subpath imports in CSS url()

Vite already resolved Node subpath imports (the #-prefixed imports field in package.json) in JavaScript. 8.4 also resolves them in CSS url(). Add an alias:

package.json
  "imports": {
    "#assets/*": "./src/assets/*"
  }

Use it in a stylesheet a few folders deep, and import that stylesheet from src/main.ts:

src/components/card/card.css
.card {
  /* Resolved through "imports" in package.json */
  background-image: url('#assets/hero.png');
}

.card svg {
  /* Not a subpath import, so Vite leaves the hash URL alone */
  filter: url('#glow');
}
terminal
npm run build
grep -o '\.card[^}]*}' dist/assets/*.css
text
.card{background-image:url(/assets/hero-CLDdwZDr.png)}
.card svg{filter:url(#glow)}

#assets/hero.png became a hashed asset. #glow has no matching imports entry, so it stays an SVG fragment reference. Vite tries the subpath import first and falls back to the raw hash URL.

The same build on Vite 8.3.8 printed .card{background-image:url(#assets/hero.png)}. The build succeeded, and the image was silently missing. If you use subpath imports, pin vite to at least 8.4.0 so nobody on the team builds with the old behavior.

The announcement now recommends subpath imports over resolve.alias and tsconfig paths, because Node and TypeScript understand them too.

7. Stop starting the dev server twice

With a dev server already running, a second npx vite --port 3000 in the same project now exits:

text
error when starting dev server:
Error: Found another Vite dev process for this project at http://localhost:3000/ (PID 99354).
Pass --bypass-lock to bypass this check.

On Vite 8.3.8, the same command printed Port 3000 is in use, trying another one... and started a second server on 3001 for the same project. If you really do want two, --bypass-lock gives you the old behavior:

text
Port 3000 is in use, trying another one...
  ➜  Local:   http://localhost:3001/

Scripts that start Vite in the background, for example before an end-to-end test run, should stop any leftover server first. Otherwise they now fail with exit code 1.

8. Fix two deprecation warnings

css.devSourcemap has moved to dev.sourcemap.css:

text
The `css.devSourcemap` option is deprecated. Please use `dev.sourcemap.css` instead.
vite.config.ts
import { defineConfig } from 'vite'

export default defineConfig({
  dev: { sourcemap: { css: true } },
})

--configLoader is now stable, and its runner value is on the way out:

text
The `runner` config loader is deprecated and will be removed in Vite 9. Use `bundle` or `native` instead.

Other changes in 8.4

These weren't run for this guide. The details come from the announcement and the release notes:

  • Retried dynamic imports. An HTML spec change lets browsers retry a failed dynamic import() (Chrome 156+, Firefox 155+, Safari Technology Preview 252). Vite's preload helper now refetches the chunk's CSS too, so a second click after a network blip can succeed.
  • Wasm source phase imports. import source mod from './mod.wasm' gives you a WebAssembly.Module. TypeScript support arrives in TypeScript 7.1, which is in beta. Vite plans to recommend it over .wasm?init once 7.1 is stable. See the TC39 source phase imports proposal.
  • Bundled dev mode for SSR. It's marked highly experimental, and it's groundwork for meta-frameworks.
  • Smaller build changes. Worker chunks are now included in the build manifest, empty CSS files are no longer emitted, and the preview server serves compressed Wasm.

When to hold off on the allow-list

  • You rely on string paths. Apps that fetch() JSON, Markdown or images from src/ by plain path need those files moved or rewritten first.
  • Your plugins inject URLs. Until they call addSafeModule, you'd have to list those files in server.fs.allow yourself.
  • The dev server never leaves localhost. The risk is lower here. Still, turning the allow-list on now, while it's opt-in, means the next major won't surprise you.

Next steps

  • Turn on strict: 'extended' and allow: [] in a branch, click through your app, and grep the dev terminal for "outside of Vite serving allow list".
  • Replace resolve.alias entries that CSS uses with imports in package.json.
  • Read the server options reference for adding specific folders back to the allow-list.

Related tutorials