T05 · Unauthorized Access and Privilege Escalation
- Location
zim/api.py:152- Finding
API and Administrative Authentication Fail Open When Keys Are Unset
- Content
View full analysis
Any: path = request.url.path # Skip auth for public paths if path in _PUBLIC_PATHS or any(path.startswith(p) for p in _PUBLIC_PREFIXES): return await call_next(request) is_admin_path = path.startswith("/v1/admin/") or path == "/v1/admin" if is_admin_path: required_key = os.environ.get("ZIM_ADMIN_KEY") or os.environ.get("ZIM_API_KEY", "") else: required_key = os.environ.get("ZIM_API_KEY", "") if required_key: auth_header = request.headers.get("Authorization", "") if not auth_header.startswith("Bearer "): return JSONResponse( {"detail": "Missing Authorization header (Bearer token required)"}, status_code=401, ) if auth_header[7:] != required_key: return JSONResponse({"detail": "Invalid API key"}, status_code=401) return await call_next(request) ``` Sensitive request data is returned without field-level filtering: ```python @app.get("/v1/requests/{request_id}") def get_request(request_id: str) -> dict[str, Any]: """Get the full state of a travel request.""" req = _get_request_or_404(request_id) return req.model_dump(mode="json") @app.get("/v1/requests") def list_requests( ...[truncated 2891 chars]- Remediation
View remediation
