Skip to content

🛡️ Sentinel: [HIGH] Fix timing side-channel vulnerability in constant-time comparison#319

Draft
EffortlessSteven wants to merge 1 commit intomainfrom
sentinel/fix-constant-time-eq-2180715446142688830
Draft

🛡️ Sentinel: [HIGH] Fix timing side-channel vulnerability in constant-time comparison#319
EffortlessSteven wants to merge 1 commit intomainfrom
sentinel/fix-constant-time-eq-2180715446142688830

Conversation

@EffortlessSteven
Copy link
Copy Markdown
Member

🚨 Severity: HIGH
💡 Vulnerability: The constant_time_eq implementation manually iterated over bytes using a bitwise fold (^). Compilers (like LLVM) often recognize these patterns and aggressively optimize them into standard, short-circuiting sequence comparisons (or auto-vectorize them in ways that vary execution time). This optimization defeats the constant-time intent, re-introducing potential timing side-channels during token verification.
🎯 Impact: Attackers could potentially use timing measurements to iteratively guess valid authentication tokens character by character.
🔧 Fix: Replaced the manual implementation with the industry-standard subtle crate's ConstantTimeEq trait (ct_eq). The subtle crate uses compiler black-boxes and inline assembly to guarantee constant-time evaluation and prevent dangerous compiler optimizations. Added subtle as a dependency in Cargo.toml.
✅ Verification: Ran cargo fmt, cargo clippy, and cargo test -p http-auth-verifier. All 18 tests passed successfully.


PR created automatically by Jules for task 2180715446142688830 started by @EffortlessSteven

@google-labs-jules
Copy link
Copy Markdown

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

Warning

Rate limit exceeded

@EffortlessSteven has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 12 minutes and 37 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 12 minutes and 37 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 18bae3f3-3dcc-4164-b2ae-7f8915deff86

📥 Commits

Reviewing files that changed from the base of the PR and between 90fd4d1 and f565d33.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • crates/http-auth-verifier/Cargo.toml
  • crates/http-auth-verifier/src/lib.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sentinel/fix-constant-time-eq-2180715446142688830

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces a manual constant-time equality implementation with the subtle crate's ConstantTimeEq trait. Feedback suggests managing the new dependency via the workspace root for consistency and removing a now-redundant length check within the constant_time_eq function.

[dependencies]
jsonwebtoken = { version = "10.2.0", features = ["rust_crypto"] }
serde.workspace = true
subtle = "2.6.1"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency and better dependency management within the workspace, it's recommended to define this dependency in the root Cargo.toml and reference it here using subtle.workspace = true. This aligns with how other dependencies like serde and tracing are managed in this file.

Suggested change
subtle = "2.6.1"
subtle.workspace = true

}

left.bytes().zip(right.bytes()).fold(0_u8, |acc, (x, y)| acc | (x ^ y)) == 0
left.as_bytes().ct_eq(right.as_bytes()).into()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ct_eq method on slices from the subtle crate already includes a length check. This makes the explicit length check on lines 93-95 redundant. Consider removing it to simplify the function.

@github-actions
Copy link
Copy Markdown

Test Results

283 tests   245 ✅  11m 23s ⏱️
 25 suites   38 💤
  1 files      0 ❌

Results for commit f565d33.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant