gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
34.01k stars 2.58k forks source link

gr.File as Output throws hostname failed validation #9828

Open bergerchris opened 3 weeks ago

bergerchris commented 3 weeks ago

Describe the bug

I am using the component File as an output to make some created files available. The input for the component is an url. This worked with version 4.29.0 but is now broken. It throws an ValueError: Hostname 127.0.0.1 failed validation.

I can fix the error by adding 127.0.0.1 to PUBLIC_HOSTNAME_WHITELIST = ["hf.co", "huggingface.co"] in processing_utils.py. So basically I need an option to add trusted hostname to the list or maybe there is another option to deactivate this validation?

Have you searched existing issues? 🔎

Reproduction

import gradio as gr

Screenshot

No response

Logs

Traceback (most recent call last):
  File "/Users/berger/ai-converter-web-app/.venv/lib/python3.10/site-packages/gradio/queueing.py", line 624, in process_events
    response = await route_utils.call_process_api(
  File "/Users/berger/ai-converter-web-app/.venv/lib/python3.10/site-packages/gradio/route_utils.py", line 323, in call_process_api
    output = await app.get_blocks().process_api(
  File "/Users/berger/ai-converter-web-app/.venv/lib/python3.10/site-packages/gradio/blocks.py", line 2028, in process_api
    data = await self.postprocess_data(block_fn, result["prediction"], state)
  File "/Users/berger/ai-converter-web-app/.venv/lib/python3.10/site-packages/gradio/blocks.py", line 1834, in postprocess_data
    prediction_value = block.postprocess(prediction_value)
  File "/Users/berger/ai-converter-web-app/.venv/lib/python3.10/site-packages/gradio/components/file.py", line 197, in postprocess
    value = self._download_files(value)
  File "/Users/berger/ai-converter-web-app/.venv/lib/python3.10/site-packages/gradio/components/file.py", line 173, in _download_files
    downloaded_file = processing_utils.save_url_to_cache(
  File "/Users/berger/ai-converter-web-app/.venv/lib/python3.10/site-packages/gradio/processing_utils.py", line 470, in ssrf_protected_download
    return client_utils.synchronize_async(
  File "/Users/berger/ai-converter-web-app/.venv/lib/python3.10/site-packages/gradio_client/utils.py", line 872, in synchronize_async
    return fsspec.asyn.sync(fsspec.asyn.get_loop(), func, *args, **kwargs)  # type: ignore
  File "/Users/berger/ai-converter-web-app/.venv/lib/python3.10/site-packages/fsspec/asyn.py", line 103, in sync
    raise return_result
  File "/Users/berger/ai-converter-web-app/.venv/lib/python3.10/site-packages/fsspec/asyn.py", line 56, in _runner
    result[0] = await coro
  File "/Users/berger/ai-converter-web-app/.venv/lib/python3.10/site-packages/gradio/processing_utils.py", line 419, in async_ssrf_protected_download
    response = await async_get_with_secure_transport(
  File "/Users/berger/ai-converter-web-app/.venv/lib/python3.10/site-packages/gradio/processing_utils.py", line 401, in async_get_with_secure_transport
    verified_ip = await async_validate_url(url)
  File "/Users/berger/ai-converter-web-app/.venv/lib/python3.10/site-packages/gradio/processing_utils.py", line 390, in async_validate_url
    raise ValueError(f"Hostname {hostname} failed validation")
ValueError: Hostname 127.0.0.1 failed validation

System Info

Gradio Environment Information:
------------------------------
Operating System: Darwin
gradio version: 5.3.0
gradio_client version: 1.4.2

------------------------------------------------
gradio dependencies in your environment:

aiofiles: 23.2.1
anyio: 4.3.0
fastapi: 0.115.3
ffmpy: 0.3.2
gradio-client==1.4.2 is not installed.
httpx: 0.27.0
huggingface-hub: 0.26.1
jinja2: 3.1.3
markupsafe: 2.1.5
numpy: 1.26.4
orjson: 3.10.1
packaging: 24.0
pandas: 2.2.2
pillow: 10.3.0
pydantic: 2.7.0
pydub: 0.25.1
python-multipart: 0.0.9
pyyaml: 6.0.1
ruff: 0.4.1
semantic-version: 2.10.0
starlette: 0.41.0
tomlkit==0.12.0 is not installed.
typer: 0.12.3
typing-extensions: 4.11.0
urllib3: 2.2.1
uvicorn: 0.29.0
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.

gradio_client dependencies in your environment:

fsspec: 2024.3.1
httpx: 0.27.0
huggingface-hub: 0.26.1
packaging: 24.0
typing-extensions: 4.11.0
websockets: 11.0.3

Severity

Blocking usage of gradio

bergerchris commented 1 week ago

Any news on this or maybe a workaround? At the moment I don't know what to do here.

bergerchris commented 6 days ago

For anyone who has the same error and is looking for a quick way to fix this. I monkey patched it with this:

from gradio.processing_utils import PUBLIC_HOSTNAME_WHITELIST

PUBLIC_HOSTNAME_WHITELIST.append("127.0.0.1")