Skip to content

Commit 784470f

Browse files
karussellKirill89
andcommitted
avoid prototype pollution (graphhopper#2370)
* avoid prototype pollution * Update web-bundle/src/main/resources/com/graphhopper/maps/js/tools/url.js Co-authored-by: Kirill <[email protected]> * Update web-bundle/src/test/resources/com/graphhopper/maps/spec/tools/urlSpec.js Co-authored-by: Kirill <[email protected]> * add expected in test Co-authored-by: Kirill <[email protected]>
1 parent f005b67 commit 784470f

File tree

2 files changed

+7
-0
lines changed
  • web-bundle/src
    • main/resources/com/graphhopper/maps/js/tools
    • test/resources/com/graphhopper/maps/spec/tools

2 files changed

+7
-0
lines changed

web-bundle/src/main/resources/com/graphhopper/maps/js/tools/url.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ function mergeParamIntoObject(res, key, value) {
6262
var newKey = key.substring(0, objectIndex);
6363
var subKey = key.substring(objectIndex + 1);
6464

65+
if(newKey == "__proto__" || newKey == "constructor" || newKey == "prototype") return res;
66+
6567
tmpVal = res[newKey];
6668
if(!tmpVal)
6769
tmpVal = {};

web-bundle/src/test/resources/com/graphhopper/maps/spec/tools/urlSpec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ describe('urlTools', function () {
4545
someObject = urlTools.mergeParamIntoObject({}, "one.two.three", "123");
4646
expect("123").toEqual(someObject.one.two.three);
4747

48+
someObject = urlTools.mergeParamIntoObject({}, "__proto__.polluted", "true");
49+
expect(undefined).toEqual({}.polluted);
50+
someObject = urlTools.mergeParamIntoObject({}, "constructor.prototype.polluted", "true");
51+
expect(undefined).toEqual({}.polluted);
52+
4853
var params = urlTools.parseUrl("localhost:8989?pt.test=now&pt.go.test=single&pt.go.further=far&pt.go.further=now");
4954
expect("now").toEqual(params.pt.test);
5055
expect("single").toEqual(params.pt.go.test);

0 commit comments

Comments
 (0)