T09 · Insecure Skill Coding Practices
- Location
scripts/script.sh:6- Finding
Local Log Data Is Created Without Enforced Private Permissions or Symlink Protection
- Content
View full analysis
Vulnerability Details
File Location:
scripts/script.sh:6-9; repeated log writes atscripts/script.sh:123-137,138-152,153-167,168-182,183-197,198-212,213-227,228-242,243-257,258-272,273-287, and288-302
Vulnerability Type: Insecure local file permissions and unsafe file handling
Risk Level: MediumVulnerable Code
bash DATA_DIR="${HOME}/.local/share/tire" mkdir -p "$DATA_DIR" _log() { echo "$(date '+%m-%d %H:%M') $1: $2" >> "$DATA_DIR/history.log"; }Representative command handler:
bash run) shift if [ $# -eq 0 ]; then echo "Recent run entries:" tail -20 "$DATA_DIR/run.log" 2>/dev/null || echo " No entries yet. Use: tire run <input>" else local input="$*" local ts=$(date '+%Y-%m-%d %H:%M') echo "$ts|$input" >> "$DATA_DIR/run.log" local total=$(wc -l < "$DATA_DIR/run.log") echo " [Tire] run: $input" echo " Saved. Total run entries: $total" _log "run" "$input" fi ;;The same append pattern is used for the other input-taking commands.
Technical Analysis
The script stores all supplied command input under
~/.local/share/tire, but it does not establish a restrictive umask, enforce mode0700on the data directory, or enforce mode0600on log files. Under a common default umask of022, the directory can be created as0755and log files as0644. On a multi-user system where home-directory traversal is permitted, other local users may therefore read recorded inputs.The log files are also opened using ordinary append redirection without checking whether the destination is a symbolic link or a regular file. If an attacker can write to the data directory—for example, because it was previously created with overly permissive ownership or permissions—the attacker can replace a log path with a symbolic link. A subsequent inv ...[truncated 1852 chars]
- Remediation
View remediation
Remediation Suggestions
-
Set a restrictive umask before creating any persistent state:
bash umask 077 -
Create and validate the data directory with owner-only permissions:
bash DATA_DIR="${HOME}/.local/share/tire" mkdir -p -- "$DATA_DIR" chmod 700 -- "$DATA_DIR" if [[ -L "$DATA_DIR" || ! -d "$DATA_DIR" || ! -O "$DATA_DIR" ]]; then printf 'Unsafe data directory: %s\n' "$DATA_DIR" >&2 exit 1 fi -
Before writing, reject symbolic links and non-regular existing files:
bash ensure_safe_log() { local file="$1" if [[ -L "$file" ]]; then printf 'Refusing symbolic-link log: %s\n' "$file" >&2 return 1 fi if [[ -e "$file" && ( ! -f "$file" || ! -O "$file" ) ]]; then printf 'Refusing unsafe log file: %s\n' "$file" >&2 return 1 fi if [[ ! -e "$file" ]]; then (umask 077; : > "$file") fi chmod 600 -- "$file" } -
Apply the validation to every log destination, including
history.log, immediately before opening it. -
Avoid recording secrets by documenting that command input is persisted, offering a no-log mode, and redacting known sensitive fields where applicable.
-
For stronger protection against time-of-check/time-of-use races in hostile shared environments, perform file creation and append operations through a helper that uses
open()withO_NOFOLLOW, verifies ownership and regular-file status withfstat(), and sets mode0600.
-
