T09 · Insecure Skill Coding Practices
- Location
src/utils.py:75- Finding
Path Traversal Enables Arbitrary Markdown File Read, Write, and Deletion
- Content
View full analysis
str: user_prompt_path = os.path.join( get_prompts_dir(), f"{prompt_name}.md" ) if os.path.exists(user_prompt_path): with open(user_prompt_path, 'r', encoding='utf-8') as f: return f.read() default_prompt_path = os.path.join( "prompts", f"{prompt_name}.md" ) if os.path.exists(default_prompt_path): with open(default_prompt_path, 'r', encoding='utf-8') as f: return f.read() raise FileNotFoundError( f"Prompt template {prompt_name} does not exist" ) def save_prompt(prompt_name: str, content: str) -> None: prompts_dir = get_prompts_dir() prompt_path = os.path.join(prompts_dir, f"{prompt_name}.md") with open(prompt_path, 'w', encoding='utf-8') as f: f.write(content) ``` The corresponding deletion operation is: ```python user_prompts_dir = get_prompts_dir() user_prompt_path = os.path.join(user_prompts_dir, f"{name}.md") if os.path.exists(user_prompt_path): os.remove(user_prompt_path) ``` ### Technical Analysis The prompt name is supplied directly through the `get-prompt`, `set-prompt`, and `reset-prompt` CLI commands. It is concatenated with the `.md` suffix and passed to `os.path.join()` without validation. A value containing `../` components can escape the intended `~/.arxiv-search/prompts/` directory. An absolute path is also dangerous because `os.path.join()` discards its preceding directory when a later component is absolute. The `.md` suffix limits direct access to paths ending in that extension, but does not prevent access to sensitive Markdown files elsewhere on the filesystem. Existing symbolic links may also broaden the overwrite impact. ### Attack Pat ...[truncated 1270 chars]- Remediation
View remediation
