security: v1.7.7 hardening release
- Add WEBHOOK_CLIENT_SECRET validation for Graph webhooks - Add Redis-backed rate limiting (fetch/ask/write/default tiers) - Validate LLM_BASE_URL to prevent SSRF (HTTPS only, block private IPs) - Enforce non-wildcard CORS when AUTH_ENABLED=true - Add Content-Security-Policy headers - Fix audit middleware to use verified JWT claims via contextvars - Cap bulk_tags updates to 10,000 documents - Return generic error messages to clients (no internal detail leakage) - Strict AlertCondition Pydantic model for alert rules - Security warning on MCP stdio server startup - Remove MongoDB/Redis host ports from docker-compose - Remove mongo_query from /ask API response
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import contextvars
|
||||
import time
|
||||
|
||||
import requests
|
||||
@@ -15,6 +16,9 @@ from fastapi import Header, HTTPException
|
||||
from jwt import ExpiredSignatureError, InvalidTokenError, decode
|
||||
from jwt.algorithms import RSAAlgorithm
|
||||
|
||||
# Thread-/task-local storage for verified auth claims (used by audit middleware)
|
||||
_auth_context: contextvars.ContextVar[dict | None] = contextvars.ContextVar("auth_context", default=None)
|
||||
|
||||
JWKS_CACHE = {"exp": 0, "keys": []}
|
||||
logger = structlog.get_logger("aoc.auth")
|
||||
|
||||
@@ -94,7 +98,9 @@ def user_can_access_privacy_services(claims: dict) -> bool:
|
||||
|
||||
def require_auth(authorization: str | None = Header(None)):
|
||||
if not AUTH_ENABLED:
|
||||
return {"sub": "anonymous"}
|
||||
user = {"sub": "anonymous"}
|
||||
_auth_context.set(user)
|
||||
return user
|
||||
|
||||
if not authorization or not authorization.lower().startswith("bearer "):
|
||||
raise HTTPException(status_code=401, detail="Missing bearer token")
|
||||
@@ -106,4 +112,5 @@ def require_auth(authorization: str | None = Header(None)):
|
||||
if not _allowed(claims, AUTH_ALLOWED_ROLES, AUTH_ALLOWED_GROUPS):
|
||||
raise HTTPException(status_code=403, detail="Forbidden")
|
||||
|
||||
_auth_context.set(claims)
|
||||
return claims
|
||||
|
||||
Reference in New Issue
Block a user