T09 · Insecure Skill Coding Practices
- Location
scripts/feishu-calendar.sh:24- Finding
Tenant access token stored in an insecure predictable temporary file
- Content
View full analysis
&2 exit 1 fi expire_at=$(( $(date +%s) + 7000 )) echo "{\"token\":\"$token\",\"expire\":$expire_at}" > "$TOKEN_CACHE" echo "$token" } ``` ### Technical Analysis The script stores a Feishu tenant bearer token in the fixed path `/tmp/feishu_token_cache`. The shared temporary directory is accessible to multiple local users, and the script does not: - Set a restrictive `umask`. - Explicitly create the cache with mode `0600`. - Verify that the cache is owned by the current user. - Reject symbolic links or other unexpected file types. - Separate cache files by user, application, or tenant. - Create or replace the cache atomically. With a common `umask` of `022`, a newly created cache can be readable by other local users. Because the path is predictable, an attacker can monitor it and retrieve the bearer token while it remains valid. On systems without effective temporary-directory symlink protections, pre-creating the path as a symbolic link may also redirect the write to another file writable by the victim process. The script also trusts any unexpired JSON object al ...[truncated 1777 chars]- Remediation
View remediation
"$tmp_cache" mv -f "$tmp_cache" "$TOKEN_CACHE" ``` Ownership and file-type checks should still be performed before reading an existing cache. ]]>
