Severity
Low
Short Description
Dynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Packages
View packages with this alert.Suggestion
Packages should avoid dynamic imports when possible. Audit the use of dynamic require to ensure it is not executing malicious or vulnerable code.
This alert indicates that the package uses require
dynamically to load modules. Dynamic require
calls can pose risks as they may introduce unsafe or malicious code into the application if not properly controlled.
Dynamic require
allows loading modules at runtime based on dynamic input (e.g., require(variable)
instead of require('module-name')
). While it provides flexibility, it also presents several risks, including:
require
call, attackers can load malicious modules or code.require
can make the code harder to analyze, audit, or understand, increasing the chance of unnoticed vulnerabilities.Dynamic require
usage should be carefully audited to ensure it is not being used for unsafe or insecure purposes.
Audit Dynamic Require Usage:
require
in the codebase.Avoid Unnecessary Dynamic Imports:
require('module-name')
or import
).Validate Inputs:
require
is unavoidable, sanitize and validate the inputs to prevent malicious module loading.Review Module Sources:
Consider Alternatives:
import()
dynamically for modern ECMAScript modules, as they have more predictable behavior and are often easier to secure.Here's an example of a package flagged for the Dynamic Require alert.
By exposing require
, the package effectively enables dynamic imports at runtime, which is flagged because it can lead to:
require
, it could load malicious or untrusted modules.The Dynamic Require alert detects the exposure of Node.js's require
function as it allows dynamic module imports, which could enable arbitrary code execution or code injection if user inputs are not validated.