mirror of
https://github.com/github/codeql.git
synced 2026-04-24 16:25:15 +02:00
Use better sanitiser.
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
const app = require("express")();
|
||||
|
||||
function isRelativePath(path) {
|
||||
return !/^(\w+:)?[/\\]{2}/.test(path);
|
||||
function isLocalUrl(path) {
|
||||
try {
|
||||
return (
|
||||
new URL(path, "https://example.com").origin === "https://example.com"
|
||||
);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
app.get("/redirect", function (req, res) {
|
||||
// GOOD: check that we don't redirect to a different host
|
||||
let target = req.query["target"];
|
||||
if (isRelativePath(target)) {
|
||||
if (isLocalUrl(target)) {
|
||||
res.redirect(target);
|
||||
} else {
|
||||
res.redirect("/");
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
const app = require("express")();
|
||||
|
||||
function isRelativePath(path) {
|
||||
return !/^(\w+:)?[/\\]{2}/.test(path);
|
||||
function isLocalUrl(path) {
|
||||
try {
|
||||
return (
|
||||
new URL(path, "https://example.com").origin === "https://example.com"
|
||||
);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
app.get("/redirect", function (req, res) {
|
||||
// GOOD: check that we don't redirect to a different host
|
||||
let target = req.query["target"];
|
||||
if (isRelativePath(target)) {
|
||||
if (isLocalUrl(target)) {
|
||||
res.redirect(target);
|
||||
} else {
|
||||
res.redirect("/");
|
||||
|
||||
Reference in New Issue
Block a user