Chapter 9: XSS samples

This commit is contained in:
Beth Griggs
2020-09-06 00:58:03 +01:00
parent a77f753e2f
commit c4714dffa7
7 changed files with 534 additions and 0 deletions
@@ -0,0 +1,44 @@
const express = require("express");
const app = express();
app.get("*", (req, res) => {
const { previous, lang, token } = req.query;
if (!validateParameters({ previous, token, lang }, req.query)) {
res.sendStatus(422);
return;
}
getServiceStatus((status) => {
res.send(`
<h1>Service Status</h1>
<div id=status>
${status}
</div>
<div>
<a href="${previous}${token}/${lang}">Back</a>
</div>
`);
});
});
getServiceStatus = (callback) => {
const status = "All systems are running.";
callback(status);
};
validateParameters = ({ previous, token, lang }, query) => {
return (
Object.keys(query).length <= 3 &&
typeof lang === "string" &&
lang.length === 2 &&
typeof token === "string" &&
token.length === 16 &&
typeof previous === "string" &&
previous.length <= 16
);
};
app.listen(3000, () => {
console.log("Server listening on port 3000");
});