This commit is contained in:
Dan Janosik 2021-04-16 09:46:20 -04:00
parent 508e8487f1
commit 587a304c96
No known key found for this signature in database
GPG key ID: 846311D3D259BFF1

View file

@ -12,6 +12,7 @@
const crypto = require('crypto');
const fs = require('fs');
const utils = require("./utils.js");
const authCookieName = "btcexp_auth";
@ -52,11 +53,22 @@ module.exports = (tokenFile, loginRedirect) => {
return next();
}
// We have to use timingSafeEqual to avoid timing attacks
if (crypto.timingSafeEqual(Buffer.from(req.query.token, "utf8"), Buffer.from(token, "utf8"))) {
let matchingToken = false;
if (req.query.token) {
try {
// We use timingSafeEqual to avoid timing attacks
matchingToken = crypto.timingSafeEqual(Buffer.from(req.query.token, "utf8"), Buffer.from(token, "utf8"));
} catch (e) {
utils.logError("23rheuweesaa", e);
}
}
if (matchingToken) {
req.authenticated = true;
token = updateToken(tokenFile);
cookie = generateToken();
let cookie = generateToken();
cookies.add(cookie);
res.cookie(authCookieName, cookie);