Skip to content

Studio: flag a modules.json folder of only dots and slashes that leaves the model - #14527

Merged
danielhanchen merged 2 commits into
mainfrom
studio-modules-json-dot-paths
Oct 23, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
studio-modules-json-dot-paths

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #14428.

Problem. escaping_weight_references reads a Sentence Transformers folder's modules.json and flags module folders outside the model. Before the escape check it skipped paths that strip("./\\") empties, meant for the model root ("", ., ./). But .., ../.., / and \ are also only dots and slashes, so they were skipped too, and a managed account's model folder could name a module folder above it (its account root, or the Studio root) without the load, export or training gate noticing.

Change. The escape check now runs first; the self-folder skip comes after it. A module at the model root is still accepted, so ordinary Sentence Transformers folders load as before. The check runs for every account's local model folder (as the existing weight-index check does since #14428), but no real model names a module folder like .. or /, so nothing changes for real models. Notebook loading in unsloth is unchanged.

Testing.

  • test_account_path_confinement.py: 38 passed. The 6 new escape cases (.., ../.., /, \, ./.., ..\..) fail on main; the root cases ("", ., ./) pass on both.
  • Neighbouring suites (test_embedding_model_security_gate.py, test_export_decision_backend.py, test_decision_training_route.py, test_export_absolute_paths.py): 134 passed. One test_export_absolute_paths.py case fails the same way on main in this environment (core.inference.diffusion_lora not importable).

@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-22T15:55:50.706287Z 74f0eca Manual request
🔒 Security Review 🔄 Running since 2026-10-22T15:54:11.029221Z 74f0eca 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

Copy link
Copy Markdown

The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins.

@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 Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 74f0eca953

ℹ️ 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 b515632 into main Oct 23, 2026
@danielhanchen
danielhanchen deleted the studio-modules-json-dot-paths branch October 23, 2026 03:40
danielhanchen added a commit that referenced this pull request Oct 23, 2026
Conflicts:
- studio/backend/utils/security/file_security.py: main (#14527) moved the
  modules.json escape check ahead of the self-folder skip so "..", "../.."
  and "/" (only dots and slashes) are flagged. This branch replaced the
  lexical _escapes_folder(sub) with _escapes(folder, sub), which also
  resolves a ".." climbing through a symlinked directory. Kept main's
  ordering and comment and this branch's _escapes(folder, sub) call.
- tests/test_fp8_block_small_m.py: this branch only carried pre-commit
  formatting; main has the same formatting plus the autouse
  _no_block_gemv fixture (#14813). Took main's file.

[skip ci]
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Oct 23, 2026
…ers (unslothai#14952)

Follows up unslothai#14527.

### What was wrong

`escaping_weight_references` skipped every `modules.json` module path
made only of dots and slashes (`if not sub.strip("./\\"): continue`).
unslothai#14527 moved the escape check ahead of that skip, which catches `..`,
`../..`, `/` and `\`, but `...`, `./...` and `..../` are ordinary folder
names: they do not normalize to `..`, so they passed the escape check
and were then skipped, and the index inside them was never read.
Sentence Transformers accepts such a path (`_validate_relative_path`
only rejects rooted paths and `..` components) and opens
`Path(model_dir, sub)`; transformers then joins each shard name onto
that folder (`os.path.join(path, subfolder, f)` in
`get_checkpoint_shard_files`). So an index in `.../` naming
`../../outside.safetensors` loads a file from outside the model folder
without being flagged.

### Fix

- Only a module path that normalizes to `.` (`""`, `.`, `./`) is treated
as the model root and skipped.
- The path is judged both with backslash as a separator (Windows) and as
a literal name character (POSIX, where Sentence Transformers opens it as
written); if either reading escapes, the module path is flagged.
- Otherwise the index is read from the folder the loader actually opens,
and its entries are checked against each reading.
- The earlier escape check is unchanged.

### Tests

- New cases in `test_account_path_confinement.py`: `...`, `./...`,
`..../`, `....`, `0_Transformer/...` and `.\...` (POSIX only) are
flagged when their index escapes and pass when it does not;
`0_Transformer`, `.` and `./` keep their verdict.
- The new dot-folder cases fail on main (5 failed) and pass here; the
file gives 47 passed.
- 9 other test files that use `file_security`: 716 passed; 2 failures
there also fail on main (a module missing from the test environment).

Not run: Windows (backslash cases checked on Linux only), a real
Sentence Transformers load of a `...` folder (loader behaviour read from
the 6.2.0 source and the transformers shard resolver), a live Studio
server.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant