r/javascript • u/DrAdalbbert • 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
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 keys28
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
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
10
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.
22
u/Compux72 Oct 08 '26
Cant you just eval
alert\0x28123\x29?