Skip to content

fix(auth): harden API token comparison against length timing leakage - #830

Draft
seonghobae wants to merge 4 commits into
developfrom
fix-timing-attack-15728117960867049387
Draft

fix(auth): harden API token comparison against length timing leakage#830
seonghobae wants to merge 4 commits into
developfrom
fix-timing-attack-15728117960867049387

Conversation

@seonghobae

@seonghobae seonghobae commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Current boundary

  • protected base: develop@e06b1f3fb10903569124af011da213951e6e2473
  • exact head: 8d08a83a3a77b9f114843d76f37c400c7ab6138b
  • lifecycle: Draft / side-channel hardening / exploitability and timing acceptance pending

The security premise is narrower than the previous title implied. Python's hmac.compare_digest() is designed to avoid content-based short-circuiting, but the Python documentation explicitly notes that differing lengths can theoretically reveal information about operand types and lengths. The current source therefore compares credential length first and, on mismatch, executes a same-length dummy compare_digest(expected_token, expected_token) before returning 401; equal-length credentials still use compare_digest(credentials, expected_token).

This is a defensible length-side-channel hardening. It is not yet evidence of a remotely exploitable token-recovery vulnerability, and it must not be promoted as one without a realistic timing experiment that separates network/runtime noise from the signal and shows why token length is itself sensitive in the deployment model.

Review findings

The effective PR is wider than the causal authentication change. In addition to src/newsdom_api/main.py, it contains generated .jules/sentinel.md doctrine and formatter-only churn across schema/auth tests. The Sentinel entry is especially invalid as repository authority because it is dated 2026-10-27, a future date relative to the current repository state, and states a stronger constant-time guarantee than has been demonstrated. These unrelated/generated deltas must be removed or reconciled non-destructively before Ready; do not treat them as security evidence.

RED/GREEN acceptance

RED, if the side-channel claim is retained, should measure the protected implementation and candidate under repeated local process-level requests with equal-content-different-length and equal-length-wrong-content credentials, with randomized trial order, warm-up excluded only by a predeclared rule, and median/p95/distribution evidence. Network benchmarks alone are insufficient for causal attribution.

GREEN requires:

  • correct token -> existing success behavior;
  • wrong token, same length -> 401 through compare_digest(credentials, expected_token);
  • wrong token, shorter/longer -> 401 after the dummy same-length comparison;
  • malformed scheme/separator/empty credential behavior unchanged;
  • current exact-head application/Security/SAST/CodeQL checks;
  • no measurable regression in request-path latency beyond the intended comparison work;
  • qualifying independent current-head review with no valid unresolved findings.

If realistic measurement cannot establish a material length signal or token length is not sensitive in the deployment threat model, keep the code only as low-cost defense in depth and withdraw vulnerability/exploit language.

No force push, destructive rebase, self-approval, source-neutral retrigger, synthetic status, predecessor-GREEN transfer, scanner suppression or gate weakening.

@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

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

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.

@seonghobae seonghobae changed the title API 토큰 검증 시 발생하는 타이밍 공격 취약점 수정 fix(auth): harden API token comparison against length timing leakage Sep 8, 2026
@seonghobae
seonghobae marked this pull request as draft September 8, 2026 23:04
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