Repository navigation
Studio: flag a modules.json folder of only dots and slashes that leaves the model - #14527
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
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. |
|
@codex review |
|
@codex security review |
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
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]
…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.
Follow-up to #14428.
Problem.
escaping_weight_referencesreads a Sentence Transformers folder'smodules.jsonand flags module folders outside the model. Before the escape check it skipped paths thatstrip("./\\")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 inunslothis unchanged.Testing.
test_account_path_confinement.py: 38 passed. The 6 new escape cases (..,../..,/,\,./..,..\..) fail on main; the root cases ("",.,./) pass on both.test_embedding_model_security_gate.py,test_export_decision_backend.py,test_decision_training_route.py,test_export_absolute_paths.py): 134 passed. Onetest_export_absolute_paths.pycase fails the same way on main in this environment (core.inference.diffusion_loranot importable).