Repository navigation
Studio: managed-account paths are checked as they are opened - #14428
Conversation
- account_path also requires the name as given (not only its resolved target) to sit under the account roots, so a path through an outside link or a procfs alias is refused. Paths through the owner's linked studio home still pass. - Reference mode no longer treats packaged datasets builder names (pandas, json, csv, ...) as Hub ids for managed accounts. - account_path, model_visible, require_model_allowed and private_directory judge the forward-slash spelling of a path too. - Weight index entries and config.json transformers_weights that are absolute or contain '..' are refused right before chat, export and training loads; sentence-transformers module folders likewise. - Export authorizes every base an adapter folder names (including the decision config's) and re-checks the pinned base right before load. Training authorizes and pins the adapter base of a managed folder that also carries full weights.
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. |
|
@codex review |
|
@codex security review |
|
@codex review |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 487f0b4c0b
ℹ️ 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 pinned_base and adapter_base_changed(checkpoint_path, pinned_base): | ||
| return "The adapter's base model changed after it was checked. Load it again." |
There was a problem hiding this comment.
Preserve an explicit no-base pin
When a managed account's adapter initially has no base_model_name_or_path, _authorized_adapter_base returns None, so this truthiness check performs no comparison. If the account adds an unauthorized local base after route authorization but before the worker reaches this check, line 866 accepts and loads that newly named base without another account-access check. Representing “checked and no base was named” distinctly from “not pinned” is necessary to close this TOCTOU path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Below the bar: this needs the account to add a base to its adapter_config.json inside the window between route authorization and the worker's load, a timing race on its own request; a base named at start is pinned and rechecked.
| folder = module_config.get("path") | ||
| if isinstance(folder, str) and ( | ||
| os.path.isabs(folder) | ||
| or folder.startswith(("/", "\\")) | ||
| or ".." in folder.replace("\\", "/").split("/") | ||
| ): |
There was a problem hiding this comment.
Resolve module-folder symlinks before declaring them contained
A clean relative value such as 0_Transformer passes this syntactic test even when that directory is a symlink to a location outside the selected model folder. For a managed account loading a local SentenceTransformer, the delegated loader then follows the symlink and reads another account's or the operator's files despite the new containment gate. Resolve the module folder against the local model root and verify that the target remains underneath it, while accounting for normal Hub-cache file symlinks.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not reachable for a managed account: its tools cannot create symlinks in their writable roots (Landlock withholds MAKE_SYM, the macOS profile denies it) and uploads write regular files, so a module folder in its workspace cannot be a link to elsewhere.
| resolved = path.resolve() | ||
| # Callers reopen the name itself, so every link it walks through must sit inside the roots too. | ||
| lexical = Path(os.path.abspath(path)) |
There was a problem hiding this comment.
Reject paths whose intermediate symlinks leave the account roots
Checking only the lexical path and its final resolved target does not establish the comment's invariant that every traversed link stays inside the roots. For example, an in-workspace link can point to an external directory whose next link points back into the workspace; both checks pass, but that external link can be retargeted after validation so the caller later opens a foreign path. Inspect each resolved prefix or use a confined descriptor-based open rather than relying only on the two endpoints.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Same reason: a managed account cannot create links inside its roots, so a chain through an in-workspace link cannot be built; the lexical check covers the /proc//cwd and outside-link names it can produce.
…apter pin on the load target; check weights before every training backend [skip ci]
…apter base at export, allow module folders that stay inside [skip ci]
…dexes, refuse drive-relative module folders
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a843f3245
ℹ️ 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".
| for folder in (config["model_name"], lora_base): | ||
| if folder and escaping_weight_references(folder): |
There was a problem hiding this comment.
Apply weight confinement to diffusion loads
For a managed account loading a local Diffusers pipeline through /images/load, this check never runs because load_diffusion_model_gated launches engine.begin_load rather than entering _handle_load. Those pipelines load Transformers indexes from component directories such as text_encoder/ and transformer/, so an index there can name ../../victim/model.safetensors and read outside the authorized pipeline folder. Validate the actual diffusion component load roots immediately before the media engine begins loading.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Out of scope here. This PR covers the chat, training and export loaders; the image pipeline loader is a separate path, and reading through it is limited to files that parse as safetensors. Tracking it separately rather than widening this change.
… decision adapter's base at training start [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f0e8507c56
ℹ️ 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".
| raise _training_start_error(400, "training_decision_adapter_base", str(exc)) | ||
| base = _authorize_adapter_base(str(folder), hf_token) | ||
| # The worker re-reads the pin at the model root, so pin only a root adapter. | ||
| pin = None if request.model_subfolder else base or "" |
There was a problem hiding this comment.
Retain the pin for subfolder decision adapters
When a managed account selects a local decision adapter through model_subfolder, this discards the authorized base pin. The worker's confinement pass scans only model_name, model_local_path, model_snapshot_path, and adapter_base_pin, so it examines neither the adapter subfolder nor its now-unpinned local base; FastDecisionModel.from_pretrained(root, subfolder=...) subsequently loads both. Thus a base whose weight index escapes its own folder, or an adapter config changed after preflight, bypasses the worker check. Carry the pin and make the recheck resolve the actual subfolder load target.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Leaving this. The subfolder adapter's base is still authorized at start; what remains needs a managed account to change its own adapter after the check or to point it at a base in its own workspace whose index escapes, through the less common subfolder selection. Not worth widening the worker recheck for.
| folder = module_config.get("path") | ||
| # modules/../1_Pooling stays inside: only a folder that normalizes above the model escapes. | ||
| normalized = ( |
There was a problem hiding this comment.
Apply module containment to the custom assembly path
This containment guard is called only by the delegated SentenceTransformer(...) branches. When training takes the custom _load_modules path—for example with UNSLOTH_COMPILE_DISABLE=1, or for a model outside the fast-encoder set—the code later passes the unchecked module_config["path"] to _create_transformer_module or os.path.join(model_name, module_path). A local checkpoint with ../victim or an absolute module folder therefore still loads outside the model on that supported path. Reuse this validation before _load_modules opens any declared module folder.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not needed for the Studio boundary: the training, inference and export workers run escaping_weight_references before any loader, and it refuses a modules.json folder that escapes (../victim or absolute) whichever Sentence Transformers path loads it. In a notebook the user loads their own folder.
…oted shard names inside module folders [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
…es the model (unslothai#14527) Follow-up to unslothai#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 unslothai#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).
Hardening from a security review of multi-account confinement. The owner, Desktop and notebooks load, train and export any real model as before; managed accounts lose only path spellings that leave their own roots.
Problem. Several places decided "is this path inside the managed account's roots?" on one spelling of the path and then opened another:
account_pathcheckedPath(value).resolve()but returned the original string, which callers reopen later. A name through/proc/<pid>/cwd/...(a process the account controls canchdir) or through a link outside the roots passed the check and could point elsewhere at open time.datasetsbuilder name (pandas,json,text, ...) passed as a Hub id, andload_dataset("pandas")then reads files from the server's working directory (pandasunpickles them).\as written, while the loader normalises\to/, so<own workspace>/\..\<other account>\modelpassed the gate and loaded the other account's model.model.safetensors.index.json,pytorch_model.bin.index.json,config.jsontransformers_weights) and sentence-transformersmodules.jsonfolders were followed even when absolute or.., so a folder in the account's workspace could load another account's weights.adapter_config.json.Change.
account_pathalso requires the path as typed (lexically absolute) to sit under the account roots; a workspace reached through an owner-made symlinked studio home is still accepted. Bare builder names fall through to the path check in reference mode (real Hub ids pass; validation never importsdatasets).account_path,model_visible,require_model_allowed,private_directory: both the\and/spellings must pass.utils/security/file_security.py:escaping_weight_referencesflags absolute or..shard names, checked right before load in the export, inference and training workers. A text check, so Hugging Face cache symlinks keep working.FastSentenceTransformerrefuses an absolute or..module folder inmodules.jsonthe same way.adapter_load_basesincore/export/decision.py) andload_checkpointre-checks the pinned base right beforefrom_pretrained. Training authorizes and pins a managed account's adapter base before the early return; the owner's order is unchanged.The weight-index and module-folder checks apply to every account, because the worker processes do not know the account; a genuine checkpoint never has absolute or
..shard names. All checks are pure; repeating them is a no-op.Tests. New
studio/backend/tests/test_account_path_confinement.py(17 of 23 fail on main) andtests/test_st_modules_json_folder_containment.py(3 of 4 fail on main); all pass here. The tests passing on both sides are the guards: linked studio home, owner paths, real Hub ids, an unchanged adapter, a stock module layout. 226 backend modules that use the touched code: 14291 passed on both sides with the same failing IDs (pre-existing native-audio and cache-inventory cases); Core sentence-transformers tests: 0 failures.