Skip to content

Commit

Permalink
Add path traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
timursevimli authored Aug 21, 2023
1 parent 5dc514f commit c1ed77e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions JavaScript/d-messenger/lib/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ module.exports = (root, port, console) => {
.createServer(async (req, res) => {
const url = req.url === '/' ? '/index.html' : req.url;
const filePath = path.join(root, url);
if (!filePath.startsWith(root)) {
res.statusCode = 404;
return void res.end('"File is not found"');
}
try {
const data = await fs.promises.readFile(filePath);
const fileExt = path.extname(filePath).substring(1);
Expand Down

0 comments on commit c1ed77e

Please sign in to comment.