diff --git a/.jules/sentinel.md b/.jules/sentinel.md index 9c9d083b..de55622e 100644 --- a/.jules/sentinel.md +++ b/.jules/sentinel.md @@ -1,3 +1,9 @@ +## 2024-05-24 - [API 키 비교 500 에러 처리] +**Vulnerability:** HMAC 문자열 비교에서 non-ASCII 문자가 사용될 경우 500 서버 에러(DoS 가능성)가 발생함. +**Learning:** 파이썬 hmac.compare_digest에 non-ASCII 문자열을 직접 전달하면 TypeError가 발생함. +**Prevention:** API 키를 검사할 때 항상 문자열을 UTF-8 바이트로 인코딩한 후 비교해야 함. + + ## 2026-07-25 - [Cross-platform upload basename normalization] **Behavior:** Upload metadata now interprets both forward slashes and backslashes as path separators before extracting a basename. **Learning:** On POSIX systems, `pathlib.Path(filename).name` retains backslashes because they are ordinary characters there. That caused inconsistent manifest and converter filenames for Windows-style client paths. The upload itself is still written inside a trusted temporary workspace, and batch archive entry names are generated outputs; this change does not establish a filesystem traversal or archive-entry escape. diff --git a/CHANGELOG.md b/CHANGELOG.md index 9313538b..6f9699c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,3 +12,4 @@ ### Fixed - 단일·일괄 대상 크기 입력을 비웠을 때 이전 custom validity와 `aria-invalid` 상태를 즉시 초기화해 현재 필수 입력 상태를 정확히 전달합니다. - 업로드 파일명의 경로 구분자를 정규화하여 POSIX에서도 Windows 형식의 클라이언트 경로가 일관된 basename으로 기록되도록 수정했습니다. +- 보안(Security): API 키 검사 시 non-ASCII 문자로 인한 500 내부 서버 오류(DoS 위험) 수정 diff --git a/saas_web.py b/saas_web.py index 63265e94..071b1419 100644 --- a/saas_web.py +++ b/saas_web.py @@ -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,