Skip to content

Instantly share code, notes, and snippets.

@hbi99
Last active March 9, 2017 07:19
Show Gist options
  • Save hbi99/65af9f22396d16b2f506c5edc99cff88 to your computer and use it in GitHub Desktop.
Save hbi99/65af9f22396d16b2f506c5edc99cff88 to your computer and use it in GitHub Desktop.
Sandboxed Javascript
<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>
@hbi99
Copy link
Author

hbi99 commented Mar 9, 2017

Test file exemplifying Javascript running in sandboxed mode

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