Skip to content

Commit fe94fa8

Browse files
committed
Fixed prototype pollution when using dataType: 'json'
1 parent 0880f91 commit fe94fa8

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ Headlines: Added, Changed, Deprecated, Removed, Fixed, Security
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.27.3] - 2025-10-14
9+
10+
### Security
11+
12+
- Fixed prototype pollution when using `dataType: 'json'`.
13+
814
## [2.27.2] - 2025-10-03
915

1016
### Security

src/lib/traversal.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ export type PathData = {
1010
};
1111

1212
function setPath<T extends object>(parent: T, key: keyof T, value: any) {
13+
// Prevent prototype injection
14+
if (key === '__proto__' || key === 'prototype') {
15+
throw new Error("Cannot set an object's `__proto__` or `prototype` property");
16+
}
17+
1318
parent[key] = value;
1419
return 'skip' as const;
1520
}
@@ -190,6 +195,12 @@ export function setPaths(
190195
}
191196
return parent[key];
192197
});
193-
if (leaf) leaf.parent[leaf.key] = isFunction ? value(path, leaf) : value;
198+
if (leaf) {
199+
// Prevent prototype injection
200+
if (leaf.key === '__proto__' || leaf.key === 'prototype') {
201+
throw new Error("Cannot set an object's `__proto__` or `prototype` property");
202+
}
203+
leaf.parent[leaf.key] = isFunction ? value(path, leaf) : value;
204+
}
194205
}
195206
}

0 commit comments

Comments
 (0)