Skip to content
Closed
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 @@ -65,3 +65,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-08-04 - hmac.compare_digest λΉ„-ASCII λ¬Έμžμ—΄ 처리 였λ₯˜ μˆ˜μ •
**취약점:** FastAPI λ―Έλ“€μ›¨μ–΄μ—μ„œ `hmac.compare_digest` μ‚¬μš© μ‹œ, μ•…μ˜μ μΈ μ‚¬μš©μžκ°€ API ν‚€ 헀더에 λΉ„-ASCII 문자λ₯Ό ν¬ν•¨ν•˜λ©΄ `TypeError`κ°€ λ°œμƒν•˜μ—¬ 500 μ„œλ²„ μ—λŸ¬(DoS)κ°€ 유발될 수 있음.
**ν•™μŠ΅:** 파이썬의 `hmac.compare_digest()`λŠ” λΉ„-ASCII λ¬Έμžκ°€ ν¬ν•¨λœ λ¬Έμžμ—΄μ„ 직접 비ꡐ할 수 μ—†μŒ.
**예방:** 항상 두 인자λ₯Ό λͺ…μ‹œμ μœΌλ‘œ λ°”μ΄νŠΈ(`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
22 changes: 22 additions & 0 deletions tests/test_saas_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,28 @@ def test_shrink_media_rejects_nonpositive_target_bytes(self):
{"error": "Invalid target_bytes value. Must be greater than 0."},
)

def test_non_ascii_key_rejected_safely(self):
import asyncio
import starlette.requests
from starlette.responses import JSONResponse

async def call_next(request):
return JSONResponse({"status": "ok"})

scope = {
"type": "http",
"method": "POST",
"path": "/shrink",
"headers": [(b"x-api-key", "invalΓ­d".encode("utf-8"))],
}
request = starlette.requests.Request(scope)

with patch.dict(os.environ, {"CODEC_CARVER_API_KEYS": "secret-key"}):
response = asyncio.run(saas_web.require_api_key(request, call_next))

self.assertEqual(response.status_code, 401)
self.assertEqual(json.loads(response.body), {"error": "Invalid or missing API key"})

def test_shrink_media_rejects_missing_filename(self):
response = saas_web.shrink_media(
BackgroundTasks(),
Expand Down
Loading