fix(skill_manager): allow SKILL.md in _validate_file_path without weakening traversal guard (#40568)

Salvaged from #40453; cleaned up, re-verified against main, tests added.

Co-authored-by: l37525778-coder <l37525778-coder@users.noreply.github.com>
This commit is contained in:
Teknium
2026-06-06 18:32:37 -07:00
committed by GitHub
co-authored by l37525778-coder
parent c0424b06af
commit 5a36f76a00
2 changed files with 28 additions and 1 deletions
+10 -1
View File
@@ -410,10 +410,19 @@ def _validate_file_path(file_path: str) -> Optional[str]:
normalized = Path(file_path)
# Prevent path traversal
# Prevent path traversal (checked before any allow-listing so the SKILL.md
# exception below can never be reached by a traversal-laden path).
if has_traversal_component(file_path):
return "Path traversal ('..') is not allowed."
# SKILL.md is the canonical skill file and lives at the skill root, not
# under an allowed subdirectory. Accept its two natural spellings —
# 'SKILL.md' and '<skill-name>/SKILL.md' — so callers can target the main
# file. The traversal guard above still applies, so this can't escape.
if normalized.parts and normalized.name == "SKILL.md":
if len(normalized.parts) == 1 or len(normalized.parts) == 2:
return None
# Must be under an allowed subdirectory
if not normalized.parts or normalized.parts[0] not in ALLOWED_SUBDIRS:
allowed = ", ".join(sorted(ALLOWED_SUBDIRS))