Skip to content
Open
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
16 changes: 16 additions & 0 deletions server/routes/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@ import path from "path";
import fs from "fs";
const BASEPATH = process.env.BASEPATH;

// From: https://github.com/pillarjs/send/blob/master/index.js#L63
var UP_PATH_REGEXP = /(?:^|[\\/])\.\.(?:[\\/]|$)/;

const assets = (req, res) => {
let filePath = req.originalUrl;

try {
filePath = decodeURIComponent(filePath);
} catch (err) {
return res.status(403).send(new Error("invalid url"));
}
if (~filePath.indexOf("\0")) {
return res.status(403).send(new Error("null byte attack dedected!!"));
}
if (UP_PATH_REGEXP.test(filePath)) {
return res.status(403).send(new Error("LFI attack dedected!!!"));
}

if (BASEPATH) {
filePath = req.originalUrl.replace(`/${BASEPATH}`, ``);
}
Expand Down