Skip to content

🛡️ Sentinel: [HIGH] Fix timing side-channel in token validation#314

Draft
EffortlessSteven wants to merge 2 commits intomainfrom
sentinel/subtle-constant-time-eq-7811448573488884197
Draft

🛡️ Sentinel: [HIGH] Fix timing side-channel in token validation#314
EffortlessSteven wants to merge 2 commits intomainfrom
sentinel/subtle-constant-time-eq-7811448573488884197

Conversation

@EffortlessSteven
Copy link
Copy Markdown
Member

Scope

Type: Security Fix
Intent: Replace manual fold-based XOR comparison with a compiler-black-boxed constant-time comparison to prevent timing side channels.
Touchpoints: crates/http-auth-verifier/src/lib.rs, crates/http-auth-verifier/Cargo.toml
Evidence: Lints pass, cargo test -p http-auth-verifier passes, implementation defers to audited subtle crate.

🚨 Severity: HIGH
💡 Vulnerability: Manual fold-based byte-by-byte comparisons can be optimized by LLVM (e.g., auto-vectorization, short-circuiting) resulting in variable execution times. This creates a timing side channel that could theoretically allow an attacker to guess the correct basic token length and content character-by-character.
🎯 Impact: Attackers could bypass platform HTTP authentication if they iteratively guess the valid literal basic token.
🔧 Fix: Added the subtle crate and used its ConstantTimeEq trait (ct_eq) which utilizes compiler black boxes to ensure true constant-time evaluation.
✅ Verification: cargo test -p http-auth-verifier runs normally. The proptest confirming that constant_time_eq aligns logically with standard equality still passes perfectly.


PR created automatically by Jules for task 7811448573488884197 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.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements a critical security enhancement by integrating a constant-time comparison mechanism for token validation. This change directly mitigates a high-severity timing side-channel vulnerability, ensuring that authentication processes are robust against attacks that exploit execution time differences to infer sensitive information.

Highlights

  • Security Fix: Timing Side-channel Vulnerability: Replaced a manual fold-based XOR comparison with a compiler-black-boxed constant-time comparison from the subtle crate to prevent timing side-channel attacks during token validation. This addresses a high-severity vulnerability where variable execution times could allow an attacker to guess token content.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 26, 2026

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9f8d8ea9-928d-4132-9b66-273691ba8c13

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

The pull request adds the subtle crate as a dependency and refactors the constant-time string comparison function to use the crate's ConstantTimeEq trait instead of a manual implementation. No new features or public API changes are introduced.

Changes

Cohort / File(s) Summary
Dependency Management
crates/http-auth-verifier/Cargo.toml
Added subtle crate version 2.6.1 to dependencies for constant-time comparison operations.
Comparison Implementation
crates/http-auth-verifier/src/lib.rs
Replaced manual constant-time string comparison with subtle::ConstantTimeEq trait. Added import and updated constant_time_eq function to use ct_eq() method instead of byte-wise XOR operations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A subtle shift, oh what a sight!
No more hand-rolled XORs in the night,
A crate now guards our secrets true,
With constant time in every view! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change as fixing a timing side-channel vulnerability in token validation by using constant-time comparison.
Description check ✅ Passed The description thoroughly explains the security issue, the fix applied, and verification steps performed, all directly related to the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sentinel/subtle-constant-time-eq-7811448573488884197

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 integrates the subtle crate to improve the constant_time_eq function by utilizing subtle::ConstantTimeEq for secure string comparison. The reviewer suggests managing the subtle dependency as a workspace dependency for better consistency.

[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 with other dependencies in this crate (like serde and tracing) and to promote version uniformity across the workspace, it's recommended to manage subtle as a workspace dependency. Please consider adding it to the root Cargo.toml and referencing it here.

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

@github-actions
Copy link
Copy Markdown

Test Results

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

Results for commit e4f2414.

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