Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

fix new Function(<string>) allowing for arbitrary code execution #149

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

iameli
Copy link

@iameli iameli commented Mar 8, 2020

Pay attention to the security note — I'm really not sure if there's a way to hack around this or not. But this at least makes us consistent with CF workers in the common case.

fixes #146

test('throws on new Function(<string>)', async () => {
const bindings = { EvalError: EvalError }
expect(() => { new Cloudworker(`new Function('true')`, { bindings }) }).toThrow(new EvalError('Code generation from strings disallowed for this context')) // eslint-disable-line no-new
})
})
Copy link

@xtuc xtuc Mar 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add a test for disallowing Function.constructor("console.log(1)")() and similarly ({}).constructor.constructor("console.log(1)")()?

Also note that code generation applies to wasm as well:

  const arr = [];
  new WebAssembly.Module(arr)

should be disallowed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

inconsistency: disallow new Function() eval() loophole
2 participants