Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@
**Vulnerability:** Path traversal in `media_shrinker.py` via unresolved `..` segments or symlink escapes before deriving conversion output paths.
**Learning:** `Path.relative_to()` is only a lexical containment check unless both the source and root have first been resolved into canonical absolute paths. Relative paths and symlinks can otherwise bypass root-boundary assumptions.
**Prevention:** Resolve both source and root once, reject sources outside the resolved root with a sanitized `MediaShrinkerError`, and derive `rel_source` from the resolved paths before planning outputs.
## 2026-07-28 - [Sentinel: ๋น„ ASCII API ํ‚ค๋กœ ์ธํ•œ 500 ๋‚ด๋ถ€ ์„œ๋ฒ„ ์˜ค๋ฅ˜(DoS) ์ทจ์•ฝ์  ์ˆ˜์ •]
**์ทจ์•ฝ์ :** `hmac.compare_digest` ํ•จ์ˆ˜๊ฐ€ ๋น„ ASCII ๋ฌธ์ž๊ฐ€ ํฌํ•จ๋œ ๋ฌธ์ž์—ด์„ ๋น„๊ตํ•  ๋•Œ `TypeError`๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๋Š” ๋ฌธ์ œ๋กœ ์ธํ•ด, ์•…์˜์ ์ธ `X-API-Key` ํ—ค๋” ์ „์†ก ์‹œ 500 ๋‚ด๋ถ€ ์„œ๋ฒ„ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜์—ฌ DoS ๊ณต๊ฒฉ(CWE-400)์— ์•…์šฉ๋  ์ˆ˜ ์žˆ์Œ.
**ํ•™์Šต:** ํŒŒ์ด์ฌ์˜ `hmac.compare_digest`๋Š” ๋น„ ASCII ๋ฌธ์ž์—ด ๋น„๊ต๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. HTTP ํ—ค๋”์™€ ๊ฐ™์ด ํ†ต์ œ๋˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž ์ž…๋ ฅ์— ๋Œ€ํ•ด ์ธ์ฝ”๋”ฉ ์ฒ˜๋ฆฌ ์—†์ด ๋ฌธ์ž์—ด ์ƒํƒœ๋กœ ์ง์ ‘ ๋น„๊ต๋ฅผ ์ˆ˜ํ–‰ํ•˜๋ฉด ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
**์˜ˆ๋ฐฉ:** `hmac.compare_digest`๋ฅผ ํ˜ธ์ถœํ•˜๊ธฐ ์ „์— ํ•ญ์ƒ ๋‘ ์ธ์ž๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ๋ฐ”์ดํŠธ ๊ฐ์ฒด๋กœ ์ธ์ฝ”๋”ฉ(`.encode('utf-8')`)ํ•˜์—ฌ ์˜ˆ์™ธ ๋ฐœ์ƒ์„ ๋ฐฉ์ง€ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
2 changes: 1 addition & 1 deletion saas_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async def require_api_key(request: Request, call_next):
if configured_keys and not (request.method == "GET" and request.url.path == "/"):
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
):
return JSONResponse(
status_code=401,
Expand Down
18 changes: 18 additions & 0 deletions tests/test_saas_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,24 @@ def test_video_content_type_accepted_by_validator(self):
)
)

def test_api_key_handles_non_ascii_gracefully(self):
from starlette.requests import Request
import asyncio
async def mock_call_next(request: Request):
from starlette.responses import PlainTextResponse
return PlainTextResponse("OK")

with patch("saas_web.get_configured_api_keys", return_value=["secret1"]):
scope = {
"type": "http",
"method": "GET",
"path": "/jobs/123",
"headers": [(b"x-api-key", "malicious\xff".encode("latin-1"))],
}
request = Request(scope)
response = asyncio.run(saas_web.require_api_key(request, mock_call_next))
self.assertEqual(response.status_code, 401)


if __name__ == '__main__':
unittest.main()
Loading