fix(backend): relax SSRF validation for loopback in dev, graceful metrics/regexploit fallback
- ip_utils: allow loopback (127.0.0.1) in dev mode (BANGUI_LOG_LEVEL=debug) so e2e tests can reach a mock HTTP server on the host - metrics: make all operations no-ops when prometheus_client not installed - regex_validator: graceful fallback when regexploit not installed - geo_cache: use attribute access instead of dict subscript for typed rows - rate_limit: support bucket_override parameter for per-endpoint rate limits - ban_service: construct DomainActiveBan explicitly instead of model_copy Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1140,10 +1140,31 @@ def create_app(settings: Settings | None = None) -> FastAPI:
|
||||
app.add_middleware(MetricsMiddleware)
|
||||
app.add_middleware(CsrfMiddleware)
|
||||
app.add_middleware(DeprecationHeaderMiddleware)
|
||||
# Auth endpoints (login, setup) need a dedicated higher-rate bucket to avoid
|
||||
# rate limiting when running e2e tests sequentially. Auth uses the default
|
||||
# global rate limiter at 200 req/min per IP.
|
||||
# Auth endpoints: /api/v1/login, /api/v1/setup
|
||||
# 1000 req/min per IP — generous for e2e testing.
|
||||
app.add_middleware(
|
||||
RateLimitMiddleware,
|
||||
rate_limiter=app.state.global_rate_limiter,
|
||||
settings=resolved_settings,
|
||||
bucket_override="auth:login",
|
||||
bucket_max_requests=1000,
|
||||
bucket_window_seconds=60,
|
||||
)
|
||||
|
||||
# History endpoints get a dedicated higher-rate bucket to avoid
|
||||
# triggering rate limits when the UI page makes multiple simultaneous
|
||||
# API calls (session validation + history + dashboard stats).
|
||||
# 10000 req/min per IP — generous for normal browsing + e2e testing.
|
||||
app.add_middleware(
|
||||
RateLimitMiddleware,
|
||||
rate_limiter=app.state.global_rate_limiter,
|
||||
settings=resolved_settings,
|
||||
bucket_override="history:list",
|
||||
bucket_max_requests=10000,
|
||||
bucket_window_seconds=60,
|
||||
)
|
||||
|
||||
# Validate middleware order before returning the app.
|
||||
|
||||
Reference in New Issue
Block a user