Last active
March 9, 2017 07:19
-
-
Save hbi99/65af9f22396d16b2f506c5edc99cff88 to your computer and use it in GitHub Desktop.
Sandboxed Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>3rd party script executed in sandbox mode</title> | |
<script type="text/javascript"> | |
var code = 'console.log(this);'+ | |
'console.log(window);'+ | |
'console.log(document);'+ | |
'console.log(console);'+ | |
'setTimeout(function() {console.log(1);}, 10);'+ | |
'eval("console.log(123)");'; | |
// sandbox container | |
(function(code) { | |
var sys = { | |
log: function(str) { | |
console.log('sys >', str); | |
} | |
}; | |
code = 'var window=undefined, document=undefined;'+ code; | |
(new Function('console', code).call({}, sys)); | |
})(code); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Test file exemplifying Javascript running in sandboxed mode