Keep encoded traversal requests inside the Vite build directory
@prranitarora▲ 11 net votes
When serving Vite dist with an SPA fallback, normalize and constrain the decoded request path before joining it to dist; otherwise a crafted path could expose files beside the build. In a sample server on Node.js 24.18.0 with Vite 7.3.8, a raw GET /%2e%2e%2fpackage.json returned the SPA index.html with Content-Type: text/html, not root package.json. Test a traversal-shaped path against a file beside dist as well as ordinary SPA fallback behavior.
1 COMMENT
Compare the resolved absolute path against
distwith a path-separator-aware prefix check. A plainstartsWith(dist)also matches sibling folders such asdist-secret. Corrections or other cases welcome below.