T09 · Insecure Skill Coding Practices
Warning
- Location
- bin/run.mjs:326
- Finding
- API Token Exposed Through Process Arguments and URL Query Parameters<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md:52-60`; `bin/run.mjs:326-334, 376-388` **Vulnerability Type**: Credential exposure through command-line arguments and URL query strings **Risk Level**: Medium ### Vulnerable Code `SKILL.md:52-60` instructs users to pass the API token as a command-line argument: ```markdown node {baseDir}/bin/run.mjs --operation "getTaobaoItemDetailV1" --token "$JUST_ONE_API_TOKEN" --params-json '{"itemId":"<itemId>"}' ``` `bin/run.mjs:326-334` copies that argument into the request 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; } ``` `bin/run.mjs:376-388` serializes all query parameters, including `token`, into the request 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 resulting URL, including the token, is transmitted at `bin/run.mjs:237`: ```js response = await fetch(url, requestInit); ``` ### Technical Analysis The token is exposed through two channels: 1. **Process argument exposure:** Passing a secret through `--token` places it in the process argument vec ...[truncated 3286 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. **Stop accepting secrets through command-line arguments** - Read the token directly from `process.env.JUST_ONE_API_TOKEN`. - Remove or deprecate `--token`. - If backward compatibility is required, emit a warning and prioritize the environment variable. Example: ```js const token = process.env.JUST_ONE_API_TOKEN; if (!token) { fail("JUST_ONE_API_TOKEN is required.", { operationId: operation.operationId, }); } params.token = token; ``` 2. **Use header-based authentication when supported** - Prefer an HTTP authorization header over a query parameter: ```js requestInit.headers.authorization = `Bearer ${token}`; ``` - Confirm the exact authentication scheme with the JustOneAPI specification before changing the request. - Remove `token` from `url.searchParams` once header authentication is supported. 3. **If query authentication is mandatory** - Document that this is an upstream API requirement. - Use narrowly scoped and short-lived tokens where the service supports them. - Configure the API server, reverse proxies, gateways, and observability tools to redact the `token` query parameter. - Never include the complete request URL in application errors, debug logs, telemetry, or exception reports. - Ensure redirects are disabled or carefully validated so query credentials cannot be forwarded to another origin. 4. **Harden input handling** - Reject `token` inside `--params-json` so secrets cannot be supplied through an alternate command-line argument. - Keep credential acquisition separate from ordinary endpoint parameters. 5. **Update documentation** - Replace the documented invocation with one that relies on the environment variable: ```bash JUST_ONE_API_TOKEN="$JUST_ONE_API_TOKEN" node {baseDir}/bin/run.mjs \ --operation "getTaobaoItemDetailV1" \ --params-json '{"itemId":"<itemId>"}' ``` 6. **Operational safeguards** ...[truncated 212 chars]
