Skip to content

🛡️ Sentinel: [CRITICAL] hmac.compare_digest를 통한 API 키 DoS 취약점 수정 - #295

Closed
seonghobae wants to merge 1 commit into
mainfrom
fix-hmac-compare-digest-15036794377237530148
Closed

🛡️ Sentinel: [CRITICAL] hmac.compare_digest를 통한 API 키 DoS 취약점 수정#295
seonghobae wants to merge 1 commit into
mainfrom
fix-hmac-compare-digest-15036794377237530148

Conversation

@seonghobae

Copy link
Copy Markdown
Contributor

🚨 Severity: CRITICAL
💡 Vulnerability: hmac.compare_digest TypeError 발생으로 인한 DoS (CWE-400)
🎯 Impact: 악의적인 사용자가 X-API-Key 헤더에 non-ASCII 문자를 포함하여 요청을 보낼 경우 TypeError가 발생하여 500 Internal Server Error를 유발하고, 서비스 거부(DoS) 공격이 가능합니다.
🔧 Fix: 제공된 키와 구성된 키 모두를 utf-8로 인코딩한 바이트 객체로 변환하여 hmac.compare_digest에 전달함으로써 non-ASCII 문자에 대한 처리 오류를 방지했습니다.
✅ Verification: pytest 테스트를 실행하여 정상적으로 동작하는지 확인했습니다.


PR created automatically by Jules for task 15036794377237530148 started by @seonghobae

Copilot AI review requested due to automatic review settings July 26, 2026 17:28
@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 Jul 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@seonghobae, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 6 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 80d6a2d0-5a04-425b-bc54-749348fdb88e

📥 Commits

Reviewing files that changed from the base of the PR and between 5a92586 and d6fda56.

📒 Files selected for processing (2)
  • .jules/sentinel.md
  • saas_web.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-hmac-compare-digest-15036794377237530148

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Mitigates a DoS condition in the FastAPI API-key middleware by ensuring hmac.compare_digest receives byte inputs (avoiding TypeError on non-ASCII header values), and records the incident/mitigation in the Sentinel security log.

Changes:

  • Encode both the provided X-API-Key header value and configured keys as UTF-8 bytes before calling hmac.compare_digest.
  • Document the vulnerability and prevention guidance in .jules/sentinel.md.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
saas_web.py Hardens API key comparison against non-ASCII inputs by comparing bytes via hmac.compare_digest.
.jules/sentinel.md Adds a Sentinel entry describing the DoS vector and the byte-encoding prevention rule.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread saas_web.py
Comment on lines 115 to 118
provided_key = request.headers.get("x-api-key", "")
if not any(
hmac.compare_digest(provided_key, key) for key in configured_keys
hmac.compare_digest(provided_key.encode("utf-8"), key.encode("utf-8")) for key in configured_keys
):
Comment thread saas_web.py
Comment on lines 115 to 118
provided_key = request.headers.get("x-api-key", "")
if not any(
hmac.compare_digest(provided_key, key) for key in configured_keys
hmac.compare_digest(provided_key.encode("utf-8"), key.encode("utf-8")) for key in configured_keys
):

Copy link
Copy Markdown
Contributor Author

Superseded by canonical PR #361, which implements the same non-ASCII API-key comparison fix and consolidates credential access, owned result storage, retention cleanup, and regression evidence. Closing this duplicate.

@seonghobae seonghobae closed this Aug 7, 2026
@google-labs-jules

Copy link
Copy Markdown

Superseded by canonical PR #361, which implements the same non-ASCII API-key comparison fix and consolidates credential access, owned result storage, retention cleanup, and regression evidence. Closing this duplicate.

Understood. Acknowledging that this work is now obsolete and stopping work on this task.

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.

2 participants