{"record":{"id":"454dc8e4155c6bd4","repo":"odysseus-dev/odysseus","slug":"upstream-returned-an-unsafe-image-url-reason","errorCode":null,"errorMessage":"Upstream returned an unsafe image URL: {reason}","messagePattern":"Upstream returned an unsafe image URL: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":502,"severity":"error","filePath":"routes/gallery/gallery_routes.py","lineNumber":340,"sourceCode":"async def _fetch_result_image_b64(url: str) -> Optional[str]:\n    \"\"\"Fetch an image URL returned in an upstream response body, base64-encoded\n    (or None on a non-200).\n\n    The URL comes from the diffusion/OpenAI server's response, not from our own\n    config, so a malicious or compromised endpoint could otherwise steer this\n    fetch at an internal or cloud-metadata address. Validate it the same way the\n    client-supplied endpoint is validated before the first request.\n    \"\"\"\n    import base64\n    import httpx\n    from src.url_safety import check_outbound_url\n\n    ok, reason = check_outbound_url(\n        url,\n        block_private=os.getenv(\"IMAGE_BLOCK_PRIVATE_IPS\", \"false\").lower() == \"true\",\n    )\n    if not ok:\n        raise HTTPException(502, f\"Upstream returned an unsafe image URL: {reason}\")\n    async with httpx.AsyncClient(timeout=60) as c2:\n        ir = await c2.get(url)\n        if ir.status_code == 200:\n            return base64.b64encode(ir.content).decode()\n    return None\n\n\ndef setup_gallery_routes() -> APIRouter:\n    router = APIRouter(tags=[\"gallery\"])\n\n    # ---- POST /api/gallery/upload ----\n    @router.post(\"/api/gallery/upload\")\n    async def gallery_upload(request: Request):\n        \"\"\"Upload an image file to the gallery with EXIF extraction and dedup.\"\"\"\n        import uuid\n        from pathlib import Path\n\n        form = await request.form()","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/odysseus-dev/odysseus/blob/f9235ebbf13f693a6fd29ce70b097f6ec83705bf/routes/gallery/gallery_routes.py#L322-L358","documentation":"Error \"Upstream returned an unsafe image URL: {reason}\" thrown in odysseus-dev/odysseus.","triggerScenarios":"Triggered when the corresponding server-side validation or runtime check at the recorded location rejects the request or operation and returns this error message to the caller.","commonSituations":"See trigger scenarios.","solutions":["The upstream endpoint returned a disallowed image URL; check the endpoint configuration.","Use a trusted image generation endpoint whose URLs pass validation."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f9235ebbf13f693a6fd29ce70b097f6ec83705bf","analyzedAt":"2026-08-14T21:47:48.359Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}