Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion routes/fileServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,19 @@ router.post('*splat', (req, res, next) => {
} else if (req.query.action === 'create-folder') {
const newPath = `${req.path}/folders`;

if (!isLocalUrl(newPath)) {
// Only allow strictly relative paths, no path traversal, not protocol-relative, not external host
function isSafeRelativePath(path) {
// must start with a single "/"
if (typeof path !== 'string' || !path.startsWith('/')) return false;
// must not contain "//"
if (path.includes('//')) return false;
// must not contain ".."
if (path.includes('..')) return false;
// optional: restrict to allowed base directory/prefix
return true;
}

if (!isSafeRelativePath(newPath)) {
logger.warn('Rejected potentially unsafe redirect', { path: newPath });
return res.status(400).send('Invalid redirect path');
}
Expand Down