T09 · Insecure Skill Coding Practices
Note
- Location
- anthropic-chat.js:17
- Finding
- Undefined TASK Variable Causes Unconditional Runtime Failure## Vulnerability Details **File Location**: `anthropic-chat.js`, lines 17–22 **Vulnerability Type**: Use of an undeclared variable resulting in denial of service **Risk Level**: Low ### Vulnerable Code ```js const body = JSON.stringify({ model: MODEL, max_tokens: MAX_TOKENS, messages: [{ role: 'user', content: TASK || 'Hello, Claude.' }] }); ``` ### Technical Analysis The identifier `TASK` is referenced without being declared, imported, or populated from command-line input or another defined source. In Node.js, evaluating an undeclared identifier raises a `ReferenceError`. The `|| 'Hello, Claude.'` fallback cannot handle this condition because JavaScript must first evaluate `TASK`, which throws before the fallback operand can be selected. Consequently, body construction always fails during normal execution, before the HTTPS request is created or sent. This contradicts the documented behavior that a natural-language task is accepted and forwarded to the Anthropic Messages API. ### Attack Path 1. A user or automated process invokes `anthropic-chat.js`. 2. The environment contains a valid `ANTHROPIC_API_KEY`, allowing execution to pass the initial API-key check. 3. The script reaches the request-body construction at line 21. 4. JavaScript evaluates the undeclared `TASK` identifier and raises `ReferenceError: TASK is not defined`. 5. The process terminates before sending the API request or returning a model response. No special privileges or attacker-controlled input are required to trigger the failure. ### Impact Assessment The issue causes complete loss of availability for the skill: all otherwise valid invocations fail before reaching the Anthropic API. It does not provide access to additional privileges, expose the API key, enable code execution, or affect resources beyond the failing process. The practical scope is limited to disruption of this skill and any workflow that depends on it.
- Remediation
- ## Remediation Suggestions Explicitly define and validate the task before constructing the request body. For example: ```js const TASK = process.argv.slice(2).join(' ').trim(); const taskContent = TASK || 'Hello, Claude.'; const body = JSON.stringify({ model: MODEL, max_tokens: MAX_TOKENS, messages: [{ role: 'user', content: taskContent }] }); ``` If an empty task should be rejected rather than replaced with a default, terminate with a clear usage message: ```js const TASK = process.argv.slice(2).join(' ').trim(); if (!TASK) { console.error('Usage: anthropic-chat.js <task>'); process.exit(1); } ``` Add an automated smoke test that invokes the script with a task and verifies that request construction does not raise a `ReferenceError`. The input mechanism should also be documented in `SKILL.md` so runtime behavior and usage instructions remain consistent.
