Skip to content

Commit bed93f1

Browse files
timursevimlitshemsedinov
authored andcommitted
Add path traversal
1 parent bd71f6d commit bed93f1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

JavaScript/d-messenger/lib/static.js

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ module.exports = (root, port, console) => {
2828
.createServer(async (req, res) => {
2929
const url = req.url === '/' ? '/index.html' : req.url;
3030
const filePath = path.join(root, url);
31+
if (!filePath.startsWith(root)) {
32+
res.statusCode = 404;
33+
return void res.end('"File is not found"');
34+
}
3135
try {
3236
const data = await fs.promises.readFile(filePath);
3337
const fileExt = path.extname(filePath).substring(1);

0 commit comments

Comments
 (0)