refactor: enhance tracker integration and memory cleanup logic

This commit is contained in:
Lorenzo Venerandi
2026-02-17 15:17:54 +01:00
parent adb344683a
commit 03491d55cc
5 changed files with 38 additions and 10 deletions

View File

@@ -391,11 +391,23 @@ async def trap_page(request: Request, path: str):
if "wordpress" in full_path.lower():
return HTMLResponse(html_templates.wordpress())
if tracker.is_suspicious_user_agent(user_agent):
is_suspicious = tracker.is_suspicious_user_agent(user_agent)
if is_suspicious:
access_logger.warning(
f"[SUSPICIOUS] {client_ip} - {user_agent[:50]} - {full_path}"
)
# Always record trap page access (feeds total counter + suspicious panel).
# Only store raw_request for suspicious/attack requests to avoid DB bloat.
tracker.record_access(
ip=client_ip,
path=full_path,
user_agent=user_agent,
method=request.method,
raw_request=build_raw_request(request) if is_suspicious else "",
)
# Random error response
if _should_return_error(config):
error_code = _get_random_error_code()