Skip to content

Commit

Permalink
Replace "new Function" with safe javascript code
Browse files Browse the repository at this point in the history
  • Loading branch information
extesy committed Oct 24, 2021
1 parent 4269441 commit 98a6d97
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
6 changes: 5 additions & 1 deletion plugins/duckduckgo.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ hoverZoomPlugins.push({
// Return JSON object corresponding to path, without using the Evil eval
// path syntax: [key1][key2][key3]...
function getObjectFromPath(objJson, path) {
return new Function('return ' + JSON.stringify(objJson) + path)();
if (!path || path.length < 4) return objJson;
const keys = path.substr(2, path.length-4).split('"]["');
let result = objJson;
keys.forEach(key => result = result[key]);
return result;
}

// src: https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse1.mm.bing.net%2Fth%3Fid%3DOIP.7U2iajPXuu6D4PSvAoI1wQHaFu%26pid%3DApi&f=1
Expand Down
8 changes: 6 additions & 2 deletions plugins/flickr.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ hoverZoomPlugins.push({
// Return JSON object corresponding to path, without using the Evil eval
// path syntax: [key1][key2][key3]...
function getObjectFromPath(objJson, path) {
return new Function('return ' + JSON.stringify(objJson) + path)();
if (!path || path.length < 4) return objJson;
const keys = path.substr(2, path.length-4).split('"]["');
let result = objJson;
keys.forEach(key => result = result[key]);
return result;
}

// Find node with good id
Expand Down Expand Up @@ -518,4 +522,4 @@ hoverZoomPlugins.push({
callback($(res), name);
}

});
});
6 changes: 5 additions & 1 deletion plugins/qwant.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ hoverZoomPlugins.push({
// Return JSON object corresponding to path, without using the Evil eval
// path syntax: [key1][key2][key3]...
function getObjectFromPath(objJson, path) {
return new Function('return ' + JSON.stringify(objJson) + path)();
if (!path || path.length < 4) return objJson;
const keys = path.substr(2, path.length-4).split('"]["');
let result = objJson;
keys.forEach(key => result = result[key]);
return result;
}

function cleanUrl(url) {
Expand Down
6 changes: 5 additions & 1 deletion plugins/sogou.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ hoverZoomPlugins.push({
// Return JSON object corresponding to path, without using the Evil eval
// path syntax: [key1][key2][key3]...
function getObjectFromPath(objJson, path) {
return new Function('return ' + JSON.stringify(objJson) + path)();
if (!path || path.length < 4) return objJson;
const keys = path.substr(2, path.length-4).split('"]["');
let result = objJson;
keys.forEach(key => result = result[key]);
return result;
}

// return true if thumbnail found among internal data from Sogou
Expand Down

0 comments on commit 98a6d97

Please sign in to comment.