Prevent symlink path traversal in local artifact store#18964
Prevent symlink path traversal in local artifact store#18964BenWilson2 merged 4 commits intomlflow:masterfrom
Conversation
Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
|
Documentation preview for 275de93 is available at: More info
|
mlflow/utils/uri.py
Outdated
| return path | ||
|
|
||
|
|
||
| def validate_path_within_directory(base_dir, constructed_path): |
mlflow/utils/uri.py
Outdated
| Returns: | ||
| The constructed_path if validation passes. | ||
| """ | ||
| real_base_dir = os.path.realpath(base_dir) |
| secret_file.write_text("SECRET_CONTENT") | ||
| yield secret_dir | ||
| if secret_dir.exists(): | ||
| shutil.rmtree(str(secret_dir)) |
There was a problem hiding this comment.
we can remove this. pytest removes the tmp directory
| secret_dir = tmp_path.parent / "secrets_outside" | ||
| secret_dir.mkdir(exist_ok=True) | ||
| secret_file = secret_dir / "secret.txt" | ||
| secret_file.write_text("SECRET_CONTENT") |
There was a problem hiding this comment.
| secret_file.write_text("SECRET_CONTENT") | |
| secret_file.touch() |
since contents don't matter
mlflow/utils/uri.py
Outdated
| real_constructed_path = pathlib.Path(constructed_path).resolve() | ||
|
|
||
| try: | ||
| real_constructed_path.relative_to(real_base_dir) |
| ): | ||
| artifact_dir = pathlib.Path(local_artifact_repo.artifact_dir) | ||
| symlink_path = artifact_dir / symlink_name | ||
| os.symlink(str(external_secret_dir), str(symlink_path)) |
There was a problem hiding this comment.
os.symlink only accepts strings?
There was a problem hiding this comment.
pathlib doesn't have a method to create a symlink?
|
|
||
| def validate_path_within_directory(base_dir: str, constructed_path: str) -> str: | ||
| """ | ||
| Validates that the constructed path (after resolving symlinks) is within the base directory. |
There was a problem hiding this comment.
Currently, we blindly follow symlinks. I wonder if that's really ok
There was a problem hiding this comment.
I don't think we have much of an option since symlinks would be entirely justifiable to use from within the scope of the artifact root directory. Blocking traversal outside of that root seems like effective prevention of attack vectors.
Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
🛠 DevTools 🛠
Install mlflow from this PR
For Databricks, use the following command:
Related Issues/PRs
#xxxWhat changes are proposed in this pull request?
Checks that symlink path traversal cannot extend outside of the base artifact path to prevent a path traversal attack.
How is this PR tested?
Does this PR require documentation update?
Release Notes
Is this a user-facing change?
What component(s), interfaces, languages, and integrations does this PR affect?
Components
area/tracking: Tracking Service, tracking client APIs, autologgingarea/models: MLmodel format, model serialization/deserialization, flavorsarea/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registryarea/scoring: MLflow Model server, model deployment tools, Spark UDFsarea/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflowsarea/gateway: MLflow AI Gateway client APIs, server, and third-party integrationsarea/prompts: MLflow prompt engineering features, prompt templates, and prompt managementarea/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionalityarea/projects: MLproject format, project running backendsarea/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev serverarea/build: Build and test infrastructure for MLflowarea/docs: MLflow documentation pagesHow should the PR be classified in the release notes? Choose one:
rn/none- No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" sectionrn/breaking-change- The PR will be mentioned in the "Breaking Changes" sectionrn/feature- A new user-facing feature worth mentioning in the release notesrn/bug-fix- A user-facing bug fix worth mentioning in the release notesrn/documentation- A user-facing documentation change worth mentioning in the release notesShould this PR be included in the next patch release?
Yesshould be selected for bug fixes, documentation updates, and other small changes.Noshould be selected for new features and larger changes. If you're unsure about the release classification of this PR, leave this unchecked to let the maintainers decide.What is a minor/patch release?
Bug fixes, doc updates and new features usually go into minor releases.
Bug fixes and doc updates usually go into patch releases.