Skip to content

๐Ÿ›ก๏ธ Sentinel: [HIGH] hmac.compare_digest ์˜ˆ์™ธ ์ฒ˜๋ฆฌ ๋ฐ DoS ์ทจ์•ฝ์  ์ˆ˜์ • - #299

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

๐Ÿ›ก๏ธ Sentinel: [HIGH] hmac.compare_digest ์˜ˆ์™ธ ์ฒ˜๋ฆฌ ๋ฐ DoS ์ทจ์•ฝ์  ์ˆ˜์ •#299
seonghobae wants to merge 1 commit into
mainfrom
sentinel-hmac-compare-digest-fix-1454767504914277086

Conversation

@seonghobae

Copy link
Copy Markdown
Contributor

๐Ÿšจ Severity: HIGH
๐Ÿ’ก Vulnerability: hmac.compare_digest ํ•จ์ˆ˜์— ๋น„ ASCII ๋ฌธ์ž๊ฐ€ ํฌํ•จ๋œ ๋ฌธ์ž์—ด์ด ์ „๋‹ฌ๋  ๊ฒฝ์šฐ TypeError๊ฐ€ ๋ฐœ์ƒํ•˜์—ฌ 500 ์„œ๋ฒ„ ์—๋Ÿฌ๋ฅผ ์œ ๋ฐœํ•˜๋Š” ์ฒ˜๋ฆฌ๋˜์ง€ ์•Š์€ ์˜ˆ์™ธ ์ทจ์•ฝ์ ์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.
๐ŸŽฏ Impact: ๊ณต๊ฒฉ์ž๊ฐ€ ์•…์˜์ ์œผ๋กœ ๋น„ ASCII ๋ฌธ์ž๊ฐ€ ํฌํ•จ๋œ X-API-Key ํ—ค๋”๋ฅผ ์ „์†กํ•˜์—ฌ ์„œ๋น„์Šค๋ฅผ ์ค‘๋‹จ์‹œํ‚ค๊ฑฐ๋‚˜ ๋ฆฌ์†Œ์Šค๋ฅผ ์†Œ๋ชจํ•˜๊ฒŒ ํ•˜๋Š” DoS(์„œ๋น„์Šค ๊ฑฐ๋ถ€) ๊ณต๊ฒฉ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๐Ÿ”ง Fix: ๋‘ ์ธ์ž ๋ชจ๋‘ .encode('utf-8')๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ”์ดํŠธ ํ˜•์‹์œผ๋กœ ์ธ์ฝ”๋”ฉํ•œ ํ›„ ๋น„๊ตํ•˜๋„๋ก ์ˆ˜์ •ํ•˜์—ฌ ์˜ˆ์™ธ๋ฅผ ๋ฐฉ์ง€ํ–ˆ์Šต๋‹ˆ๋‹ค.
โœ… Verification: pytest ํ…Œ์ŠคํŠธ ์Šค์œ„ํŠธ๊ฐ€ ๋ชจ๋‘ ํ†ต๊ณผํ•˜๋Š”์ง€ ํ™•์ธํ•˜์˜€๊ณ , ๋ชจ์˜ ํ™˜๊ฒฝ์—์„œ ์œ ๋‹ˆ์ฝ”๋“œ ํ—ค๋”๊ฐ€ ํฌํ•จ๋œ ์š”์ฒญ์ด ์ •์ƒ์ ์œผ๋กœ 401์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ๊ฒƒ์„ ๊ฒ€์ฆํ–ˆ์Šต๋‹ˆ๋‹ค.


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

hmac.compare_digest ํ•จ์ˆ˜์— ๋น„ ASCII ๋ฌธ์ž๊ฐ€ ์ „๋‹ฌ๋  ๋•Œ ์ฒ˜๋ฆฌ๋˜์ง€ ์•Š์€ ์˜ˆ์™ธ(TypeError)๊ฐ€ ๋ฐœ์ƒํ•˜์—ฌ 500 ์„œ๋ฒ„ ์˜ค๋ฅ˜๋ฅผ ์œ ๋ฐœํ•  ์ˆ˜ ์žˆ๋Š” ์ทจ์•ฝ์ ์„ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‘ ์ธ์ž๋ฅผ utf-8 ๋ฐ”์ดํŠธ๋กœ ์ธ์ฝ”๋”ฉํ•œ ํ›„ ๋น„๊ตํ•˜๋„๋ก ๋ณ€๊ฒฝํ•˜์—ฌ DoS ๊ณต๊ฒฉ ์œ„ํ—˜์„ ์ œ๊ฑฐํ–ˆ์Šต๋‹ˆ๋‹ค.
Copilot AI review requested due to automatic review settings July 27, 2026 17:12
@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 27, 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: f811c985-ace7-425a-8f08-302bb0c7ad16

๐Ÿ“ฅ Commits

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

๐Ÿ“’ 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 sentinel-hmac-compare-digest-fix-1454767504914277086

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

This PR hardens the FastAPI API-key authentication middleware to avoid unhandled exceptions (500s) and potential DoS when hmac.compare_digest receives non-ASCII str header values, by comparing byte strings instead.

Changes:

  • Encode X-API-Key and configured keys to bytes before calling hmac.compare_digest.
  • Record 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 Updates API key comparison to use byte-encoded inputs for hmac.compare_digest.
.jules/sentinel.md Adds a Sentinel entry documenting the compare_digest non-ASCII exception/DoS class.

๐Ÿ’ก 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
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 contains the same Unicode-safe constant-time API-key comparison and extends the security boundary to registry-backed runtime credentials and bounded result retention. Closing this duplicate.

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

Copy link
Copy Markdown

Superseded by canonical PR #361, which contains the same Unicode-safe constant-time API-key comparison and extends the security boundary to registry-backed runtime credentials and bounded result retention. 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