Security Risks of Lodash Path Resolution

Using the Lodash JavaScript library to dynamically resolve object paths introduces critical security vulnerabilities if dynamic inputs are not strictly validated. Functions such as _.get, _.set, _.has, and _.unset evaluate string or array paths to traverse object graphs, which can allow attackers to manipulate application behavior. This article examines the primary risks associated with dynamic path resolution in Lodash—including prototype pollution, information disclosure, and denial of service—and details effective mitigation strategies.

Prototype Pollution

Prototype pollution is the most severe vulnerability associated with dynamic path manipulation in Lodash, particularly when using functions like _.set or _.setWith. When an application allows untrusted input to specify object property paths, attackers can provide payload segments such as __proto__, constructor, or prototype.

If a dynamic path injects values into the base JavaScript Object.prototype, those injected properties become globally accessible across all objects in the runtime environment. This can alter control flows, bypass authorization checks, or trigger gadget chains that escalate to Remote Code Execution (RCE) in Node.js environments. Although modern versions of Lodash include patches against common prototype pollution vectors, passing completely arbitrary or nested user-controlled paths can still expose unpatched or improperly configured execution contexts to risk.

Unauthorized Property Access and Data Exposure

The _.get method simplifies accessing nested properties safely without causing TypeError exceptions. However, when users control the path argument, they can traverse parts of the object graph never intended for public access.

If an application passes request parameters, session contexts, or configuration states to _.get, an attacker can extract sensitive metadata. For instance, paths navigating into private properties, database connection instances, hidden system flags, or API credentials can leak sensitive application state directly to the user interface or API response payloads.

Denial of Service (DoS)

Malicious path inputs can cause denial-of-service conditions in several ways:

Mitigation Strategies

To secure dynamic path resolution when using Lodash, implement the following defenses: