fix(auth): constant-time owner-token comparison
Owner bearer token was compared with === / !==, which short-circuits on the first differing byte and leaks token length+prefix via response timing (security-sweep-2026-06-01.md). New timingSafeStrEqual (crypto.timingSafeEqual with a length pre-check so it never throws on length mismatch); wired into both owner.js and agent_auth.js. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import * as agents from '../../db/repos/agents.js';
|
||||
import { timingSafeStrEqual } from '../../auth/safe_compare.js';
|
||||
|
||||
export async function agentOrOwner(req, res, next) {
|
||||
const expectedOwner = process.env.OWNER_TOKEN;
|
||||
@@ -12,7 +13,7 @@ export async function agentOrOwner(req, res, next) {
|
||||
if (scheme !== 'Bearer' || !token) {
|
||||
return res.status(401).json({ error: { code: 'unauthorized', message: 'missing bearer token' } });
|
||||
}
|
||||
if (token === expectedOwner) {
|
||||
if (timingSafeStrEqual(token, expectedOwner)) {
|
||||
req.actor = { kind: 'user', id: null };
|
||||
return next();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user