T09 · Insecure Skill Coding Practices
Warning
- Location
- bin/run.mjs:23
- Finding
- API Token Exposed Through Command-Line Arguments and URL Query Parameters<![CDATA[ ## Vulnerability Details **File Location**: `bin/run.mjs:23-31, 71-72, 89, 148-151, 224-234`; `SKILL.md:39, 45`; `generated/operations.json:17-25`; `generated/operations.md:20` **Vulnerability Type**: Credential exposure through process arguments and URL query strings **Risk Level**: Medium ### Complete Vulnerable Code Snippets The operation defines the API token as a query parameter: ```js { "defaultValue": null, "description": "API access token.", "enumValues": [], "location": "query", "name": "token", "required": true, "schemaType": "string" } ``` The token is injected into the parameter collection: ```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; } ``` All query parameters, including the token, are appended to the URL before transmission: ```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); } } ``` The resulting URL is sent to the declared remote API: ```js applyQueryParams(operation, params, url); const requestInit = { headers: { "accept": "application/json", }, method: operation.method, }; response = await fetch(url, requestInit); ``` The documented invocation also expands the secret into a command-line argument: ```bash node {baseDir}/bin/run.mjs --operation "getWeiboDetailsV1" --token "$JUST_ONE_API_TOKEN" --params-json '{"id":"<id>"}' ``` ### Technical Analysis The Skill legitimately requires authentication to call `https://api.justoneapi.c ...[truncated 3278 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. **Prefer authorization headers** - Change the API contract, where supported, to accept an `Authorization` header rather than a query parameter. - For example: ```js const token = process.env.JUST_ONE_API_TOKEN; if (!token) { fail("JUST_ONE_API_TOKEN is required."); } const requestInit = { method: operation.method, headers: { accept: "application/json", authorization: `Bearer ${token}`, }, }; ``` 2. **Read the credential directly from the environment** - Remove the documented `--token` argument. - Read `process.env.JUST_ONE_API_TOKEN` inside the process so the credential is not placed in the command-line argument vector. - Do not accept `token` through `--params-json`, because that would still expose it through process arguments. 3. **Remove token query serialization** - Mark the credential as a header-based authentication value rather than a normal operation parameter. - Ensure `applyQueryParams()` cannot append credentials or other sensitive fields to URLs. 4. **Apply compensating controls if query authentication is an unavoidable upstream requirement** - Continue using HTTPS. - Configure the API server, gateways, reverse proxies, tracing tools, and access logs to redact or omit the `token` query parameter. - Avoid logging complete request URLs. - Use short-lived, narrowly scoped tokens with quota and billing limits. - Rotate the token promptly after suspected disclosure. - Review redirect behavior and prevent credentials from being forwarded to an unintended destination. 5. **Add regression tests** - Verify that the token is absent from `process.argv`. - Verify that generated request URLs do not contain `token`. - Verify that error output and diagnostic logs never include the credential. ]]>
