T09 · Insecure Skill Coding Practices
- Location
scripts/script.sh:5- Finding
Potentially Sensitive Mental-Health Data Stored in Plaintext with Inherited Permissions
- Content
View full analysis
Vulnerability Details
File Location:
scripts/script.sh, lines 5-34
Vulnerability Type: Insecure local storage of potentially sensitive data
Risk Level: MediumVulnerable Code
bash DATA_DIR="${MENTAL_HEALTH_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/mental-health}" DB="$DATA_DIR/data.log" mkdir -p "$DATA_DIR" show_help() { cat << EOF mental-health v$VERSION Health and wellness tracker Usage: mental-health <command> [args] Commands: log Log entry today Today summary streak Current streak stats Statistics reminder Set reminder tips Health tips goal Set goal history View history export Export data reset Reset tracker help Show this help version Show version Data: \$DATA_DIR EOF } _log() { echo "$(date '+%m-%d %H:%M') $1: $2" >> "$DATA_DIR/history.log"; } cmd_log() { echo "$(date +%Y-%m-%d) $*" >> "$DB"; echo " Logged: $*" _log "log" "${1:-}" }Technical Analysis
The
logcommand writes arbitrary user-provided wellness or mental-health entries directly todata.log. It also records activity information inhistory.log. These records are stored as unencrypted plaintext.The script creates the storage directory with
mkdir -pand creates the log files through shell redirection, but it does not establish a restrictive umask or explicitly apply secure filesystem permissions. Consequently, directory and file permissions are inherited from the invoking process's umask and the permissions of parent directories. Under a permissive configuration, the files may be created with modes such as0644, allowing other local users to read their contents.Because users may place private emotional, medical, or wellness informati ...[truncated 1631 chars]
- Remediation
View remediation
Remediation Suggestions
-
Establish a restrictive umask before creating any data:
bash umask 077 -
Create the storage directory with owner-only permissions and verify its final mode:
bash mkdir -p -- "$DATA_DIR" chmod 700 -- "$DATA_DIR" -
Secure both files after creation:
bash touch -- "$DB" "$DATA_DIR/history.log" chmod 600 -- "$DB" "$DATA_DIR/history.log" -
Reject unsafe storage locations or symlinked files where practical. Resolve and validate a user-supplied
MENTAL_HEALTH_DIRbefore writing, and avoid following pre-existing symbolic links when opening sensitive files. -
Clearly disclose that log entries are persisted locally in plaintext, including the exact location and retention behavior.
-
Implement the documented reset operation so users can securely remove their records. The current
resetcommand only prints instructions and does not delete data. -
If the threat model includes privileged administrators, device theft, or offline disk access, use operating-system credential storage or authenticated encryption rather than relying only on file permissions.
-
