๐ก๏ธ Sentinel: [HIGH] Fix DoS via unhandled exception in hmac.compare_digest - #439
๐ก๏ธ Sentinel: [HIGH] Fix DoS via unhandled exception in hmac.compare_digest#439seonghobae wants to merge 2 commits into
Conversation
|
๐ 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Pull request overview
This PR hardens the optional bearer-auth gate by preventing hmac.compare_digest from raising TypeError on non-ASCII Authorization header values, eliminating a potential DoS via unhandled 500s in the auth path.
Changes:
- Encode both the provided and expected bearer strings to UTF-8 bytes before calling
hmac.compare_digest. - Add a regression test that sends a non-ASCII Authorization header and asserts a clean
401 Unauthorized. - Document the security fix in the Sentinel log and the changelog (though the changelog entry is currently placed in the wrong section).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/newsdom_api/main.py |
Encodes auth strings to bytes before constant-time comparison to avoid non-ASCII TypeError. |
tests/test_auth.py |
Adds coverage to ensure non-ASCII Authorization headers donโt trigger a 500. |
CHANGELOG.md |
Adds a โFixedโ entry for the DoS issue (currently appended after reference links). |
.jules/sentinel.md |
Records the vulnerability, learning, and prevention guidance for this class of issue. |
๐ก Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| ### Fixed | ||
| - `hmac.compare_digest`์ ๋น-ASCII ๋ฌธ์๊ฐ ํฌํจ๋ `Authorization` ํค๋๊ฐ ์ ๋ ฅ๋ ๋ ๋ฐ์ํ๋ 500 ์๋ฌ ๋ฐ ์ ์ฌ์ DoS ์ทจ์ฝ์ ์ ์์ ํ์ต๋๋ค. |
|
Warning Review limit reached
Next review available in: 13 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: โ Files ignored due to path filters (1)
๐ Files selected for processing (5)
โจ Finishing Touches๐งช Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
CHANGELOG.md:105
- This changelog entry is appended after the link reference definitions (
[Unreleased]: ...,[0.2.0]: ...), so itโs no longer part of any release/Unreleased section and breaks the expected Keep-a-Changelog structure. Please move this bullet under the appropriate section (likely## [Unreleased]โ### Fixedor### Security) and keep the link references as the final lines of the file.
### Fixed
- `hmac.compare_digest`์ ๋น-ASCII ๋ฌธ์๊ฐ ํฌํจ๋ `Authorization` ํค๋๊ฐ ์
๋ ฅ๋ ๋ ๋ฐ์ํ๋ 500 ์๋ฌ ๋ฐ ์ ์ฌ์ DoS ์ทจ์ฝ์ ์ ์์ ํ์ต๋๋ค.
| def test_authorization_non_ascii_header(monkeypatch: pytest.MonkeyPatch) -> None: | ||
| """Ensure non-ASCII characters in Authorization header do not cause a 500 error (DoS).""" | ||
| monkeypatch.setenv("NEWSDOM_API_TOKEN", "secret-token") | ||
| # Sending non-ASCII requires explicitly encoding to bytes in TestClient headers | ||
| # otherwise httpx raises a UnicodeEncodeError internally during test setup. | ||
| header_val = "Bearer ์๋ ํ์ธ์".encode("utf-8") | ||
|
|
||
| client = TestClient(app) | ||
| response = client.post("/parse", files={"file": ("test.pdf", b"%PDF-")}, headers={"Authorization": header_val}) | ||
|
|
||
| assert response.status_code == 401 | ||
| assert response.json() == {"detail": "Unauthorized"} |
| DS-0002 | ||
| # Revisit by 2026-10-01 | ||
| # CVE-2026-61632 in pymdown-extensions is unfixable upstream right now | ||
| CVE-2026-61632 |
๐จ Severity: HIGH
๐ก Vulnerability:
hmac.compare_digest์ ASCII๊ฐ ์๋ ๋ฌธ์(์: ํ๊ตญ์ด ๋ฑ)๊ฐ ํฌํจ๋Authorizationํค๋๊ฐ ์ ๋ ฅ๋๋ฉดTypeError๊ฐ ๋ฐ์ํ์ฌ, ์์ธ ์ฒ๋ฆฌ๋์ง ์์ 500 Internal Server Error๋ฅผ ์ ๋ฐํฉ๋๋ค. ์ด๋ ์ธ์ฆ ํ๋ก์ธ์ค์ ๋ํ DoS ๊ณต๊ฒฉ(์๋น์ค ๊ฑฐ๋ถ)์ ๊ฐ๋ฅํ๊ฒ ํฉ๋๋ค.๐ฏ Impact: ์ ์์ ์ธ ์ฌ์ฉ์๊ฐ ํน์๋ฌธ์๋ ๋น์์ด ๋ฌธ์๊ฐ ํฌํจ๋ ํ ํฐ์ ์ง์์ ์ผ๋ก ๋ณด๋ด์ด ์๋ฒ์ ๋ฆฌ์์ค๋ฅผ ์๋ชจํ๊ฑฐ๋ ์๋ฌ๋ฅผ ์ ๋ฐํ์ฌ ์๋น์ค๋ฅผ ์ค๋จ์ํฌ ์ ์์ต๋๋ค.
๐ง Fix: ์ ๋ ฅ๋ฐ์ ๋ฌธ์์ด(์ ๊ณต๋ ํ ํฐ๊ณผ ์์ ํ ํฐ)์ ๋น๊ตํ๊ธฐ ์ ์ ๋ช ์์ ์ผ๋ก
utf-8๋ฐ์ดํธ๋ก ์ธ์ฝ๋ฉ(encode("utf-8"))ํ๋๋ก ์์ ํ์์ต๋๋ค.โ Verification: ํ ์คํธ ์ค์ํธ(
uv run pytest)๊ฐ ์ฑ๊ณต์ ์ผ๋ก ํต๊ณผํ๋ฉฐ, ๋น-ASCII ํค๋ ์์ฒญ ์ 500 ์๋ฌ ๋์ ์ฌ๋ฐ๋ฅด๊ฒ 401(๋๋ ๊ธฐํ ์ ์ ํ ์๋ต)์ด ๋ฐํ๋ฉ๋๋ค.What:
hmac.compare_digestํธ์ถ ์ ์ ๋น๊ตํ ๋ ๋ฌธ์์ด(provided๋ฐexpected)์ ๋ชจ๋utf-8๋ฐ์ดํธ ๋ฐฐ์ด๋ก ๋ณํํ๋ ๊ณผ์ ์ ์ถ๊ฐํ์ต๋๋ค.Why:
Python์
hmac.compare_digest๋ ๋น-ASCII ๋ฌธ์๊ฐ ํฌํจ๋ ๋ฌธ์์ด ์ฒ๋ฆฌ๋ฅผ ์ง์ํ์ง ์์TypeError๊ฐ ๋ฐ์ํฉ๋๋ค. ์ธ๋ถ ์ ๋ ฅ์ ํญ์ ์ ๋ขฐํ ์ ์์ผ๋ฏ๋ก, ์ด๋ฅผ ๋ฐ์ดํธ๋ก ์ธ์ฝ๋ฉํ์ฌ ์์คํ ์์ ์ฑ์ ํ๋ณดํด์ผ ํฉ๋๋ค.Before/After:
Accessibility/DX:
๋ณด์ ์์ ์ฑ์ด ํฅ์๋์ด, ์ธ์ฆ ๊ด๋ จ ์๋ฌ๋ก ์ธํ ์๋น์ค ์ค๋จ ์์ด ์์ ์ ์ธ ์ด์ ํ๊ฒฝ์ ์ ๊ณตํฉ๋๋ค.
PR created automatically by Jules for task 17379201691801903708 started by @seonghobae