Skip to content

Instantly share code, notes, and snippets.

@mmis1000
Created December 14, 2019 04:54
Show Gist options
  • Save mmis1000/1395dd4147fe1093087c09067808e063 to your computer and use it in GitHub Desktop.
Save mmis1000/1395dd4147fe1093087c09067808e063 to your computer and use it in GitHub Desktop.
Use stack overflow to expose RangeError prototype in other context
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
let iframe = document.createElement('iframe')
iframe.setAttribute('sandbox', 'allow-same-origin allow-scripts');
iframe.style.display = 'none';
document.body.append(iframe)
iframe.contentWindow.eval('window.foo = () => {}')
function getLimit (depth = 1) {
try {
return getLimit(depth + 1)
} catch (err) {
return depth
}
}
console.log(getLimit())
let err
function exhaust(depth, cb) {
try {
if (depth > 0) {
exhaust(depth - 1, cb)
} else {
cb()
}
} catch (_err) {
err =_err
}
}
exhaust(getLimit(), iframe.contentWindow.foo)
console.log(err, err instanceof RangeError)
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment