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

3

u/alcuadrado Aug 12 '12

But I can run eval myself.

Function is eval, so I do this: []["sort"]"constructor"()

Of course the website must be vulnerable to XSS.

2

u/__j_random_hacker Aug 12 '12

I see, thank you! What you've just shown there -- the ability to generate a call to eval from text strings and a few parens and brackets -- is a critically important for your work to be useful I think.

To convince myself, I just tried

[]["sort"]["constructor"]("return 4+2")()

in the Firefox Javascript web console, and sure enough I see "6"! And of course the words "sort" and "constructor" can be synthesised using a pile of non-alphanumeric characters as you've already shown.