Yet another way to invoke functions without parentheses(blog.ikaes.de)
264 points by aragonite 12 days ago | 105 comments
tl;dr: A novel JavaScript technique for invoking arbitrary functions without parentheses by overwriting `Error.prepareStackTrace` with the `Function` constructor, which shares a compatible signature. Since accessing an error's `stack` triggers this callback with an array of code positions, the author manipulates `Array.prototype.toString` (via direct override or prototype pollution of `Object.prototype.message`) to inject valid JS code. The generated function is then triggered using the `valueOf` trick by coercing the error object to a primitive.
HN Discussion:
  • ↑Appreciation for the clever hack as nostalgic, fun code exploration
  • ↑JavaScript's ability to enable such weird tricks is cursed/amazing
  • ↓The technique is limited since prepareStackTrace is V8-only, not standard
  • ~There are many other known ways to invoke functions without parentheses in JS
  • ↓The use of \x28/\x29 escapes technically counts as using parentheses, undermining the claim