T09 · Insecure Skill Coding Practices
- Location
scripts/move.sh:7- Finding
Unvalidated Destination Filename Allows File Overwrite and Path Manipulation
- Content
View full analysis
Vulnerability Details
File Location:
scripts/move.sh, lines 7–10 and 33–37
Vulnerability Type: Unvalidated path construction and unsafe file overwrite
Risk Level: MediumVulnerable Code
bash SOURCE="$1" TYPE="$2" DESC="$3" DATE="$4" EXT="${SOURCE##*.}" FILENAME="input-${DESC}-${DATE}.${EXT}" cp "$SOURCE" "$TARGET_DIR/$FILENAME"Technical Analysis
The destination filename is constructed directly from the attacker-controlled
DESCandDATEarguments and from an extension derived from the supplied source path. These values are not normalized or restricted to safe filename characters.Path separators, traversal components, control characters, and other special filename content are not rejected. If suitable intermediate directories already exist, crafted components can cause the resolved destination to differ from the expected single file directly beneath
TARGET_DIR.The script also invokes
cpwithout checking whether the destination already exists or is a symbolic link. By default, this can overwrite an existing destination file and can follow a destination symbolic link to another file writable by the account executing the script.Attack Path
- An attacker predicts the destination name generated from the description, date, and source extension.
- The attacker creates an existing file or symbolic link at that destination, or prepares intermediate directories that make crafted path components meaningful.
- The attacker invokes the script with the crafted arguments, or causes an automated agent to invoke it while processing attacker-controlled file metadata.
- The script constructs the destination without validating its canonical location.
cpfollows the resulting path and overwrites the existing destination or the writable target of a symbolic link.
Exploitation is limited by the filesystem permissions of the account running the script and by the attacker's ...[truncated 599 chars]
- Remediation
View remediation
Remediation Suggestions
- Restrict
DESCandDATEto an explicit allowlist:- Permit only ASCII letters, digits, hyphens, and underscores in descriptions.
- Require dates to match a strict format such as
^[0-9]{8}$. - Reject
/,\,.., control characters, and empty normalized values.
- Derive the extension from the source basename and validate it against the selected file category.
- Resolve and validate the final destination path, confirming that it remains directly beneath the expected
TARGET_DIR. - Reject existing destination files rather than overwriting them. Use collision-resistant names or a no-clobber operation.
- Check destination components with
lstator equivalent logic and reject symbolic links. - Enable strict shell error handling, such as
set -euo pipefail, and verify that the copy completed before reporting success.
- Restrict
