{"id":"d73f83e8d6dd5b75","repo":"vitest-dev/vitest","slug":"access-denied-to-path-see-vite-config-docume","errorCode":null,"errorMessage":"Access denied to \"${path}\". See Vite config documentation for \"server.fs\": https://vitejs.dev/config/server-options.html#server-fs-strict.","messagePattern":"Access denied to \"(.+?)\"\\. See Vite config documentation for \"server\\.fs\": https://vitejs\\.dev/config/server-options\\.html#server-fs-strict\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser/src/node/rpc.ts","lineNumber":120,"sourceCode":"          sessions.destroySession(sessionId)\n        }\n        // this will reject any hanging methods if there are any\n        rpc.$close(\n          new Error(`[vitest] Browser connection was closed while running tests. Was the page closed unexpectedly?`),\n        )\n      })\n    })\n  })\n\n  // we don't throw an error inside a stream because this can segfault the process\n  function error(err: Error) {\n    console.error(err)\n    vitest.state.catchError(err, 'RPC Error')\n  }\n\n  function checkFileAccess(path: string) {\n    if (!isFileLoadingAllowed(vite.config, path)) {\n      throw new Error(\n        `Access denied to \"${path}\". See Vite config documentation for \"server.fs\": https://vitejs.dev/config/server-options.html#server-fs-strict.`,\n      )\n    }\n  }\n\n  function canWrite(project: TestProject) {\n    return (\n      project.config.api.allowWrite\n      && project.vitest.config.api.allowWrite\n    )\n  }\n\n  function isCdpAllowed(project: TestProject) {\n    return (\n      project.config.api.allowExec\n      && project.vitest.config.api.allowExec\n      && project.config.api.allowWrite\n      && project.vitest.config.api.allowWrite","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/browser/src/node/rpc.ts#L102-L138","documentation":"`checkFileAccess` runs every snapshot/attachment/benchmark path through Vite's `isFileLoadingAllowed`, which enforces `server.fs.allow` and `server.fs.strict`. If the path falls outside the allowed roots, the call is rejected to prevent arbitrary filesystem reads/writes from the browser.","triggerScenarios":"Any RPC method that touches the filesystem (`readSnapshotFile`, `saveSnapshotFile`, `removeSnapshotFile`, attachment recording, benchmark read/write) with a path outside Vite's `server.fs.allow` list while `server.fs.strict` is on (the default).","commonSituations":"Custom `resolveSnapshotPath` that resolves outside the workspace root; symlinked test files whose real path is outside root; monorepo where the test file is in one package but snapshots write to another; cross-drive paths on Windows.","solutions":["Add the offending root to `server.fs.allow` in the Vite/Vitest config: `server: { fs: { allow: ['/abs/path'] } }`.","Make sure `resolveSnapshotPath` / custom attachment paths resolve under the project root.","If intentional, set `server.fs.strict: false` (less safe — only when you trust all test code).","On Windows, prefer forward-slash absolute paths to avoid drive-letter edge cases."],"exampleFix":"// before\nexport default defineConfig({\n  test: { server: { fs: { strict: true } } },\n})\n\n// after — explicitly allow the snapshot root\nexport default defineConfig({\n  test: {\n    server: { fs: { allow: ['/home/me/project', '/home/me/shared-snapshots'] } },\n  },\n})","handlingStrategy":"validation","validationCode":"import { isFileLoadingAllowed } from 'vitest/node'\n\nfunction assertFsAllowed(viteConfig: import('vite').InlineConfig, path: string): void {\n  if (!isFileLoadingAllowed(viteConfig, path)) {\n    throw new Error(`Path ${path} is outside server.fs.allow — add it or use a path under root`)\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await fs.writeFile(snapshotPath, content)\n} catch (err) {\n  if (err instanceof Error && /Access denied to/.test(err.message)) {\n    // add the path to server.fs.allow, or move under root\n  }\n  throw err\n}","preventionTips":["Keep snapshot/attachment paths under the project root.","Add extra roots to `server.fs.allow` rather than disabling strict mode.","On Windows use forward-slash absolute paths."],"tags":["filesystem","security","vite-config","snapshot"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}