T09 · Insecure Skill Coding Practices
- Location
scripts/snapshot.sh:6- Finding
Predictable Shared Temporary Directory Enables Snapshot Disclosure and Manipulation
- Content
View full analysis
Vulnerability Details
File Location:
scripts/snapshot.sh:6-18; duplicated inSKILL.md:56-68
Vulnerability Type: Unsafe temporary-file and directory handling
Risk Level: MediumVulnerable Code
bash SNAP_DIR="/tmp/nova-snapshots" create_snapshot() { local desc="${1:-unnamed}" local target="${2:-.}" mkdir -p "$SNAP_DIR" local stamp=$(date +%s) local snap_path="$SNAP_DIR/${stamp}_${desc}" if [ -e "$target" ]; then cp -r "$target" "$snap_path" 2>/dev/null echo "[$(date '+%H:%M:%S')] snapshot created: $snap_path" # Keep the last three snapshots ls -dt "$SNAP_DIR"/*/ 2>/dev/null | tail -n +4 | xargs rm -rf 2>/dev/nullThe corresponding implementation documented in
SKILL.mdis:bash nova-snapshot() { local desc="${1:- unnamed}" local target="${2:-.}" local snap_dir="/tmp/nova-snapshots" mkdir -p "$snap_dir" local stamp=$(date +%s) local snap_path="$snap_dir/${stamp}_${desc}" if [ -e "$target" ]; then cp -r "$target" "$snap_path" 2>/dev/null echo "[$(date '+%H:%M:%S')] snapshot: $snap_path" # Keep the last three snapshots ls -dt "$snap_dir"/*/ 2>/dev/null | tail -n +4 | xargs rm -rf 2>/dev/null fi }Technical Analysis
The snapshot implementation stores copies in the fixed, globally predictable path
/tmp/nova-snapshots. It creates that path withmkdir -pbut does not verify that it is a genuine directory owned by the current user, reject symbolic links, or set restrictive permissions.Snapshot names are based on second-resolution timestamps and a caller-provided description. The implementation does not validate the description or create the destination atomically. A local attacker able to monitor or predict invocation parameters may pre-create the directory or destination entr ...[truncated 1883 chars]
- Remediation
View remediation
Remediation Suggestions
- Create a private snapshot root with
mktemp -dor use a per-user state directory rather than a shared fixed path. - Set a restrictive
umask, such asumask 077, and enforce directory mode0700. - Before every operation, use
lstat-equivalent checks to reject symbolic links and verify that the snapshot root is a directory owned by the invoking user. - Create each snapshot destination atomically with
mktemp -dinstead of using a second-resolution timestamp. - Restrict descriptions to a safe character set, such as
[A-Za-z0-9._-], and reject path separators and control characters. - Check the exit status of
mkdirandcp; do not print a success message if either operation fails. - Replace the
ls | tail | xargs rm -rfpipeline with controlled iteration over validated entries beneath the verified snapshot root. - Apply the same corrected implementation to the example in
SKILL.mdso users are not instructed to reproduce the vulnerability.
- Create a private snapshot root with
