INNER CODE UNIT · JavaScript
readFile
Adamkadaban/CTFs · 1.CTFs/CSAW Red 2020/web/traverse 2/index.js:10
function readFile(filepath) {
return fs.readFileSync(filepath, {encoding: 'utf8'});
}
app.use(logger());
app.use(async ctx => {
// Get the filepath from the http get query
// https://en.wikipedia.org/wiki/Query_string
const filepath = ctx.query.filepath || 'index.html';
// We shouldn't accept filepaths that start with /
if (filepath.startsWith('/')) {
ctx.body = 'You cant trick me this time!';
return;
}
// Return the file as a response