T09 · Insecure Skill Coding Practices
- Location
scripts/script.sh:5- Finding
Permissive File Permissions May Expose Sensitive Financial Records
- Content
View full analysis
Vulnerability Details
File Location:
scripts/script.sh, lines 5-7, 30, and 54
Vulnerability Type: Sensitive data exposure through insecure default file permissions
Risk Level: MediumVulnerable Code
bash DATA_DIR="${CASHFLOW_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/cashflow}" DB="$DATA_DIR/data.log" mkdir -p "$DATA_DIR"bash _log() { echo "$(date '+%m-%d %H:%M') $1: $2" >> "$DATA_DIR/history.log"; }bash cmd_add() { echo "$(date +%Y-%m-%d) $*" >> "$DB"; echo " Added: $*" _log "add" "${1:-}" }Technical Analysis
The script stores potentially sensitive personal financial information in
data.logand command details inhistory.log, but it does not establish a restrictiveumaskor explicitly set permissions on the storage directory and files.Consequently, permissions are inherited from the invoking process. With a common
umaskof022,mkdir -ptypically creates the directory with mode0755, while shell redirection creates log files with mode0644. On a multi-user system, these modes may allow other local accounts to traverse the data directory and read both logs.The exposure depends on the effective permissions of parent directories and the process
umask. It is therefore not guaranteed on every installation, but the script does not enforce the confidentiality expected for financial records.Attack Path
- A user invokes
cashflow addand records an expense, income item, balance, or private note. - The script creates the data directory and log files using the caller's default
umask. - Under permissive defaults, the resulting directory and files are readable by other local users.
- Another local account accesses
data.logorhistory.log. - The account obtains the stored financial entries, command arguments, or search terms without authorization.
The attacker must already possess local access and sufficient traversal permissions for the relevant parent directories. This ...[truncated 589 chars]
- A user invokes
- Remediation
View remediation
Remediation Suggestions
- Set a restrictive file-creation mask before creating any storage:
bash umask 077- Create and enforce owner-only permissions on the data directory:
bash mkdir -p -- "$DATA_DIR" chmod 700 -- "$DATA_DIR"- Secure existing and newly created log files:
bash touch -- "$DB" "$DATA_DIR/history.log" chmod 600 -- "$DB" "$DATA_DIR/history.log"-
Validate that
DATA_DIRis owned by the current user and reject unsafe locations, such as directories owned by another account or writable by group/others. -
Document that
CASHFLOW_DIRmust point to a private, user-owned directory. -
Consider using
printfinstead ofechofor predictable handling of user-supplied text:
bash printf '%s %s\n' "$(date +%Y-%m-%d)" "$*" >> "$DB" printf '%s %s: %s\n' "$(date '+%m-%d %H:%M')" "$1" "$2" >> "$DATA_DIR/history.log"
