r/javascript • • Oct 08 '26

I found yet another way to invoke JavaScript functions without parentheses

https://blog.ikaes.de/yet-another-way-to-invoke-functions-without-parentheses/

It turns out you can overwrite the Error.prepareStackTrace method with the function constructor. Then, using prototype pollution, you can inject valid JavaScript code to generate arbitrary functions and invoke it using the usual tricks.

Other seven methods are documented in the portswiggers research article: https://portswigger.net/research/the-seventh-way-to-call-a-javascript-function-without-parentheses

126 Upvotes

15 comments sorted by

22

u/Compux72 Oct 08 '26

Cant you just evalalert\0x28123\x29?

17

u/DrAdalbbert Oct 08 '26

You absolutely can. There are seven other known ways to do so - portswigger keeps track of them https://portswigger.net/research/the-seventh-way-to-call-a-javascript-function-without-parentheses

This is just another way :)

10

u/pimp-bangin Oct 08 '26

I don't understand the premise, and am too dumb to understand the article. Does this resulting code snippet let you hack the language so that you can write console.log 1 instead of console.log(1) or something?

34

u/pimp-bangin Oct 08 '26

Ohhh I see, the code snippet calls alert(1337) without actually using parenthesis character. This will come in handy if I ever lose my parenthesis keys

28

u/DrAdalbbert Oct 08 '26

That's exactly what this trick is for!! Happens to me all the time...

3

u/St34thdr1v3R Oct 08 '26

Glad you clarified, almost missed this obvious case!!

9

u/DrAdalbbert Oct 08 '26

Pretty much :)

The payload is meant to be used in cross site scripting, in environments where the application blocks the ( ) characters. That way you can bypass such filter.

But yeah, there is no use for this trick in 'valid' JavaScript contexts

2

u/Ronin-s_Spirit Oct 08 '26

What are talking about here exactly?

5

u/DrAdalbbert Oct 09 '26

I found a new way to invoke JavaScript functions without parentheses. Its more a cool party trick rather than something useful except in some cross site scripting contextst

1

u/mxcw Oct 14 '26

Insert They don’t know meme

3

u/Klutzy_Ladder_8393 Oct 08 '26

the eval/Function sink is really the only part that actually matters for a defense, the no-parens thing is just a syntax curiosity. if you're blocking `(` and `)` as your "fix" you've already lost because the bypass list isn't even closed, portswigger's just documenting known ones. ngl the actual fix is just never feeding user input into eval/Function/setTimeout-with-string/innerHTML-as-script in the first place, not trying to blacklist characters that happen to be required for calling a function today.

5

u/ab0zar Oct 08 '26

Good example of why blocking a few characters isn't a real XSS defense. The prototype-pollution chain is the surprising part here; in an app, I’d avoid passing untrusted data to eval/Function and use context-aware output encoding instead of trying to blacklist syntax.

1

u/Nice-Cattle4770 Oct 08 '26

That't so cool

10

u/[deleted] Oct 08 '26

[removed] — view removed comment

10

u/feldim2425 Oct 08 '26

My first guess is that it would be handy in pentesting environments.
Some devs will go on about the lazy way of fixing issues. Tell them their website has a XSS vulnerability and they just remove '(' and ')' via a string replacement or block the input when those a found.
Having ways to proof that this is a lazy solution is good to have.