T09 · Insecure Skill Coding Practices
- Location
scripts/_common.sh:5- Finding
Environment-Controlled API Base URL Enables Credential Exfiltration
- Content
View full analysis
&2; exit 3; } ``` Each command places the API credential in the query string. For example, `scripts/data.sh` contains: ```bash qs="method=getList" qs+="&apiKey=$(urlencode "$KOSIS_API_KEY")" qs+="&orgId=$(urlencode "$org_id")" qs+="&tblId=$(urlencode "$tbl_id")" ``` The bulk endpoint additionally transmits a saved-slice identifier in `scripts/bulk.sh`: ```bash qs="method=getList" qs+="&apiKey=$(urlencode "$KOSIS_API_KEY")" qs+="&userStatsId=$(urlencode "$user_stats_id")" ``` ### Technical Analysis Sending the KOSIS API key to the official KOSIS API is necessary for the declared functionality. However, the shared request helper permits the inherited `KOSIS_BASE` environment variable to replace the official destination without validating its scheme, hostname, port, or path. As a result, all commands trust ambient process configuration to determine where credential-bearing requests are sent. This exceeds the minimum privileges necessary for a KOSIS-only client: production operations require network access to the official KOSIS HTTPS origin, not arbitrary network destinations. Because the API key is included in the URL query string, invocation of any command sends it to the configured destination. Depending on the command, the request can also disclose s ...[truncated 2288 chars]- Remediation
View remediation
&2 exit 2 fi ``` Validation should reject non-HTTPS schemes, user-information components, unexpected ports, alternate hostnames, and hostnames that merely contain `kosis.kr` as a suffix or substring. 3. **Separate test configuration from production credentials.** Never allow a real `KOSIS_API_KEY` to be used with a test or custom endpoint. Require a dedicated test credential and an explicit opt-in flag when using a mock server. 4. **Avoid URL-based credentials where supported.** If the KOSIS API supports an authorization header, transmit the key in that header instead of the query string. If query authentication is mandatory, document the residual exposure and ensure scripts do not enable shell tracing or log complete request URLs. 5. **Apply network egress restrictions.** Where the runtime supports them, restrict this skill to HTTPS connections to `kosis.kr` so that environment manipulation cannot redirect credentials to another origin. 6. **Add regression tests.** Verify that custom schemes, hosts, ports, user-information components, and malformed URLs are rejected before `curl` is invoked. ]]>
