# Uncontrolled Resource Consumption (CWE-400) The product does not properly control the allocation and maintenance of a limited resource, thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources. **Stack:** JavaScript - Prevalence: उच्च बार-बार शोषित - Impact: मध्यम समीक्षा अनुशंसित - Prevention: प्रलेखित 8 फिक्स उदाहरण **OWASP:** Security Misconfiguration (A05:2021-Security Misconfiguration) - #5 ## Description Limited resources include memory, file system storage, database connection pool entries, and CPU. If an attacker can trigger the allocation of these limited resources, but the number or size of the resources is not controlled, then the attacker could cause a denial of service. ## Prevention 2 Shoulder डिटेक्शन नियमों पर आधारित Resource Exhaustion के लिए रोकथाम रणनीतियाँ। ### JavaScript Set max_tokens limits and validate input length before LLM API calls Configure timeout and maxBuffer for child process execution to prevent resource exhaustion ## Warning Signs - [MEDIUM] LLM API call lacks resource limits (...) - [MEDIUM] AI/LLM API calls that lack token limits, potentially enabling denial of service attacks - [MEDIUM] child process execution (exec, spawn) without proper resource limits ## Consequences - DoS: संसाधन खपत - DoS: क्रैश / निकास / पुनः आरंभ ## Mitigations - रेट लिमिटिंग लागू करें - संसाधन कोटा का उपयोग करें - ऑपरेशनों के लिए टाइमआउट लागू करें ## Detection - Total rules: 8 - Languages: go, javascript, typescript, yaml, python ## Rules by Language ### Javascript (2 rules) - **LLM Denial of Service** [MEDIUM]: Detects AI/LLM API calls that lack token limits, potentially enabling denial of service attacks. OWASP LLM04 - Model Denial of Service. DoS attacks against LLMs can: - Exhaust API quotas through unbounded token generation - Cause excessive costs via high token usage - Degrade service availability This rule detects: - Missing max_tokens limits on completions - Missing input length validation - Unbounded streaming responses NOTE: Rate limiting is covered separately by the Express rate-limiting - Remediation: Set max_tokens limits and validate input length before LLM calls. ```javascript const response = await openai.chat.completions.create({ model: 'gpt-4', messages: [{ role: 'user', content: message.substring(0, 2000) }], max_tokens: 500 }); ``` Learn more: https://shoulder.dev/learn/javascript/cwe-400/llm-denial-of-service - **Denial of Service via Unbounded Child Processes** [MEDIUM]: Detects child process execution (exec, spawn) without proper resource limits. Without timeout or maxBuffer configuration, these processes can: - Hang indefinitely, consuming server resources - Flood memory with unbounded output - Enable DoS attacks through resource exhaustion This is especially critical when the command can be influenced by user input or interacts with external resources (network requests, git operations, etc.). - Remediation: Configure timeout and maxBuffer for child process execution: ```javascript const { exec } = require('child_process'); const { promisify } = require('util'); const execPromise = promisify(exec); const { stdout } = await execPromise(`ping -c 4 ${domain}`, { timeout: 5000, maxBuffer: 1024 * 100 }); ``` Learn more: https://shoulder.dev/learn/javascript/cwe-400/unbounded-exec-dos ### Typescript (2 rules) - **LLM Denial of Service** [MEDIUM]: Detects AI/LLM API calls that lack token limits, potentially enabling denial of service attacks. OWASP LLM04 - Model Denial of Service. DoS attacks against LLMs can: - Exhaust API quotas through unbounded token generation - Cause excessive costs via high token usage - Degrade service availability This rule detects: - Missing max_tokens limits on completions - Missing input length validation - Unbounded streaming responses NOTE: Rate limiting is covered separately by the Express rate-limiting - Remediation: Set max_tokens limits and validate input length before LLM calls. ```javascript const response = await openai.chat.completions.create({ model: 'gpt-4', messages: [{ role: 'user', content: message.substring(0, 2000) }], max_tokens: 500 }); ``` Learn more: https://shoulder.dev/learn/javascript/cwe-400/llm-denial-of-service - **Denial of Service via Unbounded Child Processes** [MEDIUM]: Detects child process execution (exec, spawn) without proper resource limits. Without timeout or maxBuffer configuration, these processes can: - Hang indefinitely, consuming server resources - Flood memory with unbounded output - Enable DoS attacks through resource exhaustion This is especially critical when the command can be influenced by user input or interacts with external resources (network requests, git operations, etc.). - Remediation: Configure timeout and maxBuffer for child process execution: ```javascript const { exec } = require('child_process'); const { promisify } = require('util'); const execPromise = promisify(exec); const { stdout } = await execPromise(`ping -c 4 ${domain}`, { timeout: 5000, maxBuffer: 1024 * 100 }); ``` Learn more: https://shoulder.dev/learn/javascript/cwe-400/unbounded-exec-dos