Skip to content

Commit 6ad6035

Browse files
committed
Fix prototype pollution
1 parent 6fc27c2 commit 6ad6035

File tree

6 files changed

+47
-7
lines changed

6 files changed

+47
-7
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 yeikos - http://www.yeikos.com
3+
Copyright (c) 2014 yeikos
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "merge",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"homepage": "https://github.com/yeikos/js.merge",
55
"authors": [
66
"yeikos <[email protected]>"

merge.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* @name JavaScript/NodeJS Merge v1.2.0
2+
* @name JavaScript/NodeJS Merge v1.2.1
33
* @author yeikos
44
* @repository https://github.com/yeikos/js.merge
55
@@ -128,6 +128,8 @@
128128

129129
for (var key in item) {
130130

131+
if (key === '__proto__') continue;
132+
131133
var sitem = clone ? Public.clone(item[key]) : item[key];
132134

133135
if (recursive) {

merge.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "merge",
3-
"version": "1.2.0",
4-
"author": "yeikos (http://www.yeikos.com)",
3+
"version": "1.2.1",
4+
"author": "yeikos",
55
"description": "Merge multiple objects into one, optionally creating a new cloned object. Similar to the jQuery.extend but more flexible. Works in Node.js and the browser.",
66
"main": "merge.js",
77
"license": "MIT",

tests/tests.js

+38
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@ test('merge', function() {
5050

5151
});
5252

53+
test('merge (prototype pollution attack)', function() {
54+
55+
deepEqual(
56+
57+
merge({}, JSON.parse('{"__proto__": {"a": true}}')),
58+
{}
59+
60+
);
61+
62+
deepEqual(
63+
64+
{}.a,
65+
66+
undefined
67+
68+
);
69+
70+
});
71+
5372
test('merge (clone)', function() {
5473

5574
var input = {
@@ -143,6 +162,25 @@ test('merge.recursive', function() {
143162

144163
});
145164

165+
test('merge.recursive (prototype pollution attack)', function() {
166+
167+
deepEqual(
168+
169+
merge.recursive({}, JSON.parse('{"__proto__": {"a": true}}')),
170+
{}
171+
172+
);
173+
174+
deepEqual(
175+
176+
{}.a,
177+
178+
undefined
179+
180+
);
181+
182+
});
183+
146184
test('merge.recursive (clone)', function() {
147185

148186
var input = { a: { b: 1 } };

0 commit comments

Comments
 (0)