Skip to content

Commit 3833267

Browse files
authored
Revert "Potential fix for code scanning alert no. 3: Uncontrolled data used in path expression"
1 parent 277a594 commit 3833267

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

pages/api/download.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@ export default function handler(req, res) {
1212
return res.status(400).json({ error: 'Filename is required' });
1313
}
1414

15-
// Securely construct a path under the uploads directory
16-
const uploadsRoot = path.join(process.cwd(), 'uploads');
17-
const resolvedPath = path.resolve(uploadsRoot, String(filename));
18-
19-
// Ensure the resolved path is within the uploads root to prevent path traversal
20-
if (!resolvedPath.startsWith(uploadsRoot + path.sep) && resolvedPath !== uploadsRoot) {
21-
return res.status(400).json({ error: 'Invalid filename' });
22-
}
23-
15+
// VULNERABILITY: Path Traversal
16+
// User input is used directly to construct file paths
17+
// An attacker could use input like: "../../../../etc/passwd"
18+
const filePath = path.join(process.cwd(), 'uploads', filename);
19+
2420
try {
25-
const fileContent = fs.readFileSync(resolvedPath, 'utf8');
21+
// Reading file without proper validation
22+
const fileContent = fs.readFileSync(filePath, 'utf8');
2623

2724
res.status(200).json({
2825
filename: filename,

0 commit comments

Comments
 (0)