T09 · Insecure Skill Coding Practices
- Location
bin/extract.sh:43- Finding
Unvalidated Output Format Permits Arbitrary File Truncation
- Content
View full analysis
"$OUTPUT_FILE" # clear ``` ### Technical Analysis The documented values for `output_format` are `json` and `csv`, but the script does not enforce this allowlist. Instead, it incorporates the caller-controlled value directly into a filesystem path and immediately truncates the resulting file through shell redirection. The later `case "$OUTPUT_FORMAT"` statement does not protect this operation because truncation occurs before the format is checked. Path separators and parent-directory components are therefore processed by the operating system. Because the fixed `transcripts.` prefix precedes the attacker-controlled value, straightforward traversal may require an attacker-accessible directory matching the resulting prefix component. For example, an attacker who can select `output_dir` and prepare directories beneath it can create the required prefix directory and use `../` components in `output_format` to resolve the constructed path outside the intended export directory. ### Attack Path 1. The attacker identifies a file writable by the account running the Skill. 2. The attacker creates an accessible output directory and any prefix directory required by the fixed `transcripts.` path component. 3. The attacker invokes the Skill with a crafted `output_format` containing path separators and parent-directory traversal components. 4. The assignment constructs a path outside the intended export location. 5. The command `> "$OUTPUT_FILE"` follows the resolved path and truncates the target before the script validates whether the requested format is supported. ### Impact Assessment Successful exploitation can truncat ...[truncated 358 chars]- Remediation
View remediation
&2 exit 2 ;; esac ``` Additionally: 1. Resolve `OUTPUT_DIR` to a canonical path. 2. Construct the destination using a fixed filename selected by the allowlist rather than concatenating raw input. 3. Resolve the final output path and verify that it remains beneath the approved output directory. 4. Refuse symlink destinations where appropriate. 5. Create output files with restrictive permissions, such as through `umask 077`. ]]>
