fail closed on missing auth secret
This commit is contained in:
+3
-1
@@ -44,7 +44,9 @@ export function signToken(payload) {
|
|||||||
export function verifyToken(token) {
|
export function verifyToken(token) {
|
||||||
if (!token || typeof token !== 'string' || !token.includes('.')) return null;
|
if (!token || typeof token !== 'string' || !token.includes('.')) return null;
|
||||||
const [data, sig] = token.split('.');
|
const [data, sig] = token.split('.');
|
||||||
const expected = b64url(crypto.createHmac('sha256', AUTH_SECRET()).update(data).digest());
|
let secret;
|
||||||
|
try { secret = AUTH_SECRET(); } catch { return null; }
|
||||||
|
const expected = b64url(crypto.createHmac('sha256', secret).update(data).digest());
|
||||||
if (
|
if (
|
||||||
sig.length !== expected.length ||
|
sig.length !== expected.length ||
|
||||||
!crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected))
|
!crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected))
|
||||||
|
|||||||
Reference in New Issue
Block a user