T09 · Insecure Skill Coding Practices
- Location
scripts/register.sh:31- Finding
Credential File Created Without Restrictive Permissions
- Content
View full analysis
~/.scrapyard/credentials.json << EOF { "botId": "$BOT_ID", "apiKey": "$API_KEY", "botName": "$NAME", "avatar": "$AVATAR" } EOF echo "✅ Bot registered successfully!" echo " Name: $NAME $AVATAR" echo " ID: $BOT_ID" echo " Credentials saved to ~/.scrapyard/credentials.json" ``` ### Technical Analysis The script stores a bearer API key in a plaintext JSON file but does not explicitly restrict permissions on either the containing directory or the credential file. Their permissions therefore depend on the invoking process's ambient `umask`. With a common `022` umask, `~/.scrapyard` may be created with mode `755` and `credentials.json` with mode `644`. On a multi-user system, this can allow other local accounts to traverse the directory and read the API key. Persisting the credential is necessary for the declared join and leave functionality, so access to this path does not exceed the functional scope by itself. The vulnerability is the failure to apply least-privilege filesystem permissions when storing the secret. ### Attack Path 1. The victim runs `scripts/register.sh` under a permissive `umask`, such as `022`. 2. The script creates `~/.scrapyard/credentials.json` without setting an explicit restrictive mode. 3. Another local account enumerates or directly reads the credential file. 4. The attacker extracts the `botId` and bearer `apiKey`. 5. The attacker submits authenticated requests to the documented SCRAPYARD endpoints using the stolen credentials. This path requires local filesystem access under an account permitted by the resulting file and directory modes. ### Impact Assessment A successful attacker can impersonate the registered SCRAPYARD bot within the privileges granted to its API key. Th ...[truncated 359 chars]- Remediation
View remediation
"$tmp_file" chmod 600 "$tmp_file" mv "$tmp_file" "$CREDS_FILE" ``` Additional hardening measures: - Verify that the credential directory is owned by the current user before writing into it. - Reject symbolic links and unexpected file types at the destination. - Use an atomic temporary-file-and-rename operation to avoid partially written credentials. - Use `jq --arg` rather than interpolating user and server values into JSON, ensuring quotes and control characters are escaped correctly. - Consider an operating-system credential store where available. - Document that the bearer key must not be shared and provide a revocation or rotation procedure. ]]>
