{"record":{"id":"92236c52afb18590","repo":"BerriAI/litellm","slug":"feature-name-only-accepts-identity-headers-from","errorCode":null,"errorMessage":"{feature_name} only accepts identity headers from configured trusted proxy ranges. Direct client IP {direct_client_ip!r} is not trusted.","messagePattern":"(.+?) only accepts identity headers from configured trusted proxy ranges\\. Direct client IP (.+?) is not trusted\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/proxy/auth/trusted_proxy_utils.py","lineNumber":80,"sourceCode":"    \"\"\"\n    if general_settings is None:\n        general_settings = _get_proxy_general_settings()\n\n    trusted_networks: Final = parse_trusted_proxy_ranges(general_settings.get(setting_name), setting_name=setting_name)\n    if not trusted_networks:\n        raise ValueError(\n            f\"{feature_name} requires general_settings.{setting_name} before \"\n            \"trusting identity headers from an upstream proxy.\"\n        )\n\n    direct_client_ip: Final = _get_direct_client_ip(request)\n    if not ip_in_networks(direct_client_ip, trusted_networks):\n        verbose_proxy_logger.warning(\n            \"%s rejected identity headers from untrusted direct client IP %r\",\n            feature_name,\n            direct_client_ip,\n        )\n        raise ValueError(\n            f\"{feature_name} only accepts identity headers from configured \"\n            f\"trusted proxy ranges. Direct client IP {direct_client_ip!r} \"\n            \"is not trusted.\"\n        )\n","sourceCodeStart":62,"sourceCodeEnd":85,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/auth/trusted_proxy_utils.py#L62-L85","documentation":"Even with trusted_proxy_ranges configured, LiteLLM validates the direct TCP peer of the connection (request.client.host) - not X-Forwarded-For - because the direct peer is the actor supplying the identity headers. If the socket IP falls outside every configured CIDR, the identity headers are rejected with this ValueError, after a warning log naming the rejected IP ('rejected identity headers from untrusted direct client IP ...').","triggerScenarios":"The reverse proxy's egress IP is not in trusted_proxy_ranges (new LB node, autoscaled ingress pod outside the configured CIDR, Docker/K8s NAT address); or a client connects directly to LiteLLM while sending X-Forwarded-*/OAuth2 proxy headers.","commonSituations":"Kubernetes ingress pods spawn outside the configured pod CIDR; cloud LBs scale into new subnets; someone bypasses the proxy 'just for testing'; dual-stack setups where the connection arrives over IPv6 but only v4 ranges are configured.","solutions":["Read the rejected IP from the proxy's warning log line ('rejected identity headers from untrusted direct client IP')","Add that IP or its CIDR to general_settings.trusted_proxy_ranges and restart","Ensure clients can only reach LiteLLM through the trusted proxy (network policy / private binding)","For IPv6 peers, configure the matching IPv6 range"],"exampleFix":"# before\ngeneral_settings:\n  trusted_proxy_ranges: ['10.0.0.0/8']   # warning: rejected identity headers from untrusted direct client IP '172.18.0.5'\n\n# after\ngeneral_settings:\n  trusted_proxy_ranges: ['10.0.0.0/8', '172.16.0.0/12']","handlingStrategy":"validation","validationCode":"# Python: preflight - the peer your proxy server actually sees must be inside the configured ranges\nimport ipaddress\nTRUSTED = [ipaddress.ip_network(c) for c in config['general_settings']['trusted_proxy_ranges']]\nobserved = request.client.host  # e.g. from a tiny echo middleware or access log\nif not any(ipaddress.ip_address(observed) in n for n in TRUSTED):\n    raise ValueError(f'direct peer {observed} not in trusted_proxy_ranges - fix config before enabling header identity')","typeGuard":null,"tryCatchPattern":"try:\n    await handle_oauth2_proxy_request(request)\nexcept ValueError as e:\n    if 'is not trusted' in str(e):\n        # warning log already names the rejected direct client IP - add it (or its CIDR) to trusted_proxy_ranges\n        log.warning('trusted-proxy mismatch: %s', e)\n        return JSONResponse({'error': 'untrusted proxy source'}, status_code=400)\n    raise","preventionTips":["Configure the full LB/ingress subnet (not single IPs) so autoscaling stays inside the allowlist","Include IPv6 ranges if the proxy can connect over IPv6","Block direct client access to LiteLLM (private binding / network policy) so only the proxy can connect"],"tags":["network","trusted-proxy","ip-allowlist","x-forwarded-for","security"],"backgroundTag":"ip-not-in-allowlist","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}