T09 · Insecure Skill Coding Practices
Warning
- Location
- index.js:31
- Finding
- Unvalidated CLI Input Allows API Route and Query Manipulation<![CDATA[ ## Vulnerability Details **File Location**: `index.js`, lines 31–37 **Vulnerability Type**: Improper validation and encoding of user-controlled URL path segments **Risk Level**: Medium ### Vulnerable Code ```js const cmd = args[0]; const input = args.slice(1).join(' '); const endpoint = cmd === 'positions' ? `/agent/v1/defi/positions/${input}` : cmd === 'optimize' ? `/agent/v1/defi/optimize/${input}` : cmd === 'yields' ? '/agent/v1/defi/yields' : cmd === 'rebalance' ? `/agent/v1/defi/rebalance/${input}` : cmd === 'il' ? `/agent/v1/defi/il/${input}` : null; if (!endpoint) { console.log('Unknown command. Run without arguments for help.'); return; } const res = await api(endpoint); ``` ### Technical Analysis The CLI concatenates the user-supplied wallet or position value directly into an API URL path. The value is not validated against the expected wallet or position identifier format and is not encoded with `encodeURIComponent`. Consequently, reserved URL characters and path components contained in the input may affect the request structure rather than being interpreted as part of a single identifier. For example: - `?` can introduce or replace the query string. - `#` can truncate the portion of the URL transmitted to the server. - `..` path segments may be normalized and alter the requested route. - `/` can inject additional path segments. The affected operation remains an HTTPS GET request to the configured API origin. This issue does not directly permit shell command execution or local privilege escalation. However, it can cause the client to access an API route different from the route implied by the selected CLI command. ### Attack Path 1. An attacker convinces a user or automated agent to invoke a wallet- or position-based command with a crafted identifier. 2. The identifier contains reserved URL characters or traversal-like path segments, such as `../../other-route?opti ...[truncated 1031 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Validate every wallet address against the exact supported blockchain format before constructing a request. For Base/EVM addresses, require a value matching an appropriate strict format, such as a 20-byte hexadecimal address with a `0x` prefix. 2. Define and enforce a strict allowlist format for position identifiers. 3. Encode each dynamic path segment independently: ```js const encodedInput = encodeURIComponent(input); const endpoint = `/agent/v1/defi/positions/${encodedInput}`; ``` 4. Construct requests with the WHATWG `URL` API rather than string concatenation: ```js const url = new URL(API); url.pathname = `/agent/v1/defi/positions/${encodeURIComponent(input)}`; ``` 5. Reject input containing unexpected separators, control characters, query delimiters, fragments, or path traversal components. 6. Before any x402 payment approval, verify that the final normalized URL still matches the exact endpoint selected by the CLI command. ]]>
