T09 · Insecure Skill Coding Practices
- Location
scripts/read-journal.sh:29- Finding
Path Traversal Allows Reading Markdown Files Outside the Journal Directory
- Content
View full analysis
- Remediation
View remediation
&2 exit 1 fi ``` Additionally: 1. Check that `--date` has a following value before reading `$2`. 2. Canonicalize both the journal directory and requested file using `realpath`. 3. Verify that the canonical file begins with the canonical journal-directory path. 4. Reject path separators, traversal components, and unexpected filename characters. 5. Continue quoting every path passed to filesystem commands. A defense-in-depth containment check could use: ```bash journal_root=$(realpath "$journal_dir") journal_file=$(realpath -m "${journal_dir}/${target_date}.md") case "$journal_file" in "${journal_root}/"*) ;; *) echo "Error: requested file is outside the journal directory" >&2 exit 1 ;; esac ``` ]]>
