T09 · Insecure Skill Coding Practices
Error
- Location
- references/code-examples/bria_auth.sh:40
- Finding
- Credential Files Are Created Without Restrictive Permissions<![CDATA[ ## Vulnerability Details **File Location**: `references/code-examples/bria_auth.sh`, lines 40–41 and 73–76 **Vulnerability Type**: Plaintext credentials stored with permissions inherited from the process umask **Risk Level**: High ### Vulnerable Code ```bash mkdir -p ~/.bria printf 'access_token=%s\nrefresh_token=%s\n' "$BRIA_ACCESS_TOKEN" "$REFRESH_TOKEN" > "$HOME/.bria/credentials" ``` The API token is subsequently written through another temporary file without explicitly setting its permissions: ```bash if [ -n "$BRIA_API_KEY" ]; then grep -v '^api_token=' "$HOME/.bria/credentials" > "$HOME/.bria/credentials.tmp" 2>/dev/null || true printf 'api_token=%s\n' "$BRIA_API_KEY" >> "$HOME/.bria/credentials.tmp" mv "$HOME/.bria/credentials.tmp" "$HOME/.bria/credentials" fi ``` ### Technical Analysis The helper stores OAuth access tokens, refresh tokens, and the Bria API token in a plaintext file under the user's home directory. Reading and caching Bria credentials is relevant to the declared functionality, but the implementation does not establish minimum required filesystem permissions. Neither `~/.bria` nor `~/.bria/credentials` is created with an explicit restrictive mode. Their permissions therefore depend on the invoking process's umask. For example, with a typical `022` umask, the directory may be created as `0755` and the credential file as `0644`, allowing other local users to read the tokens. The later `credentials.tmp` replacement has the same weakness. Because `mv` replaces the original file with the newly created temporary file, this operation can discard secure permissions that may previously have been applied to `credentials`. ### Attack Path 1. A user invokes `bria_auth` on a multi-user system while using a permissive umask. 2. The helper creates `~/.bria/credentials` without an explicit `0600` mode. 3. The file contains the user's OAuth access token and refresh token. 4. After introspection, the same file also contains the B ...[truncated 650 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Establish a restrictive umask before creating credential material: ```bash umask 077 ``` 2. Create the credential directory with an explicit mode: ```bash install -d -m 700 "$HOME/.bria" ``` 3. Create replacement files securely and enforce mode `0600`: ```bash credential_tmp=$(mktemp "$HOME/.bria/credentials.XXXXXX") || return 1 chmod 600 "$credential_tmp" || { rm -f "$credential_tmp" return 1 } ``` 4. Write all credential fields to the secure temporary file and atomically rename it into place. 5. Apply `chmod 600 "$HOME/.bria/credentials"` after replacement as defense in depth. 6. Install cleanup traps so temporary credential files are removed on interruption or failure. 7. Where supported, use an operating-system credential store instead of a plaintext file. 8. Document token revocation and rotation procedures for users who may already have created permissive credential files. ]]>
