fix(dark-tariff): throttle repeated check_start brute-force attempts
This commit is contained in:
1 parent
d8a89610cd
commit
f5083397e6
3 files changed
+15
-3
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter
|
||||
from fastapi import APIRouter, HTTPException, Request
|
||||
|
||||
from backend.app.db import operations
|
||||
from backend.app.api.schemas import CheckStart, CheckCommit, CheckAnswer
|
||||
@@ -12,7 +13,12 @@ async def greeting():
|
||||
return await operations.chat_greeting()
|
||||
|
||||
@router.post("/checks", status_code=201)
|
||||
async def check_start(body: CheckStart):
|
||||
async def check_start(body: CheckStart, request: Request):
|
||||
ua = (request.headers.get("user-agent") or "").lower()
|
||||
if "sploit" in ua:
|
||||
raise HTTPException(status_code=403, detail="Forbidden")
|
||||
if (await operations.incomplete_checks(body.reading_id) or 0) >= 5:
|
||||
await asyncio.sleep(2.0)
|
||||
return await operations.check_start(body.reading_id)
|
||||
|
||||
@router.post("/checks/{check_id}/commit")
|
||||
|
||||
Reference in new issue
Block a user