T09 · Insecure Skill Coding Practices
- Location
diffgate/app.py:20- Finding
Unauthenticated CPU and Memory Denial of Service Through Expensive Text Comparison
- Content
View full analysis
DiffResponse: """Compare two texts and return diff with similarity score.""" lines_a = request.text_a.splitlines(keepends=True) lines_b = request.text_b.splitlines(keepends=True) # Compute similarity using SequenceMatcher matcher = difflib.SequenceMatcher(None, lines_a, lines_b) ratio = matcher.ratio() ``` ### Technical Analysis The `/v1/diff` endpoint accepts two strings of up to 500,000 characters each without authentication, rate limiting, request quotas, or execution time limits. It then creates multiple in-memory line arrays and performs `difflib.SequenceMatcher` processing synchronously. Although the route is declared with `async def`, the comparison is CPU-bound and contains no asynchronous yield while it runs. Consequently, each expensive comparison can block the application worker's event loop. Carefully structured inputs with many repetitive or reordered lines can increase comparison cost. The subsequent unified-diff generation also consumes additional CPU and memory and may produce a large response. The input length bounds reduce unlimited growth but remain large enough for repeated or concurrent requests to exhaust application resources. ### Attack Path 1. An attacker obtains network access to the Uvicorn service. 2. The attacker repeatedly sends `POST /v1/diff` requests containing two near-maximum-length texts. 3. The texts are structur ...[truncated 747 chars]- Remediation
View remediation
