fix(security): LLM memory write path traversal + skill name sanitization#17
Merged
fix(security): LLM memory write path traversal + skill name sanitization#17
Conversation
added 2 commits
March 6, 2026 13:34
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.
Two path-traversal vulnerabilities: one in LLM memory sync (arbitrary file write), one in skill name handling (directory escape via frontmatter).
Fix 1 —
apply_memory_via_llm(): validate write path before touching diskRisk: The LLM returns
{"file_path": "/absolute/path", "content": "..."}. A hallucination or prompt-injection attack could return/etc/cron.d/evilandapply_memory_via_llm()would write it — no validation existed.Fix (
appliers/base.py):MEMORY_ALLOWED_BASE: Optional[Path] = Noneclass attribute toBaseApplier.Path(file_path).resolve()(collapses../..etc) and asserts it starts withallowed_base.[security] Rejecting LLM-suggested write outside allowed path:andcontinues on violation.MEMORY_ALLOWED_BASEvia@property:ClaudeApplier→~/.claudeGeminiApplier→~/.geminiCursorApplier→~/.cursorWindsurfApplier→~/.codeium/windsurfOpenClawApplier→~/.openclaw/workspaceCopilotApplier→Path.cwd()(project-relative.github/)Path.home()whenMEMORY_ALLOWED_BASEis unset (e.g. new applier without override).Fix 2 — skill name sanitization: frontmatter path traversal
Risk: A crafted
SKILL.mdwithname: "../../etc/cron.d/evil"in its frontmatter would causesave_skill_file(skill["name"], ...)to write outside~/.apc/skills/. Similarly,link_skills()would create a symlink outside the tool's skill directory.Fix (
skills.py):sanitize_skill_name(name: str) -> str— takes basename only (Path(name).name), validates against^[A-Za-z0-9][A-Za-z0-9_\-]{0,63}$, raisesValueErroron traversal.save_skill_file()(entry point for all disk writes).fetch_skill_from_repo()on the frontmatternamefield, with fallback to the URL path component (already trusted).Fix (
install.py):sanitize_skill_name(skill["name"])beforesave_skill_file()— skips with error message on violation.sanitize_skill_namefromskills.Fix (
appliers/base.pylink_skills):nameviasanitize_skill_name()before constructing symlink paths. Skips with warning on invalid name.Tests
120 existing tests pass unchanged.