T09 · Insecure Skill Coding Practices
- Location
scripts/obsidian_cli.py:196- Finding
Vault Boundary Escape Through Unvalidated Folder Path
- Content
View full analysis
Path: """Create a new note.""" if auto_folder and not folder: folder = suggest_folder(vault, content, title) # Determine path if folder: note_dir = vault / folder note_dir.mkdir(parents=True, exist_ok=True) else: note_dir = vault # Sanitize filename safe_title = re.sub(r'[<>:"/\\|?*]', '', title) note_path = note_dir / f"{safe_title}.md" # Build frontmatter fm = { 'created': datetime.now().isoformat(), } if tags: fm['tags'] = tags full_content = format_frontmatter(fm) + content note_path.write_text(full_content, encoding='utf-8') ``` ### Technical Analysis The `folder` argument is user-controlled and is joined directly to the configured vault path without normalization or containment validation. Sanitizing only the note title does not protect the directory component. A relative value containing parent-directory components, such as `../../target`, causes the destination to resolve outside the vault. A supplied absolute path can also override the vault prefix under `pathlib` path-joining semantics. The function subsequently creates directories with `mkdir()` and writes content with `write_text()`. Because `write_text()` overwrites an existing file by default, an attacker can create or replace `.md` files anywhere writable by the process. The vulnerability does not bypass operating-system permissions, but it violates the application's intended vault boundary and grants filesystem-write scope beyond the legitimate note-management task. ### Attack Path 1. An attacker supplies or induces an agent to use a crafted fold ...[truncated 1300 chars]- Remediation
View remediation
Path: vault_resolved = vault.resolve() if not folder: return vault_resolved supplied = Path(folder) if supplied.is_absolute(): raise ValueError("Absolute folder paths are not allowed") destination = (vault_resolved / supplied).resolve() if not destination.is_relative_to(vault_resolved): raise ValueError("Folder must remain inside the configured vault") return destination ``` Use the validated path and prevent implicit overwrites: ```python note_dir = resolve_inside_vault(vault, folder) note_dir.mkdir(parents=True, exist_ok=True) note_path = (note_dir / f"{safe_title}.md").resolve() if not note_path.is_relative_to(vault.resolve()): raise ValueError("Note path escapes the configured vault") with note_path.open("x", encoding="utf-8") as output: output.write(full_content) ``` If overwriting is required, expose a deliberate `--overwrite` option and require explicit authorization. Where untrusted users can modify the vault, also account for symlink races by using platform-appropriate secure file-opening controls and running the skill under a minimally privileged account. ]]>
