Skip to content

Commit 49c243b

Browse files
committed
Resolve timing safety with access token fallback
1 parent 41b5bf8 commit 49c243b

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

.github/workflows/setup.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ jobs:
6464
AWS_SECRET_ACCESS_KEY: ""
6565
BUILD_ENGINE_SECRETS_BUCKET: ""
6666
SCRIPTURE_EARTH_KEY: ""
67+
ORIGIN: ""
68+
API_ACCESS_TOKEN: ""
6769
steps:
6870
- uses: actions/checkout@v5
6971
- uses: actions/setup-node@v5

src/lib/server/auth.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { trace } from '@opentelemetry/api';
22
import type { Prisma } from '@prisma/client';
33
import { type RequestEvent, error, redirect } from '@sveltejs/kit';
44
import { jwtDecrypt } from 'jose';
5-
import { createHash, randomUUID } from 'node:crypto';
5+
import { createHash, randomUUID, timingSafeEqual } from 'node:crypto';
66
import { getAuthConnection } from './bullmq/queues';
77
import { prisma } from './prisma';
88
import { env as secrets } from '$env/dynamic/private';
@@ -102,7 +102,12 @@ export async function tryVerifyAPIToken(
102102
}
103103
const client = await prisma.client.findFirst({ where: { access_token } });
104104
if (!client) {
105-
if (access_token === secrets.API_ACCESS_TOKEN) {
105+
if (
106+
timingSafeEqual(
107+
Buffer.from(access_token, 'hex'),
108+
Buffer.from(secrets.API_ACCESS_TOKEN, 'hex')
109+
)
110+
) {
106111
return [true, null];
107112
}
108113
return [false, ErrorResponse(403, 'Invalid Access Token')];

0 commit comments

Comments
 (0)