T09 · Insecure Skill Coding Practices
Warning
- Location
- bin/run.mjs:183
- Finding
- API Token Exposed Through Command-Line Arguments and URL Query Parameters<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md:42-50`, `bin/run.mjs:183-195`, `bin/run.mjs:231-249`, `generated/operations.json:17-25`, and `generated/operations.md:19-23` **Vulnerability Type**: Credential exposure through process arguments and URL query parameters **Risk Level**: Medium ### Vulnerable Code The documented invocation passes the secret as a command-line argument: ```bash node {baseDir}/bin/run.mjs --operation "searchKuaishouVideoV2" --token "$JUST_ONE_API_TOKEN" --params-json '{"keyword":"<keyword>"}' ``` The implementation accepts that command-line token and adds it to the parameter object: ```js function injectToken(operation, params, cliToken) { const tokenParam = operation.parameters.find((parameter) => parameter.name === "token"); if (!tokenParam || params.token !== undefined) { return; } if (!cliToken) { fail("--token is required for this operation.", { operationId: operation.operationId, }); } params.token = cliToken; } ``` Every parameter declared as a query parameter, including `token`, is then appended to the URL: ```js function applyQueryParams(operation, params, url) { for (const parameter of operation.parameters.filter((item) => item.location === "query")) { const value = params[parameter.name]; if (value === undefined) { continue; } appendValue(url.searchParams, parameter.name, value); } } function appendValue(searchParams, name, value) { if (Array.isArray(value)) { for (const item of value) { appendValue(searchParams, name, item); } return; } if (value && typeof value === "object") { searchParams.append(name, JSON.stringify(value)); return; } searchParams.append(name, String(value)); } ``` The generated operation manifest explicitly classifies the access token as a query parameter: ```json { "defaultValue": null, "description": "Access token for this API service.", "enumValues": [], "location": "query", " ...[truncated 2938 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. **Use authorization headers where supported** - Change the API contract to accept the credential through an `Authorization` header, such as: ```js const requestInit = { method: operation.method, headers: { accept: "application/json", authorization: `Bearer ${token}`, }, }; ``` - Remove `token` from `operation.parameters` so it cannot be appended to the URL. 2. **Read credentials directly from the environment** - Replace the `--token` interface with direct access to `process.env.JUST_ONE_API_TOKEN`. - Fail safely when the environment variable is absent. - Do not include the token value in validation errors or diagnostic output. 3. **If query-based authentication is mandated by the upstream API** - Continue using HTTPS, but document that query-string authentication is an upstream constraint. - Configure clients, proxies, gateways, access logs, and observability tools to remove or redact the `token` parameter. - Never log the constructed `URL` object or complete request URL. - Read the token from the environment rather than exposing it through process arguments. - Use narrowly scoped, short-lived tokens where the service supports them. - Rotate and revoke tokens suspected of appearing in historical process telemetry or URL logs. 4. **Harden documentation and generated artifacts** - Replace the documented `--token "$JUST_ONE_API_TOKEN"` command with an environment-only invocation. - Update `generated/operations.json` and `generated/operations.md` if header authentication becomes available. - Explicitly warn operators to redact query parameters from infrastructure logs if the upstream endpoint cannot be changed. 5. **Add regression controls** - Add tests confirming that credentials never appear in command-line examples, standard output, standard error, or logged URLs. - Add secret-redaction checks for request diagnostics ...[truncated 31 chars]
