Dangerous JS Functions
ID |
dangerous_js_functions |
Severity |
low |
Kind |
Cross-Site Scripting |
CWE |
749 |
Description
A dangerous JS function seems to be in use that would leave the site vulnerable. The detector identifies potentially unsafe JavaScript functions like eval(), setTimeout() with string arguments, innerHTML assignments, or document.write() that can introduce security vulnerabilities when processing untrusted data.
Rationale
Dangerous JavaScript functions can execute arbitrary code when supplied with attacker-controlled input. Functions like eval() and Function() constructor convert strings to executable code, enabling code injection attacks. Using innerHTML with unsanitized data allows XSS attacks, while document.write() can be exploited for script injection. Attackers leverage these functions by injecting malicious payloads through URL parameters, form inputs, or API responses that get processed by these unsafe operations, leading to session hijacking, data theft, or complete application compromise.
Remediation
Replace dangerous functions with safer alternatives such as JSON.parse() instead of eval(), textContent instead of innerHTML for plain text, and DOM manipulation methods instead of document.write(). If dynamic code execution is absolutely necessary, implement strict input validation and use sandboxed environments. Apply Content Security Policy headers to restrict eval() and inline script execution. Use static analysis tools to detect and eliminate usage of dangerous functions during development.