T09 · Insecure Skill Coding Practices
Error
- Location
- bin/run.mjs:164
- Finding
- API Credential Exposed Through Command-Line Arguments and URL Query Parameters<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md:43-51`; `bin/run.mjs:87-109, 164-167, 196-206, 239-260` **Vulnerability Type**: API credential exposure **Risk Level**: High The Skill requires an API token for its declared functionality, but handles that credential through two exposure-prone channels: a command-line argument and an HTTPS URL query parameter. ### Vulnerable Code `SKILL.md:43-51`: ```bash node {baseDir}/bin/run.mjs --operation "titleUserReviewsSummaryQuery" --token "$JUST_ONE_API_TOKEN" --params-json '{"id":"<id>"}' ``` ```markdown - Required: `JUST_ONE_API_TOKEN` - Pass the token with `--token "$JUST_ONE_API_TOKEN"`; do not paste token values into chat messages, screenshots, or logs. ``` `bin/run.mjs:164-167`: ```js if (flag === "--token") { parsed.token = value; index += 1; continue; } ``` `bin/run.mjs:196-206`: ```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:239-260`: ```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)); } ``` `bin/run.mjs:87-109`: ```js injectToken(operation, params, args.tok ...[truncated 3261 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. **Remove command-line token handling** - Read the secret directly from `process.env.JUST_ONE_API_TOKEN`. - Remove the `--token` parser branch and avoid accepting credentials through `--params-json`. - Fail safely when the environment variable is absent, without printing its value. 2. **Prefer header-based authentication** - If JustOneAPI supports it, transmit the credential using an authorization header, such as: ```js const token = process.env.JUST_ONE_API_TOKEN; const requestInit = { method: operation.method, headers: { accept: "application/json", authorization: `Bearer ${token}`, }, }; ``` - Confirm the exact authentication scheme with the provider rather than assuming the bearer format. 3. **Harden mandatory query-token authentication** - If the upstream service only accepts a query token, document this residual risk explicitly. - Configure gateways, proxies, application logs, monitoring systems, and error trackers to redact the `token` query parameter. - Never include the complete request URL in error output or diagnostics. - Set a restrictive referrer policy where browser-based use is possible. - Use short-lived, narrowly scoped tokens and rotate them regularly. 4. **Prevent alternate token injection** - Reject `token` inside `--params-json`; otherwise callers can bypass the intended secret-loading mechanism because `injectToken()` preserves an existing `params.token`. - Maintain an allowlist containing only the documented user inputs, such as `id` and `languageCountry`. 5. **Update documentation** - Replace the documented `--token` invocation with an environment-only invocation: ```bash JUST_ONE_API_TOKEN="..." node {baseDir}/bin/run.mjs \ --operation "titleUserReviewsSummaryQuery" \ --params-json '{"id":"<id>"}' ``` - Warn users that query-string authentication may be logged by net ...[truncated 51 chars]
