r/programming • • Aug 10 '12

Write any javascript code with just these characters: ()[]{}+!

http://patriciopalladino.com/blog/2012/08/09/non-alphanumeric-javascript.html
1.3k Upvotes

288 comments sorted by

View all comments

Show parent comments

16

u/nemec Aug 10 '12

How large of a script are you converting?

alert(1) becomes

[][(![]+[])[!+[]+!![]+!![]]+({}+[])[+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]]({}+[])[!+[]+!![]+!![]+!![]+!![]]+{}+[])[+!![]]+([][+[]]+[])[+!![]]+(![]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][+[]]+[])[+[]]+({}+[])[!+[]+!![]+!![]+!![]+!![]]+(!![]+[])[+[]]+({}+[])[+!![]]+(!![]+[])[+!![]][!+[]+!![]+!![]]+([][+[]]+[])[!+[]+!![]+!![]])()(({}+[])[+[]])[+[]]+(!+[]+!![]+!![]+[])+{}+[])[!+[]+!![]]))()

So I imagine a larger script will take a while to convert.

-3

u/stumac85 Aug 10 '12

Exactly - I don't get the point of this whatsoever! Is it meant to be useful?!

2

u/nemec Aug 10 '12

It's not meant to be useful, specifically (though OP did mention it could be used to circumvent certain security measures (like checking that "eval" isn't in the input or something).

It's more akin to Obfuscated C contests: http://www.ioccc.org/years.html

1

u/KimJongIlSunglasses Aug 10 '12

though OP did mention it could be used to circumvent certain security measures

This is the part I'm unclear on.
Are there application architectures in which a user submits arbitrary javascript to be executed server side and are only secured by some static code analysis?

1

u/nemec Aug 10 '12

Sometimes people try to implement their own (crappy) XSS prevention mechanisms, some of which consist of input.replace('eval', '').replace('alert', '').replace(';', '')...