Skip to content

Studio: managed dataset media decodes stay on readable files, and Arrow data files are validated - #14430

Merged
danielhanchen merged 1 commit into
mainfrom
studio-dataset-decode-guard
Oct 21, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
studio-dataset-decode-guard

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Hardening from a security review of dataset preview, check-format and training on multi-account installs. Nothing changes for the owner, Desktop or notebooks, apart from malformed .arrow files (all accounts), which now get a 400 instead of being read.

Problem. datasets decodes media columns lazily. An Image / Audio / Video cell that carries a path and no bytes is opened when previewed, checked or trained on, in the backend or the training worker, as the Studio user:

  • a local path opens any host file the Studio user can read;
  • an hf:// or <endpoint>/datasets/<repo>/resolve/... path for a repo other than the dataset's own is fetched with the server's ambient HF_TOKEN, since token_per_repo_id has no entry for it;
  • other URLs are fetched from the server.

So a managed account could upload a small parquet file whose cells name host images or another account's private Hub files and read them back through the preview. The VLM converters in format_conversion.py likewise Image.open plain string paths without an account check. Separately, .arrow files a user supplies are streamed through datasets' Arrow loader without validation, so a crafted IPC file can make pyarrow read past its buffers.

Change.

  • New utils/security/dataset_media.py, an install-once guard (same pattern and idempotent mark as hub_data_files.py), installed in the backend, training worker, token preview worker and recipe worker. For a managed account, a media cell with a path and no bytes is decoded only when:
    • the local path is the account's own or a Hub snapshot it may see (visible_cached_path), its training job's own dataset snapshot, or under datasets' own extraction folder (zip-packed image datasets keep working);
    • a Hub URL for the dataset's own repo keeps the caller's token; a Hub URL for another repo is fetched anonymously, never with the server's token (public datasets referencing images in other repos keep working);
    • anything else is refused (PermissionError, which check-format reports as a 400).
      The owner gets exactly the original call. audio_decode.py's soundfile fallback is installed with the guard around it.
  • format_conversion.py: the three VLM converters check local image path strings with account_path for managed accounts (the account is captured when the converter starts, since URL loading runs in a thread pool).
  • All accounts: datasets' Arrow loader runs Table.validate(full=True) on user Arrow files before casting. Datasets' own cache files do not go through that loader.

Tests. New test_dataset_media_decode_guard.py and test_arrow_validation.py: 10 fail on main (a managed Image cell pointing outside the workspace previews the file; another repo's hf:// cell is fetched with the server token; http://127.0.0.1, revision-less hf:// and s3:// cells are fetched; VLM string paths outside the account open; a crafted Arrow file returns over-read memory), all 18 pass here, including the controls (embedded image, own-workspace image, owner unchanged, own repo keeps its token, intact Arrow file, install twice). 154 related backend modules show the same failing IDs on both sides.

Left open on purpose: the unsloth-zoo vision collator, which opens string image paths in rows already in messages form.

…date Arrow data files

Dataset Image/Audio/Video/Pdf/Nifti cells that carry only a path are decoded
in the backend and training workers. For a managed account, a local path must
now be one the account may read (its own roots, a Hub snapshot it can see, its
training dataset's snapshot, or an archive datasets extracted), a Hub URL is
fetched only with the caller's token for that repo or anonymously, and other
URLs are refused. String image paths in the VLM converters get the same check.
The owner is unchanged.

The arrow builder now validates each table in full before casting, so a
malformed .arrow data file is a 400 instead of a read past its buffers.

The guard installs once next to the Hub card guard (API process, training,
token preview and recipe workers) and composes with the soundfile audio
decoder.
@danielhanchen danielhanchen self-assigned this Oct 21, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 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-21T02:52:48.927186Z 0dd2179 Manual request
🔒 Security Review ✅ Completed 2026-10-21T02:32:36.718115Z 0dd2179 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 0dd2179bbf

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@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: 0dd2179bbf

ℹ️ 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".

Comment on lines +82 to +83
root = os.path.realpath(str(config.EXTRACTED_DATASETS_PATH))
return os.path.realpath(path).startswith(root.rstrip(os.sep) + os.sep)

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 Restrict extracted media to the current account

In a multi-user installation, datasets.config.EXTRACTED_DATASETS_PATH is an installation-wide cache, so this condition trusts every extracted file regardless of which account or dataset produced it. A managed user who submits a media cell naming a path in another user's extracted archive bypasses visible_cached_path and can have that file decoded and returned; associate extracted paths with an authorized dataset/account rather than blanket-allowing the entire shared extraction root.

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.

Not reachable in practice: datasets names each extraction folder hash_url_to_filename(), so naming another account's extracted file needs that account's exact archive path and the member name, and the extraction root cannot be listed by a managed account. Allowing the root keeps zip-packed image datasets trainable; scoping it per account would need the extraction map plumbed through datasets.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 0dd2179bbf

ℹ️ 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 merged commit c446f65 into main Oct 21, 2026
@danielhanchen
danielhanchen deleted the studio-dataset-decode-guard branch October 21, 2026 04:40
JadeCong pushed a commit to CloudEngineHub/unsloth that referenced this pull request Oct 23, 2026
… archive (unslothai#14529)

Follow-up to unslothai#14430.

**Problem.** For a managed account, the dataset media guard checks the
location a media cell reads from. For a chained fsspec URL it took the
last `::` hop as that location (right for `zip://inner::<outer>`). But
only archive, compression and cache filesystems read through to the next
hop: for `file://<path>::hf://datasets/a/b@main/c.png`, fsspec opens
`<path>` and ignores the Hub URL. A Parquet dataset with such an image
cell therefore passed the check on the Hub URL, and its preview returned
an image from outside the account (a relative `file://` path to another
account's folder).

**Change.** `_permitted_tokens` refuses a chained path when any hop
before the last is not one of `zip`, `tar`, `gzip`, `bz2`, `xz`, `lz4`,
`zstd`, `simplecache`, `filecache`, `blockcache`. The last hop is
checked exactly as before. Owner accounts never reach this guard, so
their datasets are unchanged, and ordinary managed-account datasets
(embedded bytes, files in their own workspace, Hub files, zip members)
preview as before.

**Testing.**
- `test_dataset_media_decode_guard.py`: 16 passed. The new chained-path
test returns the other account's image on main and is refused here; a
zip member of the account's own archive previews on both.
- Neighbouring dataset suites (`test_arrow_validation.py`,
`test_training_worker_import_discipline.py`,
`test_audio_decode_load_order.py`, `test_dataset_image_lists.py`,
`test_vlm_repo_relative_image_paths.py`, `test_vlm_text_only_rows.py`,
`test_data_recipe_preview_image_paths.py`): 54 passed, 8 skipped.
- fsspec 2025.3.0 directly: `file://<x>::hf://...` reads `<x>`;
`zip://in.txt::<zip>` reads the member.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant