T09 · Insecure Skill Coding Practices
Warning
- Location
- bin/run.mjs:18
- Finding
- API Credential Exposed Through Process Arguments and URL Query Parameters<![CDATA[ ## Vulnerability Details **File Location**: `bin/run.mjs:18-24, 93-109, 164-168, 198-206, 239-246`; related usage guidance in `SKILL.md:43-51` **Vulnerability Type**: API credential exposure **Risk Level**: Medium ### Vulnerable Code The operation manifest defines the authentication token as a query parameter: ```js { "defaultValue": null, "description": "User's authentication token.", "enumValues": [], "location": "query", "name": "token", "required": true, "schemaType": "string" }, ``` The token is accepted as a command-line argument: ```js if (flag === "--token") { parsed.token = value; index += 1; continue; } ``` The supplied token is placed 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; } ``` All parameters marked as query parameters, including the token, are 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 transmitted to the fixed JustOneAPI endpoint: ```js applyQueryParams(operation, params, url); const requestInit = { headers: { "accept": "application/json", }, method: operation.method, }; let response; try { response = await fetch(url, requestInit); ``` The documented invocation also passes the token through the process command line: ```bash node {baseDir}/bin/run.mjs --operation "titleAwardsSummaryQuery" --token "$JUST_ONE_API_TOKEN" --params-json ...[truncated 2628 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. **Use an authorization header** - If supported by JustOneAPI, remove `token` from the query-parameter manifest. - Send the credential using a standard header such as: ```js const requestInit = { headers: { "accept": "application/json", "authorization": `Bearer ${token}`, }, method: operation.method, }; ``` 2. **Read the token directly from the environment** - Prefer `process.env.JUST_ONE_API_TOKEN` over a `--token` argument. - Do not copy the token into process arguments. - Fail safely when the variable is absent: ```js const token = process.env.JUST_ONE_API_TOKEN; if (!token) { fail("JUST_ONE_API_TOKEN is required."); } ``` 3. **Prevent accidental parameter override** - Do not permit `params-json` to contain a `token` property. - Keep authentication data separate from user-controlled endpoint parameters. 4. **Apply comprehensive redaction** - Redact `token`, `authorization`, and equivalent credential fields from application logs, proxy logs, traces, errors, telemetry, and diagnostic output. - Ensure failures never print the complete request URL when it could contain credentials. 5. **If query authentication is unavoidable** - Explicitly document the residual exposure risk. - Configure all reverse proxies, gateways, and backend services to suppress or redact the `token` query parameter. - Use narrowly scoped, short-lived tokens and provide straightforward rotation and revocation procedures. 6. **Update documentation** - Replace the documented `--token` invocation with environment-only credential handling. - Warn users not to include tokens in URLs, command history, screenshots, logs, or issue reports. ]]>
