Skip to content

Commit ec7d824

Browse files
authored
Prevent path traversal (lukejacksonn#70)
1 parent b02fd6d commit ec7d824

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

servor.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ module.exports = async ({
152152
// Start the server and route requests
153153

154154
server((req, res) => {
155-
const pathname = decodeURI(url.parse(req.url).pathname);
155+
const decodePathname = decodeURI(url.parse(req.url).pathname);
156+
const pathname = path.normalize(decodePathname).replace(/^(\.\.(\/|\\|$))+/, '');
156157
res.setHeader('access-control-allow-origin', '*');
157158
if (reload && pathname === '/livereload') return serveReload(res);
158159
if (!isRouteRequest(pathname)) return serveStaticFile(res, pathname);

0 commit comments

Comments
 (0)