T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/settle.sh:18
- Finding
- Unsafe JSON Construction Allows Settlement Request Manipulation## Vulnerability Details **File Location**: `scripts/settle.sh:18-21` **Vulnerability Type**: Improper JSON escaping and structured-data injection **Risk Level**: Medium ### Vulnerable Code ```bash curl -s -X POST "$API_URL/settle" \ -H "Authorization: Bearer $MOLTCREDIT_API_KEY" \ -H "Content-Type: application/json" \ -d "{\"with\": \"$WITH_AGENT\"}" | jq . ``` ### Technical Analysis The script interpolates the user-controlled `WITH_AGENT` value directly into a JSON string. Although shell quoting prevents ordinary shell command injection, it does not escape JSON metacharacters. An input containing quotation marks, backslashes, or additional JSON syntax can terminate the intended string and change the structure of the authenticated request. For example, a crafted value could create duplicate properties, inject additional properties, or make the body malformed. The exact result of duplicate-property injection depends on how the remote API parses JSON and validates settlement requests. Other project scripts use `jq -n --arg` to construct JSON safely, but this protection is absent from the settlement script. ### Attack Path 1. An attacker supplies or convinces an operator or agent to use a crafted MoltCredit agent identifier. 2. The identifier is passed as the first argument to `settle.sh`. 3. The script inserts the value directly into the JSON request body without escaping it. 4. The script attaches the victim's `MOLTCREDIT_API_KEY` bearer token. 5. The manipulated request is submitted to the `/settle` endpoint. 6. If the server accepts the injected structure or resolves duplicate fields unsafely, settlement generation may be performed with attacker-controlled parameters. ### Impact Assessment Exploitation occurs with the privileges associated with the victim's MoltCredit API key. A successful attack could manipulate the parameters of an authenticated settlement-generation request or cause repeated malf ...[truncated 238 chars]
- Remediation
- ## Remediation Suggestions Construct the body using `jq` so that the identifier is encoded as a JSON string rather than interpreted as JSON syntax: ```bash PAYLOAD=$(jq -n \ --arg with "$WITH_AGENT" \ '{with: $with}') curl --fail-with-body -sS -X POST "$API_URL/settle" \ -H "Authorization: Bearer $MOLTCREDIT_API_KEY" \ -H "Content-Type: application/json" \ -d "$PAYLOAD" | jq . ``` In addition: 1. Validate agent identifiers against the documented server-side format before sending the request. 2. Reject control characters, unexpected delimiters, and identifiers exceeding a reasonable length. 3. Require the server to reject unknown or duplicate JSON properties. 4. Validate settlement parameters again on the server and require explicit confirmation before any irreversible payment action.
