Skip to content

fix(auth): handle non-ASCII API keys without 500 responses - #326

Closed
seonghobae wants to merge 3 commits into
mainfrom
sentinel/api-key-dos-fix-8779621121455543638
Closed

fix(auth): handle non-ASCII API keys without 500 responses#326
seonghobae wants to merge 3 commits into
mainfrom
sentinel/api-key-dos-fix-8779621121455543638

Conversation

@seonghobae

@seonghobae seonghobae commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Classification

This is an API-key input-validation and error-handling defect. Python hmac.compare_digest accepts ASCII-only strings but raises TypeError for non-ASCII string values; an unauthenticated request could therefore receive a request-scoped 500 response. The prior CRITICAL/service-wide DoS claim was not demonstrated and is intentionally removed.

Changes

  • Compare configured and supplied API keys as UTF-8 bytes so non-ASCII input cannot escape authentication as an unhandled exception.
  • Preserve constant-time comparison semantics for ASCII and non-ASCII keys.
  • Add regression coverage for rejected non-ASCII input, accepted matching non-ASCII configured keys, and the downstream-handler call contract.
  • Correct the Sentinel learning note to distinguish supported ASCII-only string comparisons from failing non-ASCII string comparisons.
  • Refresh the direct setuptools runtime lock from 82.0.1 to patched 83.0.0 for the repository's open Medium Dependabot alert, GHSA-h35f-9h28-mq5c / CVE-2026-59890.

Verification

  • pytest -q tests/test_saas_web.py: 71 passed
  • pytest -q: 464 passed, 4 subtests passed
  • Ruff, compileall, and interrogate 100% passed
  • manylinux2014 x86_64 / CPython 3.10 pip install --dry-run --require-hashes resolved the refreshed lock, including setuptools==83.0.0
  • Current-head GitHub CI, fuzz, SAST, dependency, Trivy, OSV, Strix, and central review checks are being re-evaluated for commit c56bb97

PR originally created by Jules for task 8779621121455543638 started by @seonghobae.

@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 31, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

API 키 비교 전에 설정값과 요청 헤더를 UTF-8 바이트로 변환합니다. 비ASCII API 키 요청에 대한 401 회귀 테스트와 hmac.compare_digest 오류 예방 문서를 추가했습니다.

Changes

API 키 인증

Layer / File(s) Summary
UTF-8 비교 및 회귀 검증
saas_web.py, tests/test_saas_web.py, .jules/sentinel.md
API 키를 UTF-8 바이트로 변환한 뒤 hmac.compare_digest로 비교합니다. 비ASCII 키 요청은 표준 401 응답을 반환하고, 유효한 키 요청은 다운스트림 응답을 반환합니다. 관련 TypeError와 예방책을 보안 문서에 기록했습니다.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 제목은 비ASCII API 키 처리와 500 응답 방지라는 변경의 핵심 내용을 정확하고 간결하게 설명합니다.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sentinel/api-key-dos-fix-8779621121455543638

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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/test_saas_web.py (1)

694-703: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Non-ASCII 설정 키도 검증하세요.

현재 테스트는 요청 키만 안녕으로 설정하고 CODEC_CARVER_API_KEYS는 ASCII 값으로 설정합니다. 따라서 key.encode("utf-8") 경로와 Non-ASCII 설정 키의 정상 인증을 검증하지 않습니다. 설정 키와 요청 헤더가 모두 안녕인 성공 케이스를 추가하고 call_next 호출도 확인하세요.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_saas_web.py` around lines 694 - 703, Update the API-key tests
around require_api_key to add a successful case where both CODEC_CARVER_API_KEYS
and the request header use the non-ASCII key “안녕”. Assert a successful response
and verify mock_call_next is called, while preserving the existing invalid-key
assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.jules/sentinel.md:
- Line 65: Update the 학습 note describing hmac.compare_digest to state that
ASCII-only str comparisons are supported, while comparisons involving non-ASCII
str values raise TypeError; do not claim that Unicode string comparisons are
categorically unsupported.

In `@tests/test_saas_web.py`:
- Line 694: MockRequest의 공유 mutable class attribute인 headers를 제거하고 __init__에서
인스턴스별 self.headers로 생성하세요. 기존 헤더 값은 유지하되 각 테스트 인스턴스가 독립적인 헤더 상태를 갖도록 수정해 Ruff
RUF012 경고를 해결하세요.

---

Nitpick comments:
In `@tests/test_saas_web.py`:
- Around line 694-703: Update the API-key tests around require_api_key to add a
successful case where both CODEC_CARVER_API_KEYS and the request header use the
non-ASCII key “안녕”. Assert a successful response and verify mock_call_next is
called, while preserving the existing invalid-key assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a6437a3c-1d61-453f-b2a3-63f213574415

📥 Commits

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

📒 Files selected for processing (3)
  • .jules/sentinel.md
  • saas_web.py
  • tests/test_saas_web.py

Comment thread .jules/sentinel.md Outdated
Comment thread tests/test_saas_web.py Outdated
@seonghobae seonghobae changed the title 🛡️ Sentinel: [CRITICAL] hmac.compare_digest에서 처리되지 않은 예외로 인한 API Key DoS 취약점 수정 fix(auth): handle non-ASCII API keys without 500 responses Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by canonical PR #361. #361 retains the accurately scoped non-ASCII authentication fix while also implementing the repository-required credential-registry boundary, owned result storage, TTL cleanup, broader tests, and doctoring. Closing this narrower duplicate.

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

Copy link
Copy Markdown

Superseded by canonical PR #361. #361 retains the accurately scoped non-ASCII authentication fix while also implementing the repository-required credential-registry boundary, owned result storage, TTL cleanup, broader tests, and doctoring. Closing this narrower 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.

1 participant