{"record":{"id":"ee8c9d0c008639ba","repo":"BerriAI/litellm","slug":"rejected-polling-url-host-is-not-within-the-bfl-a","errorCode":null,"errorMessage":"Rejected polling URL: host is not within the bfl.ai domain","messagePattern":"Rejected polling URL: host is not within the bfl\\.ai domain","errorType":"http","errorClass":"BlackForestLabsError","httpStatus":502,"severity":"error","filePath":"litellm/llms/black_forest_labs/common_utils.py","lineNumber":48,"sourceCode":"    from the submission host ``api.bfl.ai``. A strict same-origin check would\n    reject these legitimate URLs. Instead we verify the host is ``bfl.ai`` or\n    any subdomain of it, which keeps the SSRF guarantee (credentials only go\n    to BFL-controlled infrastructure) without false-positives on regional hosts.\n\n    Raises:\n        BlackForestLabsError: If the polling URL scheme or host is not trusted.\n    \"\"\"\n    parsed: Final = urlparse(polling_url)\n    host: Final = (parsed.hostname or \"\").lower()\n\n    if parsed.scheme != \"https\":\n        raise BlackForestLabsError(\n            status_code=502,\n            message=\"Rejected polling URL: scheme must be https\",\n        )\n\n    if host != _BFL_REGISTERED_DOMAIN and not host.endswith(\".\" + _BFL_REGISTERED_DOMAIN):\n        raise BlackForestLabsError(\n            status_code=502,\n            message=\"Rejected polling URL: host is not within the bfl.ai domain\",\n        )\n\n\n# Polling configuration\nDEFAULT_POLLING_INTERVAL: Final = 1.5  # seconds\nDEFAULT_MAX_POLLING_TIME: Final = 300  # 5 minutes\n\n# Model to endpoint mapping for image edit\nIMAGE_EDIT_MODELS: Final[dict[str, str]] = {\n    \"flux-kontext-pro\": \"/v1/flux-kontext-pro\",\n    \"flux-kontext-max\": \"/v1/flux-kontext-max\",\n    \"flux-pro-1.0-fill\": \"/v1/flux-pro-1.0-fill\",\n    \"flux-pro-1.0-expand\": \"/v1/flux-pro-1.0-expand\",\n}\n\n# Model to endpoint mapping for image generation","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/black_forest_labs/common_utils.py#L30-L66","documentation":"The second half of the BFL SSRF guard: after the https scheme check, the polling URL host must be exactly bfl.ai or a subdomain of it (host == 'bfl.ai' or host.endswith('.bfl.ai')). Anything else (localhost, an unrelated domain, or a suffix trick like 'notbfl.ai') raises BlackForestLabsError(502), keeping BFL credentials on BFL-controlled infrastructure only.","triggerScenarios":"A BFL API response whose polling_url points at a host outside bfl.ai: local mock servers (http://localhost), custom api_base proxies echoing their own host, or DNS/domain tricks from a tampered response.","commonSituations":"Local development against a stubbed BFL API, gateways that rewrite polling URLs to their own domain, or upstream responses that are not genuinely from BFL.","solutions":["If proxying/mocking BFL, ensure the polling_url your server returns is within the bfl.ai domain, or test against the real API","Remove the custom api_base so responses come from api.bfl.ai unchanged","Treat a rejection from a production call as evidence the upstream response was tampered with; verify the endpoint and TLS path"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from litellm.llms.black_forest_labs.common_utils import BlackForestLabsError\n\ntry:\n    img = litellm.image(model=\"bfl/flux-kontext-pro\", ...)\nexcept BlackForestLabsError as e:\n    if e.status_code == 502 and \"bfl.ai domain\" in str(e):\n        # polling_url host was outside bfl.ai; treat as misrouted or tampered upstream\n        log.error(\"BFL polling host rejected by SSRF guard; verify api_base and upstream\")\n    raise","preventionTips":["Do not point BFL traffic at gateways that rewrite polling URLs to their own hosts","Ensure test doubles return polling URLs under *.bfl.ai to pass the host guard","Treat any production occurrence as a security signal: verify TLS, DNS, and the api_base chain"],"tags":["bfl","flux","image-generation","ssrf","url-validation"],"backgroundTag":"ssrf-url-rejected","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}