T09 · Insecure Skill Coding Practices
- Location
scripts/save_full_snapshot.sh:23- Finding
Path Traversal Through Unsanitized Snapshot Topic
- Content
View full analysis
"$SNAPSHOT_FILE" <` redirection then creates or truncates the resolved `.md` file using the privileges of the account running the script. The timestamp prefix and forced `.md` suffix constrain the exact filename but do not prevent traversal into another directory. Existing symbolic links at a predicted destination can also redirect the write to another writable target. ### Attack Path 1. An attacker gains the ability to control the topic argument passed to `save_full_snapshot.sh`, such as through untrusted automation, a wrapper, or direct local invocation. 2. The attacker supplies a topic containing directory traversal components, for example: ```bash bash scripts/save_full_snapshot.sh "../../../../tmp/attacker-controlled" ``` 3. The script concatenates the unvalidated value with `VAULT_DIR` and the timestamp. 4. The operating system resolves the `../` components outside the configured Obsidian vault. 5. The `cat > "$SNAPSHOT_FILE"` operation creates or truncates the resulting `.md` file. 6. The script writes session metadata and conversation contents into that destination. If a predict ...[truncated 616 chars]- Remediation
View remediation
&2 exit 1 fi ``` 2. Explicitly reject `/`, `\`, control characters, and traversal components. 3. Create the vault directory and resolve its canonical path before writing: ```bash mkdir -p -- "$VAULT_DIR" VAULT_REAL=$(realpath -- "$VAULT_DIR") SNAPSHOT_FILE="$VAULT_REAL/$TIMESTAMP-$TOPIC.md" ``` 4. Verify that the canonical parent directory of the destination remains equal to the canonical vault directory. 5. Defend against symbolic-link attacks by refusing existing symlink destinations and, where possible, creating output files with no-follow and exclusive-creation semantics. 6. Run the script as a dedicated unprivileged user with write access only to the intended vault and tracking directories. ]]>
