Top 3 Security Risks from `eval()` & `new Function()`
These functions are primary vectors for Cross-Site Scripting (XSS), arbitrary code execution, and data theft, as they can run malicious, user-supplied code, bypassing static security checks.
The top 3
- Top Risk: Arbitrary Code Execution & RCE: The primary danger of `eval()` and `new Function()` is enabling attackers to execute arbitrary malicious code, potentially leading to a full system compromise or remote code execution (RCE) if unsanitized user input is evaluated.
- XSS Vulnerability: Hijacking User Sessions: These functions are common vectors for Cross-Site Scripting (XSS) attacks, where malicious scripts are injected into web pages and executed in other users' browsers. This can lead to credential theft, session hijacking, or website defacement.
- Local Scope Pollution & Data Exposure: Direct `eval()` executes code within the current local scope, which means injected malicious code could read or modify local variables and sensitive data, bypassing intended access controls. `new Function()` typically executes in the global scope.
Sources
Open the full topic