1| const fs = require("fs");
2| const path = require("path");
3|
4| module.exports = (filepath) => {
5| const traversals = filepath.match(/\.\.\//g) || [];
6| if (traversals.length <= 1) {
7| // How bad could it be?
8| // I should just let it happen.
9| // There's no way they can read the flag in ./stuff/flag.txt
10| } else if (traversals.length == 2) {
11| // Okay maybe this is kinda bad.
12| filepath = filepath.replace(/\.\.\//g, "");
13| } else {
14| // Okay this is really bad.
15| // This is completely safe by the way so look elsewhere.
16| filepath = path.resolve("/", filepath);
17| }
18| return fs.readFileSync(path.join(__dirname, "stuff/things", filepath));
19| };