3 Commits

Author SHA1 Message Date
Renn F
53fa3627d9 fix(api): disable the ssrf category and qualify guard behaviour notes
Browsers send the page URL as Referer, and guard-core 4.4.0 flags
localhost and LAN addresses in it as ssrf, which returned 400 for every
UI request. Pass every detection category except ssrf, with tests for
local-address Referers (200) and an attack pattern in a Referer (400).

Say that system.json gains the disabled security_guard block on the next
load instead of claiming nothing changes, document the IPv4-mapped peer
caveat of guard-core 4.4.0 with the mapped-form workaround, fix the
session handoff line citation, and drop the launch-flag test that
duplicates tests/runtime/test_uvicorn_launch_flags.py.

Add tests for the mapped-form workaround and for the access log
recording a guard rejection through the real application stack.
2026-10-16 17:21:34 +02:00
Renn F
86b3633ca2 feat(api): exempt loopback from the guard rate limit by default
The bundled frontend proxy drops X-Forwarded-For and does not add the
browser address, so every browser reaches the backend as loopback and
would share one rate-limit bucket. Add `security_guard.exempt_ips`
(default 127.0.0.1 and ::1, DEEPTUTOR_GUARD_EXEMPT_IPS) passed to
SecurityConfig. It skips the rate limit only; the denylist, bans and the
attack-pattern scan still apply, and loopback requests that carry
X-Forwarded-For are still limited as the forwarded client.

Document that an allowlist must list loopback for the bundled frontend,
and qualify engine behaviour statements with the engine versions they
were verified on.
2026-10-16 16:38:15 +02:00
Renn F
dbd270cfdb feat(api): add opt-in fastapi-guard request screening
Add an off-by-default `security_guard` setting (system.json, with
DEEPTUTOR_GUARD_* deployment overrides) that mounts fastapi-guard's
pure-ASGI middleware in front of the routers: per-address rate limit,
IP allow/deny lists, ban list and an attack-pattern scan of path, query
and headers. Request bodies, WebSocket handshakes, Redis, CORS and
security headers are left alone.

The guard is added before the access-log and CORS middlewares so CORS
stays outermost and 429/403 responses carry CORS headers. When disabled
the package is never imported. When enabled without the package the
backend fails at startup with an install hint. fastapi-guard ships as
the optional `guard` extra (requirements/guard.txt, DEEPTUTOR_EXTRAS).
2026-10-16 16:24:52 +02:00