T09 · Insecure Skill Coding Practices
- Location
scripts/hooks_manager.py:89- Finding
Path Traversal and Absolute-Path Injection Enable Arbitrary File Write and Deletion
- Content
View full analysis
bool: """Install a hook by name.""" if hook_name not in HOOK_NAMES: print(f"Warning: {hook_name} is not a standard Git hook name") hook_path = self.hooks_dir / hook_name if script: content = script elif template and template in TEMPLATES: content = TEMPLATES[template] else: # Default no-op hook content = "#!/bin/sh\n# Hook installed by git-hooks-manager\n" with open(hook_path, "w") as f: f.write(content) # Make executable on Unix if os.name != "nt": os.chmod(hook_path, 0o755) print(f"Installed {hook_name} hook at {hook_path}") return True def uninstall(self, hook_name: str) -> bool: """Remove a hook.""" hook_path = self.hooks_dir / hook_name if hook_path.exists(): hook_path.unlink() ``` `scripts/hooks_manager.py:163-169`: ```python def import_config(self, path: str) -> None: """Import hook configuration from JSON.""" with open(path) as f: config = json.load(f) for hook_name, script in config.get("hooks", {}).items(): self.install(hook_name, script=script) print(f"Imported hooks config from {path}") ``` ### Technical Analysis The `hook_name` value is used directly as a filesystem path component. Although the implementation checks whether it appears in `HOOK_NAMES`, an invalid value only generates a warning and is still processed. `pathlib.Path` does not constrain the resulting path to `self.hooks_dir`: - A value containing `../` can traverse outside the Git hooks direc ...[truncated 2676 chars]- Remediation
View remediation
