T09 · Insecure Skill Coding Practices
- Location
anthropic-chat.js:17- Finding
Undefined TASK Variable Causes Unconditional Runtime Failure
- Content
View full analysis
Vulnerability Details
File Location:
anthropic-chat.js, lines 17–22
Vulnerability Type: Use of an undeclared variable resulting in denial of service
Risk Level: LowVulnerable Code
js const body = JSON.stringify({ model: MODEL, max_tokens: MAX_TOKENS, messages: [{ role: 'user', content: TASK || 'Hello, Claude.' }] });Technical Analysis
The identifier
TASKis referenced without being declared, imported, or populated from command-line input or another defined source. In Node.js, evaluating an undeclared identifier raises aReferenceError. The|| 'Hello, Claude.'fallback cannot handle this condition because JavaScript must first evaluateTASK, 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
- A user or automated process invokes
anthropic-chat.js. - The environment contains a valid
ANTHROPIC_API_KEY, allowing execution to pass the initial API-key check. - The script reaches the request-body construction at line 21.
- JavaScript evaluates the undeclared
TASKidentifier and raisesReferenceError: TASK is not defined. - 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.
- A user or automated process invokes
- Remediation
View 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 inSKILL.mdso runtime behavior and usage instructions remain consistent.
