T09 · Insecure Skill Coding Practices
- Location
readme-generator.sh:3- Finding
Unconditional File Overwrite Through Symlink-Following Redirection
- Content
View full analysis
Vulnerability Details
File Location:
readme-generator.sh, lines 3–8
Vulnerability Type: Unsafe file overwrite and symbolic-link following
Risk Level: MediumVulnerable Code
bash PROJECT_PATH=${1:-.} PROJECT_NAME=$(basename "$PROJECT_PATH") README_CONTENT="# $PROJECT_NAME\n\n## Description\n\nThis is a brief description of the project.\n\n## Installation\n\n\`\`\`bash\nnpm install\n# or\npip install -r requirements.txt\n\`\`\`\n\n## Usage\n\n\`\`\`bash\n# Example usage\n\`\`\`\n\n## License\n\nThis project is licensed under the MIT License.\n" echo -e "$README_CONTENT" > "$PROJECT_PATH/README.md"Technical Analysis
The output redirection unconditionally truncates and replaces
README.mdwithout checking whether the destination already exists or is a symbolic link. Standard shell redirection follows symbolic links. Consequently, ifREADME.mdpoints to another file writable by the invoking user, that target is truncated and replaced with the generated template.The project path is caller-controlled, but it is quoted correctly, so no command injection was identified. Exploitation instead depends on controlling the destination directory or its existing
README.mdentry. There is no evidence that this flaw enables privilege escalation beyond the permissions of the account running the script.Attack Path
- An attacker obtains write access to a project directory that a victim is likely to process.
- The attacker creates
README.mdas a symbolic link to another file writable by the victim. - The victim invokes the generator for that project directory.
- Shell redirection follows the symbolic link and truncates the linked target.
- The generated README content replaces the target file, potentially corrupting data or configuration.
A simpler accidental-loss scenario occurs when a legitimate
README.mdalready exists: running the script replaces it without warning or backup....[truncated 507 chars]
- Remediation
View remediation
Remediation Suggestions
- Refuse to overwrite an existing destination by default and require an explicit
--forceoption. - Reject symbolic-link destinations before writing, for example with
[[ -L "$destination" ]]. - Create the output in the destination directory using a securely created temporary file and atomically rename it after successful generation.
- Verify that the project path exists and is a directory.
- Avoid relying solely on a check followed by ordinary redirection where an untrusted party can modify the directory concurrently, because that introduces a time-of-check/time-of-use race.
- Preserve or back up existing content when replacement is explicitly requested.
- Refuse to overwrite an existing destination by default and require an explicit
