Added scripting JPath restriction

This commit is contained in:
Michael Rowley 2022-08-14 11:42:06 +01:00
parent 037590f831
commit 4687adc9d4
2 changed files with 19 additions and 0 deletions

View File

@ -49,6 +49,14 @@ class JPathExpression extends Operation {
let results,
obj;
// Split the string by literal quotes
const quoteSplit = query.split(/(?<=[^\\])"/);
for (let i = 0; i < quoteSplit.length; i++) {
// Only check the text that isn't surrounded by quotes.
if (i % 2 === 0 && quoteSplit[i].match(/\[\??\(/))
throw new OperationError("Query contains unsafe expression.");
}
try {
obj = JSON.parse(input);
} catch (err) {

View File

@ -310,6 +310,17 @@ TestRegister.addTests([
}
],
},
{
name: "JPath Expression: Script-based expression",
input: "[{}]",
recipeConfig: [
{
"op": "JPath expression",
"args": ["$..[?(({__proto__:[].constructor}).constructor(\"self.postMessage({action:'bakeComplete',data:{bakeId:1,dish:{type:1,value:''},duration:1,error:false,id:undefined,inputNum:2,progress:1,result:'<iframe/onload=debugger>',type: 'html'}});\")();)]", "\n"]
}
],
expectedOutput: "Query contains unsafe expression."
},
{
name: "CSS selector",
input: '<div id="test">\n<p class="a">hello</p>\n<p>world</p>\n<p class="a">again</p>\n</div>',