Skip to content

Instantly share code, notes, and snippets.

@alenaksu
Created March 13, 2018 11:46
Show Gist options
  • Save alenaksu/26c5edc49e62463a9df06a87bf747c3d to your computer and use it in GitHub Desktop.
Save alenaksu/26c5edc49e62463a9df06a87bf747c3d to your computer and use it in GitHub Desktop.
const trusted = [],
untrusted = [
'eval',
...Object.keys(window)
].filter(k => trusted.indexOf(k) !== -1);
export default function createSecureScript(script, ...args) {
return new Function(
...untrusted,
...args,
`return ${script}`
).bind(undefined, ...Array(untrusted.length))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment