T09 · Insecure Skill Coding Practices
- Location
SKILL.md:19- Finding
API Credential Exposed in a Query String and Forwarded to a Configurable Destination
- Content
View full analysis
``` The associated configuration instructions obtain `BASE_URL` from the configurable `TSY_API_URL` value and obtain `SATOKEN` from `TSY_API_KEY`. ### Technical Analysis The Skill inserts the sensitive `TSY_API_KEY` value directly into the request URL as the `apikey` query parameter. Query strings are frequently recorded by HTTP clients, reverse proxies, gateways, monitoring platforms, access logs, error reports, and tool execution traces. Consequently, the credential can be exposed even when HTTPS protects the request while it is in transit. The credential's destination is also determined by the configurable `TSY_API_URL` value. The instructions do not require HTTPS, validate the destination origin, or restrict it to the expected `api.tangshiye.cn` host. A malicious or incorrectly configured value can therefore cause the Skill to transmit the API key to an unintended server. Authentication is necessary for the declared API operation, but embedding the credential in a URL and allowing its destination to be changed without validation exceed the minimum safe privileges required. ### Attack Path 1. An attacker, compromised deployment process, or unsafe configuration changes `TSY_API_URL` to an attacker-controlled endpoint. 2. The Skill independently reads the legitimate `TSY_API_KEY` from the global `.env` configuration. 3. It constructs a request to the configured endpoint with the secret embedded in `?apikey={SATOKEN}`. 4. The attacker-controlled server receives and records the API key. 5. Alternatively, without changing the destination, infrastructure that records complete URLs may capture the key from request or error logs ...[truncated 655 chars]- Remediation
View remediation
``` If the backend requires a different header format, use a dedicated secret header rather than a query parameter. 2. Require the destination to use HTTPS and reject plaintext HTTP URLs. 3. Restrict requests to an explicit allowlist containing the expected origin, such as: ```text https://api.tangshiye.cn ``` 4. If custom API origins are a legitimate requirement, require explicit user approval before sending credentials to an origin other than the trusted default. Never automatically forward a production credential across origins. 5. Validate the parsed URL rather than relying on string-prefix checks. Confirm the scheme, normalized hostname, port, and expected path. 6. Ensure that request diagnostics, WebFetch traces, proxy logs, and error messages redact authorization values. 7. Scope the API key to only the `findTopic` operation where supported, apply rate limits, establish expiration and rotation procedures, and revoke any key that may already have appeared in URL logs. ]]>
