diff --git a/frontend/html/poll.html b/frontend/html/poll.html index 8ee9f65..ca51be6 100644 --- a/frontend/html/poll.html +++ b/frontend/html/poll.html @@ -36,6 +36,7 @@
+
{{ POLL_TITLE }}
diff --git a/src/backend.ts b/src/backend.ts index 0ce5e8c..de9acdb 100644 --- a/src/backend.ts +++ b/src/backend.ts @@ -4,6 +4,7 @@ import { CookieOptions, Router } from "express"; import { BackendPoll as Poll, DupeCheckMode } from "./Poll"; import { MAX_POLL_OPTIONS, MAX_CHARACTER_LENGTH } from "./Config"; import Storage from "./Storage"; +import crypto from "crypto"; function randomString(length = 10, charset = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789") { let result = ""; @@ -213,12 +214,25 @@ export default async function init(router: Router, polls: Storage): Promise` ).join(""); + const csrfToken = req.cookies.csrftoken || crypto.randomBytes(32).toString("base64"); + res.cookie("csrftoken", csrfToken, { + httpOnly: true, + }); + await displayPage(req, res, "poll.html", { + "CSRF_TOKEN": csrfToken, "POLL_ID": poll.id, "POLL_TITLE": xss(poll.title), "POLL_OPTION_DIVS": pollOptions,