Skip to content

Instantly share code, notes, and snippets.

@fennifith
Created November 4, 2019 20:57
Show Gist options
  • Save fennifith/4b6a97bb335dc747f30872a08fc96ef9 to your computer and use it in GitHub Desktop.
Save fennifith/4b6a97bb335dc747f30872a08fc96ef9 to your computer and use it in GitHub Desktop.
JavaScript regex code injection.
function f() {
console.log("hello");
console.log("steve");
}
f = new Function(/\{([\S\s]*)\}/.exec(f.toString())[1].replace('hello', 'goodbye'));
f(); // "goodbye steve"
@benrucker
Copy link

🐴

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment