Skip to content

Studio: fetch VLM dataset row image URLs through the SSRF-guarded fetch - #14701

Merged
danielhanchen merged 9 commits into
mainfrom
studio-vlm-row-image-ssrf
Oct 23, 2026
Merged

danielhanchen merged 9 commits into
mainfrom
studio-vlm-row-image-ssrf

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Summary

VLM dataset conversion opened row image URLs with fsspec.open(url, "rb", expand=True). That call follows redirects to any host, including loopback, the LAN and cloud metadata addresses, and has no size cap. The image-column probe sent an unguarded urllib HEAD request to the same row values. Row values are dataset content, so a crafted dataset could make Studio issue requests to internal addresses once per row.

Adapted from LeoBorcherding/unsloth-security-staging#85 and #66.

Changes

  • Both converters (convert_to_vlm_format, convert_sharegpt_with_images_to_vlm_format) now fetch through core.inference.tools._fetch_url_raw, the web tool's guarded fetch:
    • public addresses only
    • pinned to the resolved IP
    • every redirect re-checked
    • a 64 MiB cap per image
  • The detection probe's HEAD uses the same fetch.
  • utils/datasets/remote_images.py wraps datasets.Image.decode_example once, at import (idempotent). A typed Image() cell holding only a URL is otherwise fetched by datasets itself, wherever a row is read: detection, previews, conversion, streaming and nested Sequence(Image()). For a bytes-less cell:
    • a non-Hub http(s) URL is fetched through the same guard and handed to datasets as bytes, so EXIF handling is unchanged
    • Hub URLs (exact origin of HF_ENDPOINT) keep datasets' own token-aware fetch
    • every hop of a :: chained path is checked: a scheme outside local, Hub, cloud object stores and datasets' archive/compression wrappers (ftp, sftp, smb, ...) is refused, as is a non-Hub URL inside a chain
    • UNC paths and file: URLs naming a remote host are refused, so a row cannot make Windows open an SMB share
  • String rows naming a network share are refused before the probe's os.path.exists or the conversion's Image.open.
  • A refused URL counts as a failed image, like any other download error.

Public image URLs (including HF resolve-to-CDN redirects), embedded images, data: URLs, local paths, _own_image_path and repo-relative lookups behave as before. The probe's local-path check is unchanged. #66's restriction to the datasets folder is left out, so that local image datasets keep their column detection.

Behaviour change

Image URLs on localhost or private-network hosts, images over 64 MiB, image URLs with schemes such as ftp:// or smb://, non-Hub URLs inside a :: chain, and network share paths are now refused.

Tests

  • tests/test_vlm_conversion_row_urls.py: loopback is refused in both converters, for string rows and for Image()-typed rows (also nested and streamed); public URLs go through the guarded fetch; embedded and Hub images keep datasets' own decode; lookalike Hub hosts, unsupported schemes, chained hops and network shares are refused; local and Hub archive paths still reach datasets.
  • tests/test_vlm_probe_untrusted_rows.py: private URLs are never dialled, public URLs use a guarded HEAD, network share paths are never probed.
  • tests/test_vlm_text_only_rows.py: switched from a loopback server to a stubbed fetch.

Every new case fails on the head before its fix and passes here. The dataset and VLM suites give 2232 passed, 63 skipped. test_search_images.py needs the optional ddgs package and fails the same way on main.

Row image URLs are dataset content, not user input. Conversion opened them with
fsspec.open(..., expand=True), which follows redirects to any host, including
loopback, the LAN and cloud metadata addresses, with no size cap. The image-column
probe sent an unguarded urllib HEAD to the same values.

Both now go through core.inference.tools._fetch_url_raw: public addresses only,
pinned to the resolved IP, every redirect re-checked, and conversion downloads are
capped at 64 MiB per image. Public image URLs, embedded images, local paths and
repo-relative lookups behave as before; a refused URL counts as a failed image
like any other download error.

Adapted from LeoBorcherding/unsloth-security-staging#85 and #66 (the probe's
local-path restriction is left out so local image datasets keep their detection).
@danielhanchen danielhanchen self-assigned this Oct 22, 2026
[skip ci]
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T19:26:30.506511Z 3cd258a Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ad0a72f6b3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

):
if "::" in path:
raise OSError(f"Refusing a remote archive image path: {path}")
value = {"path": None, "bytes": fetch_untrusted_image_bytes(path)}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Defer typed URL decoding until the per-row handler

When an Image()-typed HTTP dataset has a valid first row and any later URL is refused or broken, this eager fetch runs while tqdm(dataset) advances the iterator, before the try around _convert_single_sample in format_conversion.py. The resulting OSError therefore aborts the entire conversion instead of counting and skipping the failed row as string-backed URL datasets do, even when the failure rate is below the permitted 30%.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-existing and unchanged here: on main, datasets also fetches Image() URL cells while the iterator advances, so a broken typed URL already aborts conversion. This PR only routes that same fetch through the SSRF guard.

):
if "::" in path:
raise OSError(f"Refusing a remote archive image path: {path}")
value = {"path": None, "bytes": fetch_untrusted_image_bytes(path)}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve parallel conversion for typed URL columns

For an Image()-typed public URL column, this wrapper turns each cell into a PIL image before convert_to_vlm_format inspects it. Consequently first_image is no longer a string, has_urls becomes false, and the converter takes its serial iteration branch instead of the URL thread pool and 200-row probe; it also downloads the first image again during conversion. Large typed remote-image datasets therefore become substantially slower than equivalent string-backed datasets.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-existing and unchanged here: Image()-typed columns already reach the converter as decoded PIL images on main, so they took the serial path before this PR too. Only the fetch underneath is now guarded.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

…ares

fsspec opens each hop of a chained path, so an unsupported scheme or a
non-Hub URL anywhere in the chain is refused, not only in the last hop.
datasets own archive and compression wrappers (zip, tar, gzip, ...) still
chain onto local and Hub paths. UNC paths and file: URLs naming a remote
host are refused so a dataset row cannot make Windows open an SMB share.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 22, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 22, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 22, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 22, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 22, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 22, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 22, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 22, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 22, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 22, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 22, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 22, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 22, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 3cd258a7d1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen danielhanchen added important# refactor# regresses# security# Moves a security boundary: sandbox, allowlist, permission or network guard labels Oct 22, 2026
@danielhanchen
danielhanchen merged commit 866fed8 into main Oct 23, 2026
2 of 37 checks passed
@danielhanchen
danielhanchen deleted the studio-vlm-row-image-ssrf branch October 23, 2026 02:13
danielhanchen added a commit that referenced this pull request Oct 23, 2026
…at startup (#14888)

## Summary

#14701 routes dataset image URLs through the SSRF-guarded fetch by
patching `datasets.Image.decode_example`. It applies that patch with a
module-level `install_guarded_image_decode()` call in
`utils/datasets/remote_images.py`, which runs `from datasets import
config`. That module is on the startup import path:

```
routes/__init__.py -> routes/datasets.py -> hub/services/datasets/formatting.py
-> hub/utils/dataset_format.py -> utils/datasets/__init__.py -> format_conversion.py -> remote_images.py
```

So every Unsloth Studio and Desktop start loads `datasets`, `pandas` and
`pyarrow` (and `torch` in CI). On main this fails
`test_startup_defers_torch.py` (4 tests), and the Startup profile job
fails its budget: 8.123 s median to a healthy port against 8.0 s.

## Change

The guard itself is unchanged. Only when it is installed changes:

- If `datasets.features.image` is already imported, it is patched
immediately, as before.
- Otherwise a meta-path finder wraps that module's loader and patches it
as soon as it finishes loading, before any caller can decode a row. This
is the same pattern `utils/security/hub_data_files.py` uses.

`install_guarded_image_decode()` keeps its name and idempotence. It now
takes the module as an optional argument, so it can patch from inside
the loader. The finder is inserted once.

## Testing

- New `test_guard_applies_when_datasets_loads_after_this_module` runs in
a subprocess. It imports `remote_images` first and asserts `datasets`
was not loaded, then imports `datasets.features.image` and asserts
`decode_example` is guarded.
  - On main's code: this test and the 4 startup tests fail (5 failed).
  - With this change: all pass.
- Dataset, VLM, image, format and startup test files in
`studio/backend/tests`: 2598 passed, 34 skipped.
- `import main` wall time, 5 runs each on the same machine: main 9.07
(cold), 6.36, 6.07, 6.26, 6.34 s; this branch 6.12, 6.12, 5.72, 5.70,
5.54 s.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
danielhanchen added a commit that referenced this pull request Oct 23, 2026
…sion harness (#14903)

## Summary

`TestFormatConversionNoTorchVenv` (4 tests, Python 3.12 and 3.13) fails
on main, so Backend CI is red on every PR:

```
File "<string>", line 10, in <module>
ImportError: attempted relative import with no known parent package
```

The harness execs `format_conversion.py` as a standalone script and
rewrites its relative imports (`.cells`, `.iterable`,
`.format_detection`) to top-level ones. #14701 added `from
.remote_images import fetch_untrusted_image_bytes, is_network_share` on
line 10, which the harness does not rewrite.

## Change

Rewrite `from .remote_images import` the same way as `.cells` in the
four exec snippets. `remote_images.py` imports only the standard library
at module level, so it loads in the no-torch venv. Test-only change.

## Testing

- `tests/python/test_studio_import_no_torch.py` on main: 4 failed. With
this change: 29 passed.
- With #14888's `remote_images.py` (guard installed on datasets import)
in place: 29 passed.
NilayYadav pushed a commit to samihsq/unsloth that referenced this pull request Oct 23, 2026
…ths, unencoded spaces) (unslothai#14966)

## Summary

unslothai#14701 routes dataset image URLs through the SSRF guard, so an untrusted
dataset cannot make Studio fetch loopback, LAN or metadata addresses. A
recheck of the user flows found that it also blocked things owners do on
purpose, with no way back:
- images served from the owner's own LAN or loopback server (a NAS,
MinIO, a local file server)
- images on a Windows share the owner uses
- chained cells into a public non-Hub archive, such as
`zip://img.png::https://images.example.org/images.zip`
- `\\wsl$\...` and `\\wsl.localhost\...` paths (the user's own WSL
distro), and `//`-prefixed paths on Linux and macOS, which are ordinary
local paths there
- image URLs with a raw space (`https://host/my images/a b.png`), which
the web tool's URL check rejects but fsspec used to quote

## Changes

`utils/datasets/remote_images.py`:
- `UNSLOTH_ALLOW_PRIVATE_URL_FETCH=1`, the opt-in `unsloth_zoo` already
honours for media URLs, turns the image guard off on a single-user
install: image cells and string URLs load the way `datasets` and fsspec
loaded them before unslothai#14701. Once managed accounts exist it is ignored, so
a row a managed account supplies cannot reach the owner's LAN; an
unreadable account store keeps the guard on. It is read on every call,
so it takes effect without a restart.
- a refusal of a private or local destination, a share or a non-Hub
archive names that variable; a 404, timeout or size refusal is reported
as is
- `is_network_share` only applies on Windows, and treats `wsl$` and
`wsl.localhost` as local
- `guard_url` percent-encodes a raw space (and other characters a
browser would) in the path, query and fragment before the guard; the
host is left alone so an internationalized name still goes through IDNA,
and an already-encoded URL is unchanged

`format_conversion.py` and `format_detection.py` use the same opt-in,
share rule and quoting for string rows and the column probe. With the
opt-in on, a URL column is still probed (a plain HEAD request), so a
broken column loses to a working one. The probe and the string-row fetch
share one small `urllib` helper that quotes the URL and IDNA-encodes an
internationalized host, and the row fetch keeps the guarded fetch's
limits: the 64 MB image cap (a declared size over it is refused, and the
read stops at the cap when no size is sent), the 30 s timeout and the 60
s overall deadline. Typed `Image()` cells are decoded by `datasets`
itself, as they are without Studio.

The default for everyone else is unchanged: public addresses only, every
redirect re-checked, size capped.

## Tests

`tests/test_vlm_conversion_row_urls.py`:
- WSL and `\\?\C:\` paths reach `datasets` on Windows, and `//data/...`
reaches it off Windows
- refusals name the opt-in
- with the opt-in on a single-user install, a loopback image server
works for string rows and typed `Image()` cells, and a non-Hub archive
chain reaches `datasets`
- with managed accounts the opt-in is ignored and a loopback image is
refused
- only a private-destination refusal suggests the opt-in
- with the opt-in, a 404 column loses to a working column
- an internationalized host is not percent-encoded
- a raw space in an image URL reaches the guard percent-encoded
- with the opt-in, an image over the size cap is refused, with and
without a declared size
- opted-in requests are quoted, IDNA-encoded and carry the image timeout
- the existing share-refusal tests pin Windows mode, so they still check
the Windows rule on Linux CI

The new cases fail on `main` and pass here. The VLM conversion and probe
suites give 55 passed (52 on the windows-latest, ubuntu-latest and
macos-15 runners before the size-cap commit), and the 14 test files that
import the changed modules give 1275 passed. The one failure there,
`test_csv_cells_as_written.py::test_csv_files_missing_a_column_still_load_together`,
also fails on `main`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

important# refactor# regresses# security# Moves a security boundary: sandbox, allowlist, permission or network guard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant