Skip to content

Commit 5e71697

Browse files
authored
fix: travel path vulnerability on tutorial pages, merge pull request #233 from rcowsill/fix/path-traversal
Fix path traversal vulnerability
2 parents b2aed38 + 69e3d0d commit 5e71697

File tree

2 files changed

+43
-19
lines changed

2 files changed

+43
-19
lines changed

app/routes/index.js

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ const ContributionsHandler = require("./contributions");
55
const AllocationsHandler = require("./allocations");
66
const MemosHandler = require("./memos");
77
const ResearchHandler = require("./research");
8-
const {
9-
environmentalScripts
10-
} = require("../../config/config");
8+
const tutorialRouter = require("./tutorial");
119
const ErrorHandler = require("./error").errorHandler;
1210

1311
const index = (app, db) => {
@@ -74,25 +72,12 @@ const index = (app, db) => {
7472
return res.redirect(req.query.url);
7573
});
7674

77-
// Handle redirect for learning resources link
78-
app.get("/tutorial", (req, res) => {
79-
return res.render("tutorial/a1", {
80-
environmentalScripts
81-
});
82-
});
83-
84-
app.get("/tutorial/:page", (req, res) => {
85-
const {
86-
page
87-
} = req.params;
88-
return res.render(`tutorial/${page}`, {
89-
environmentalScripts
90-
});
91-
});
92-
9375
// Research Page
9476
app.get("/research", isLoggedIn, researchHandler.displayResearch);
9577

78+
// Mount tutorial router
79+
app.use("/tutorial", tutorialRouter);
80+
9681
// Error handling middleware
9782
app.use(ErrorHandler);
9883
};

app/routes/tutorial.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const express = require("express");
2+
const {
3+
environmentalScripts
4+
} = require("../../config/config");
5+
6+
const router = express.Router();
7+
8+
router.get("/", (req, res) => {
9+
"use strict";
10+
return res.render("tutorial/a1", {
11+
environmentalScripts
12+
});
13+
});
14+
15+
const pages = [
16+
"a1",
17+
"a2",
18+
"a3",
19+
"a4",
20+
"a5",
21+
"a6",
22+
"a7",
23+
"a8",
24+
"a9",
25+
"a10",
26+
"redos",
27+
"ssrf"
28+
];
29+
30+
for(const page of pages) {
31+
router.get(`/${page}`, (req, res) => {
32+
"use strict";
33+
return res.render(`tutorial/${page}`, {
34+
environmentalScripts
35+
});
36+
});
37+
}
38+
39+
module.exports = router;

0 commit comments

Comments
 (0)