ux: CHANGE fail if invalid UTF8 to prevent tampered data #25
This commit is contained in:
parent
0d6e3244b1
commit
521465c2d9
1 changed files with 9 additions and 1 deletions
10
main.py
10
main.py
|
|
@ -265,7 +265,15 @@ async def upload_text(request: Request, authorized: bool = Depends(validate_uplo
|
|||
raise HTTPException(status_code=413, detail="Payload too large")
|
||||
chunks.append(chunk)
|
||||
body = b"".join(chunks)
|
||||
content = body.decode('utf-8', errors='ignore')
|
||||
try:
|
||||
content = body.decode('utf-8', errors='strict')
|
||||
except UnicodeDecodeError:
|
||||
log("WARNING", "upload_failed",
|
||||
client_ip=client_ip,
|
||||
user_agent=user_agent,
|
||||
reason="invalid_utf8",
|
||||
size_bytes=total)
|
||||
raise HTTPException(status_code=400, detail="Invalid UTF-8 content")
|
||||
|
||||
if not validate_content(content):
|
||||
log("WARNING", "upload_failed",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue