T09 · Insecure Skill Coding Practices
- Location
scripts/settle.sh:18- Finding
Unsafe JSON Construction Allows Settlement Request Manipulation
- Content
View full analysis
Vulnerability Details
File Location:
scripts/settle.sh:18-21
Vulnerability Type: Improper JSON escaping and structured-data injection
Risk Level: MediumVulnerable 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_AGENTvalue 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 --argto construct JSON safely, but this protection is absent from the settlement script.Attack Path
- An attacker supplies or convinces an operator or agent to use a crafted MoltCredit agent identifier.
- The identifier is passed as the first argument to
settle.sh. - The script inserts the value directly into the JSON request body without escaping it.
- The script attaches the victim's
MOLTCREDIT_API_KEYbearer token. - The manipulated request is submitted to the
/settleendpoint. - 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
View remediation
Remediation Suggestions
Construct the body using
jqso 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:
- Validate agent identifiers against the documented server-side format before sending the request.
- Reject control characters, unexpected delimiters, and identifiers exceeding a reasonable length.
- Require the server to reject unknown or duplicate JSON properties.
- Validate settlement parameters again on the server and require explicit confirmation before any irreversible payment action.
