T09 · Insecure Skill Coding Practices
Warning
- Location
- bin/run.mjs:187
- Finding
- API Token Exposed Through Process Arguments and URL Query Parameters<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md:42,50`; `bin/run.mjs:22,81-100,149-159,187-198,230-237`; `generated/operations.json:13-24`; `generated/operations.md:13-18` **Vulnerability Type**: Credential exposure through command-line arguments and URL query parameters **Risk Level**: Medium ### Vulnerable Code The documented invocation expands the secret into a command-line argument: ```bash node {baseDir}/bin/run.mjs --operation "streamingPicksQuery" --token "$JUST_ONE_API_TOKEN" --params-json '{"key":"value"}' ``` The token is defined as a query parameter: ```js { "defaultValue": null, "description": "User's authentication token.", "enumValues": [], "location": "query", "name": "token", "required": true, "schemaType": "string" } ``` The argument parser reads the token from the process command line: ```js if (flag === "--token") { parsed.token = value; index += 1; continue; } ``` The token is copied into the request parameters: ```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 marked as a query parameter, including the token, is 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); } } ``` The resulting URL is sent directly: ```js const baseUrl = manifest.baseUrl; const url = new URL(operation.path, ensureBaseUrl(baseUrl)); applyPathParams(operation, params, url); applyQueryParams(operation, params, url); ...[truncated 2895 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. **Remove command-line token handling** - Read the token directly from `process.env.JUST_ONE_API_TOKEN`. - Remove support for `--token` so the secret is not included in the process argument vector. - Fail safely when the environment variable is absent without printing its value. 2. **Use an authorization header** - Update the API contract to use an appropriate header, such as: ```js const token = process.env.JUST_ONE_API_TOKEN; if (!token) { fail("JUST_ONE_API_TOKEN is required.", { operationId: operation.operationId, }); } const requestInit = { headers: { accept: "application/json", authorization: `Bearer ${token}`, }, method: operation.method, }; ``` - Confirm the exact authentication scheme supported by JustOneAPI before deployment. - If the service only supports query authentication, request a header-based authentication option from the provider and document the residual logging risk until migration is possible. 3. **Prevent accidental query injection** - Remove `token` from the operation's query-parameter definition. - Reject `token` if supplied through `--params-json`, preventing callers from bypassing the safer credential path. 4. **Harden request behavior** - Avoid forwarding authorization credentials across cross-origin redirects. - Prefer disabling redirects or validate every redirect destination against the expected HTTPS origin. - Ensure errors, telemetry, and debug output redact authorization headers and token-like query parameters. 5. **Update generated artifacts and documentation** - Regenerate `generated/operations.json` and `generated/operations.md` after changing the authentication model. - Replace the documented command with one that relies on the environment variable without shell expansion into arguments: ```bash JUST_ONE_API_TOKEN="..." node {baseDir}/bin/run.mjs \ --operation "streamingPicksQuery" \ --params-json '{"languageCountry" ...[truncated 293 chars]
