- Location
- scripts/skill-creator/auto_skill_generator.py:416
- Finding
- Path and Python Source Injection in Automatic Skill Generation<![CDATA[
## Vulnerability Details
**File Location**: `scripts/skill-creator/auto_skill_generator.py:416-547`
**Vulnerability Type**: Generated-file path traversal and generated-code injection
**Risk Level**: High
### Vulnerable Code
Only the generated directory name is sanitized:
```python
def generate_skill(
self,
name: str,
pattern_type: str,
description: str = "",
steps: List[str] = None,
triggers: List[str] = None
) -> Tuple[bool, str]:
"""Generate a new Skill."""
safe_name = re.sub(r'[^a-zA-Z0-9_-]', '-', name.lower())
skill_dir = self.skills_dir / safe_name
if skill_dir.exists():
return False, f"Skill already exists: {safe_name}"
try:
skill_dir.mkdir(parents=True, exist_ok=True)
(skill_dir / "scripts").mkdir(exist_ok=True)
(skill_dir / "references").mkdir(exist_ok=True)
self._generate_skill_md(
skill_dir,
name,
pattern_type,
description,
steps,
triggers
)
self._generate_main_script(
skill_dir,
name,
pattern_type,
steps
)
self._generate_readme(
skill_dir,
name,
description,
triggers
)
self._save_skill_meta(
skill_dir,
name,
pattern_type,
triggers
)
return True, str(skill_dir)
except Exception as e:
if skill_dir.exists():
import shutil
shutil.rmtree(skill_dir)
return False, f"Generation failed: {e}"
```
The unsanitized name is reused in persistent Skill instructions:
```python
content = f"""# {name}
Automatically generated Skill - {pattern_type}
## Functionality
{description or f'Automatically process tasks related to {pattern_type}'}
{steps_text}
{triggers_text}
## Usage
```bash
python3 scripts/{name}.py [arguments]
```
"""
```
It is also i
...[truncated 3507 chars]
- Remediation
- <![CDATA[
## Remediation Suggestions
1. Define one canonical identifier and use it for the directory, filename, metadata, and generated source.
2. Reject invalid identifiers instead of silently transforming them:
```python
if not re.fullmatch(r"[a-z][a-z0-9_-]{0,63}", name):
raise ValueError("Invalid Skill name")
```
3. Resolve every generated path and verify that it remains beneath `SKILLS_DIR`.
4. Reject absolute paths, separators, traversal components, control characters, quotes, and newlines in identifiers.
5. Do not interpolate user-controlled values directly into Python templates.
6. Serialize display values with `repr()` or, preferably, generate code through an AST or a fixed template with validated data files.
7. Keep descriptions and steps in JSON metadata rather than executable Python wherever possible.
8. Mark generated Markdown as untrusted draft content and require human review before registration or activation.
9. Do not automatically register triggers until the generated Skill passes validation.
10. Run syntax checks and static security checks in a sandbox before exposing a generated script.
11. Execute generated Skills under a restricted account with no network access and write access limited to a dedicated workspace.
12. Add tests for absolute names, multi-level traversal, quote termination, triple-quote termination, newline injection, and Markdown instruction injection.
]]>