RC RANDOM CHAOS

Parenthesis-Free Function Calls via Error.prepareStackTrace in JavaScript

· via Hacker News

Original source

Yet another way to invoke functions without parentheses

Hacker News →

A technique is described for invoking arbitrary functions in JavaScript without parentheses by repurposing Error.prepareStackTrace. That function, normally called to format a stack trace when an error’s stack property is read, receives the error object plus an array of code positions. Because that parameter list mirrors the Function constructor’s signature, overwriting prepareStackTrace with Function causes a new function to be generated each time a stack trace is accessed. The catch is that the array of code positions is not valid JavaScript, so the payload only executes if you can control what Array.prototype.toString() returns for that array.

Read the full article

Continue reading at Hacker News →

This is an AI-generated summary. Read the original for the full story.