Loading...
Loading...
Incomplete path sanitization that can be bypassed with double encoding or nested sequences.
1const express = require('express');2const path = require('path');3const fs = require('fs');45app.get('/files/:filename', (req, res) => {6 let filename = req.params.filename;78 // "Sanitize" by removing ../9 filename = filename.replace('../', '');1011 const filepath = path.join('/var/app/data', filename);1213 if (fs.existsSync(filepath)) {14 res.sendFile(filepath);15 } else {16 res.status(404).send('File not found');17 }18});
String.replace() only removes the first occurrence. Attackers use nested sequences (....//), double encoding (%252e%252e/), or mixed encoding to bypass.
Use nested sequences to bypass single replace
....//....//etc/passwd
..././..././etc/passwd
..%2F..%2Fetc/passwdAfter replace: ../etc/passwd - still traverses!