T09 · Insecure Skill Coding Practices
- Location
scripts/script.sh:9- Finding
Lead PII Stored with Unsafe Default File Permissions
- Content
View full analysis
Vulnerability Details
File Location:
scripts/script.sh, lines 9–16 and 100–101
Vulnerability Type: Sensitive data exposure through insecure filesystem permissions
Risk Level: MediumVulnerable Code
bash DATA_DIR="${HOME}/.leads" LEADS_FILE="${DATA_DIR}/leads.json" ensure_data_dir() { mkdir -p "${DATA_DIR}" [[ -f "${LEADS_FILE}" ]] || echo '[]' > "${LEADS_FILE}" }The file is subsequently populated without enforcing restrictive permissions:
python with open(leads_file, 'w') as f: json.dump(data, f, ensure_ascii=False, indent=2)Technical Analysis
The application stores names, email addresses, companies, lead statuses, follow-up notes, scores, and deal values in
~/.leads/leads.json. Neither the data directory nor the JSON file is assigned explicit restrictive permissions.Filesystem permissions therefore depend on the invoking user's
umask. With a commonumaskof022,mkdirmay create~/.leadswith mode0755, while shell redirection may createleads.jsonwith mode0644. On a multi-user system, these modes permit other local users to traverse the directory and read the CRM database.The later Python writes truncate and rewrite the existing file but do not correct its permissions. This can preserve an initially permissive mode throughout the file's lifetime.
Attack Path
- A legitimate user invokes a command such as:
bash bash scripts/script.sh add "Alice Smith" "alice@example.com" "Example Corp" "website" ensure_data_dircreates~/.leadsand~/.leads/leads.jsonusing permissions derived from the user'sumask.- Under a permissive or common
umask, the directory and database become accessible to other local accounts. - The Skill writes customer PII and commercially sensitive data into the JSON file.
- Another local user reads the database directly:
bash cat /home/victim/.leads/leads.json - The attacker obtains all CRM records stored by tha ...[truncated 674 chars]
- A legitimate user invokes a command such as:
- Remediation
View remediation
Remediation Suggestions
-
Set a restrictive process umask before creating or writing CRM data:
bash umask 077 -
Create the data directory with owner-only permissions and correct permissions on an existing directory:
bash mkdir -p -m 700 "${DATA_DIR}" chmod 700 "${DATA_DIR}" -
Create and enforce owner-only permissions on the database:
bash if [[ ! -f "${LEADS_FILE}" ]]; then printf '%s\n' '[]' > "${LEADS_FILE}" fi chmod 600 "${LEADS_FILE}" -
Write updates atomically to a temporary file created inside the protected directory with mode
0600, flush the data, and replace the destination withos.replace(). This reduces the risk of partial or corrupted writes while preserving restrictive access. -
Before every read or write, verify that the database is a regular file owned by the current user and is not a symbolic link. Reject unsafe ownership, file types, or permissions rather than silently operating on them.
-
If the CRM data is especially sensitive, consider encryption at rest with keys stored separately in an operating-system credential facility.
-
