π‘οΈ Sentinel: [security improvement] Fix timing attack vulnerability in token comparisons#269
Conversation
β¦n token comparisons This change introduces a `safeCompare` utility in `@jeanbot/platform` that implements constant-time string comparison using SHA-256 hashing and `crypto.timingSafeEqual`. The following call-sites have been updated to use `safeCompare`: 1. `assertInternalRequest` in `@jeanbot/platform`, which validates internal service tokens. 2. OAuth state signature verification in `auth-service`. These updates prevent timing attacks that could otherwise leak token or signature values by observing the time taken for standard string comparisons. Verification: - Added `tests/unit/platform-security.test.ts` covering `safeCompare` edge cases. - Ran `pnpm test tests/unit/auth-service.test.ts` to ensure no regressions in authentication flow. - Verified linting with Biome. Co-authored-by: hackerxj2010 <198651211+hackerxj2010@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. |
π‘οΈ Sentinel: [security improvement] Fix timing attack vulnerability in token comparisons
π¨ Severity
MEDIUM
π‘ Vulnerability
The application was using standard string comparison (
!==and===) for sensitive tokens and signatures. Standard string comparison is susceptible to timing attacks, where an attacker can infer the value of a secret by measuring how long the comparison takes (as it typically returns as soon as it finds a mismatching character).π― Impact
An attacker could potentially brute-force internal service tokens or forge OAuth state signatures by observing timing differences in the server's response. This would allow them to bypass internal service authentication or interfere with the OAuth flow.
π§ Fix
safeCompareutility inpackages/platform/src/index.ts.crypto.timingSafeEqual, which runs in constant time.assertInternalRequest(used across most microservices) andAuthService.verifyOAuthStateto use this secure comparison.β Verification
tests/unit/platform-security.test.tsto verifysafeComparecorrectly identifies matches and mismatches while handling edge cases likeundefinedand varying string lengths.auth-servicetests to confirm that normal authentication and OAuth state verification still work correctly.PR created automatically by Jules for task 14114205297027665869 started by @hackerxj2010