Skip to content

Resolver tries to access absolute paths and crashes #12523

Closed
@DASPRiD

Description

Describe the bug

When trying to access a path in a vite project which corresponds to an absolute path on your local disk, but is unreadable by the current users, vite crashes with an EACCESS error.

Ideally, Vite should not try to access absolute paths anywhere in the system. But at the least, it should catch EACCESS errors and know that it the tried path is invalid.

Reproduction

N/A

Steps to reproduce

  1. Be on a Linux system and have a directory /recovery which is only readable by the root user
  2. Create a basic vite project npm create vite@latest test and npm run dev it
  3. Try to access http://localhost:<port>/recovery path

System Info

System:
    OS: Linux 6.2 Pop!_OS 22.04 LTS
    CPU: (32) x64 13th Gen Intel(R) Core(TM) i9-13900K
    Memory: 46.10 GB / 62.54 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.15.0 - /usr/bin/node
    Yarn: 1.22.17 - /usr/bin/yarn
    npm: 9.5.0 - /usr/bin/npm
  Browsers:
    Chrome: 110.0.5481.96
    Firefox: 111.0

Used Package Manager

npm

Logs

12:00:54 AM [vite] Internal server error: EACCES: permission denied, realpath '/recovery/package.json'
      at realpathSync.native (node:fs:2644:3)
      at loadPackageData (file:///tmp/test/test/node_modules/vite/dist/node/chunks/dep-79892de8.js:22177:37)
      at tryResolveFile (file:///tmp/test/test/node_modules/vite/dist/node/chunks/dep-79892de8.js:22883:33)
      at tryFsResolve (file:///tmp/test/test/node_modules/vite/dist/node/chunks/dep-79892de8.js:22862:16)
      at Context.resolveId (file:///tmp/test/test/node_modules/vite/dist/node/chunks/dep-79892de8.js:22731:24)
      at Object.resolveId (file:///tmp/test/test/node_modules/vite/dist/node/chunks/dep-79892de8.js:43314:46)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async ModuleGraph.resolveUrl (file:///tmp/test/test/node_modules/vite/dist/node/chunks/dep-79892de8.js:61580:26)
      at async ModuleGraph.getModuleByUrl (file:///tmp/test/test/node_modules/vite/dist/node/chunks/dep-79892de8.js:61437:23)
      at async doTransform (file:///tmp/test/test/node_modules/vite/dist/node/chunks/dep-79892de8.js:41010:20)

Validations

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions