This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
inconsistency: disallow new Function()
eval() loophole
#146
Comments
iameli
changed the title
Disallow
desync: disallow Mar 8, 2020
new Function()
eval() loopholenew Function()
eval() loophole
Hmm, a naive test shows that |
iameli
changed the title
desync: disallow
inconsistency: disallow Mar 8, 2020
new Function()
eval() loopholenew Function()
eval() loophole
Minimal repro case: import Ajv from "ajv";
const handleEvent = () => {
try {
var schema = {
type: "string"
};
var ajv = new Ajv(); // options can be passed, e.g. {allErrors: true}
var validate = ajv.compile(schema);
var valid = validate("foo");
return new Response(`valid: ${valid}`);
} catch (e) {
return new Response(e.stack, { status: 500 });
}
};
addEventListener("fetch", event => {
event.respondWith(handleEvent());
}); I'm building that with
Spooky. How is AJV sneaking past |
Okay, confirmed my original hypothesis - |
I added a few cases in your PR that should be disallowed. The rule is any evaluation of any generated code is disallowed (wasm is one non obvious case). |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Ajv, the JSON-Schema validator doesn't work on Cloudflare Workers.. It relies on
eval()
'd code generation, and CF workers don't allow eval().I was surprised to find that it worked perfectly fine in Cloudworker. I think it's because ajv doesn't actually use
eval()
, it uses thenew Function(<string>)
constructor, which we patch into the runtime environment here.For consistency, we should find a way to disable that mechanism without breaking the
foo instanceof Function
construct.The text was updated successfully, but these errors were encountered: