🛡️ Sentinel: Harden equality checks against timing-based length leakage#56
🛡️ Sentinel: Harden equality checks against timing-based length leakage#56SuvenSeo wants to merge 1 commit into
Conversation
Updated `safeEqual` in `auth.js` and `safeEqualText` in `proxy.js` to hash inputs with SHA-256 before constant-time comparison. This prevents attackers from discovering secret lengths through timing side-channels. - In Node.js environment (`auth.js`), used `node:crypto`'s `createHash` and `timingSafeEqual`. - In Edge environment (`proxy.js`), used `crypto.subtle.digest` and a manual constant-time comparison loop to maintain compatibility while improving security. - Updated call sites in `proxy.js` to handle the new asynchronous `safeEqualText`. - Verified with full test suite (34/34 passing). - Documented in `.jules/sentinel.md`. Co-authored-by: SuvenSeo <263689617+SuvenSeo@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR hardens secret/token equality checks to reduce timing-based secret length leakage across both Node.js (server) and Edge runtime code paths, aligning with the existing authentication and dashboard-session mechanisms.
Changes:
- Updates Node.js
safeEqualto SHA-256 hash both inputs beforetimingSafeEqual, ensuring fixed-length comparisons. - Updates Edge
safeEqualTextto SHA-256 hash both inputs before constant-time byte comparison, and updates the call site toawaitit. - Adds a Sentinel security journal entry documenting the issue and prevention pattern.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| frontend/src/proxy.js | Makes Edge-side equality checking hash-based and async to compare fixed-length digests. |
| frontend/src/lib/middleware/auth.js | Makes server-side secret comparisons hash-based before timingSafeEqual to avoid length-based short-circuiting. |
| .jules/sentinel.md | Documents the vulnerability and mitigation approach in the security journal. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| export function safeEqual(a = '', b = '') { | ||
| const left = Buffer.from(a); | ||
| const right = Buffer.from(b); | ||
| return left.length === right.length && timingSafeEqual(left, right); | ||
| const leftHash = createHash('sha256').update(String(a)).digest(); | ||
| const rightHash = createHash('sha256').update(String(b)).digest(); | ||
| return timingSafeEqual(leftHash, rightHash); | ||
| } |
🛡️ Sentinel Security Improvement
Severity: HIGH
Vulnerability: Timing-based length leakage in secret comparison utilities.
Impact: Attackers could determine the exact length of authentication secrets (like
CRON_SECRETorDASHBOARD_PASSWORD) by measuring the time taken for equality checks to return, facilitating brute-force or targeted attacks.Fix: Hardened
safeEqual(Node.js) andsafeEqualText(Edge) to hash both the expected secret and the provided input with SHA-256 before performing a constant-time comparison. This ensures the comparison is always done on fixed-length buffers (32 bytes), hiding the original secret length.Verification:
npm testin thefrontenddirectory; all 34 tests passed, including authentication and Telegram webhook verification..jules/sentinel.md.PR created automatically by Jules for task 2039664027867004474 started by @SuvenSeo