fix: block path traversal via spec name/version in persistence - #114
Merged
Conversation
…+ delete) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FTZQT3bQzqTBXQXvDsk4w9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Security fix — path traversal in spec persistence (audit finding)
metaseed.specs.persistencebuilt filesystem paths from a spec's version (and, on delete, its name) without sanitization, so a crafted value escaped the custom-specs directory.save_specsanitized the profile name but interpolatedspec.versionraw:get_custom_specs_dir() / safe_name / spec.version→mkdir(parents=True)+ writeprofile.yaml.version="../../.config/autostart"writes aprofile.yamlinto an attacker-chosen directory (autostart → persistence). Reachable via the MCPspec_savetool, whereversionis model-controlled (spec_set_metadata/spec_clone).delete_user_specinterpolatednameandversionraw beforeshutil.rmtree(...)— a destructive traversal.Fix
New
_specs_subpath(*parts)resolves the path underget_custom_specs_dir()and raisesValueErrorunless it stays within the (resolved) base (Path.is_relative_to), also rejecting empty components. Bothsave_spec(version) anddelete_user_spec(name + version, before anyrmtree) route through it. Blocks.., absolute paths, and symlink escape in one place. Same containment approach as the dataset-name fix in #100, adapted since versions legitimately contain dots.Tests (
tests/test_specs/test_persistence_security.py)PoC-style, contained in
tmp_path(monkeypatchedget_custom_specs_dir):save_specwith a relative-traversal, absolute, and emptyversion→ raises, and no file appears outside the base.delete_user_specwith a traversalversionand a traversalname→ raises and a planted sentinel dir outside the base is untouched (rmtree never reached).version="1.0"saves and deletes correctly.tests/test_specs(320) pass; ruff + strict mypy clean.🤖 Generated with Claude Code
https://claude.ai/code/session_01FTZQT3bQzqTBXQXvDsk4w9