# Command Injection (CWE-78) User input is passed unsanitized to system shell commands, allowing attackers to execute arbitrary commands on the server. **Stack:** JavaScript - Prevalence: Common Found in many applications - Impact: Critical Full server compromise - Prevention: Avoid shell Use execFile, not exec **OWASP:** Injection (A03:2021-Injection) - #3 ## Description This could allow attackers to execute unexpected, dangerous commands directly on the operating system. This weakness can lead to a vulnerability in environments in which the attacker does not have direct access to the operating system. ## Prevention 1 Shoulder डिटेक्शन नियमों पर आधारित OS Command Injection के लिए रोकथाम रणनीतियाँ। ### JavaScript Use execFile/spawn with array arguments instead of exec with string commands ## Warning Signs - [CRITICAL] user input flowing to shell command execution functions ## Consequences - अनधिकृत कमांड निष्पादित करना - एप्लिकेशन डेटा पढ़ना - सुरक्षा तंत्र को बायपास करना ## Mitigations - बाहरी प्रक्रियाओं के बजाय लाइब्रेरी कॉल का उपयोग करें - यदि Runtime.exec() का उपयोग कर रहे हैं, तो उस संस्करण का उपयोग करें जो आर्ग्युमेंट्स का ऐरे लेता है - ऐसे संरचित तंत्रों का उपयोग करें जो डेटा और कोड के बीच पृथक्करण स्वतः लागू करते हैं ## Detection - Total rules: 3 - Critical: 3 - Languages: go, javascript, typescript, python ## Rules by Language ### Javascript (1 rules) - **Command Injection via child_process** [CRITICAL]: Detects user input flowing to shell command execution functions. - Remediation: Use execFile() with argument arrays instead of exec() with string commands. ```javascript const { execFile } = require('child_process'); execFile('ls', ['-la', directory]); ``` Learn more: https://shoulder.dev/learn/javascript/cwe-78/command-injection ### Typescript (1 rules) - **Command Injection via child_process** [CRITICAL]: Detects user input flowing to shell command execution functions. - Remediation: Use execFile() with argument arrays instead of exec() with string commands. ```javascript const { execFile } = require('child_process'); execFile('ls', ['-la', directory]); ``` Learn more: https://shoulder.dev/learn/javascript/cwe-78/command-injection