Google XSS Example
Related: Google's XSS Vulnerability
In the comments to my previous blog post, Ivo Jansch asks:
To be able to comprehend how this may affect my website, could you explain how this could be exploited, even though you cannot demonstrate it?
Rather than offer another vague answer, I decided to provide a very simple proof of concept that demonstrates how character encoding inconsistencies can bite you. Google's vulnerability has of course been fixed, but with a simple PHP script, we can reproduce the situation:
<?phpheader('Content-Type: text/html; charset=UTF-7');$string = "<script>alert('XSS');</script>";$string = mb_convert_encoding($string, 'UTF-7');echo htmlentities($string);?>
If you run this PHP script, you should see a popup window:

Although the output is escaped with htmlentities(), the JavaScript is still executed by the browser.
The example attack is a UTF-7 string (I just use mb_convert_encoding() for this demonstration), and the browser interprets the page as UTF-7 due to the Content-Type header. Internet Explorer makes this assumption automatically (thus, you can remove the explicit header() call), but this example should work in any browser.
Hopefully developers will begin to appreciate the necessity of character encoding consistency. If anyone ever tries to claim that it doesn't matter, you can point them here. :-)





36 Comments
1.
Mike (SpikeZ - Sitepoint) said:
2.
Alex said:
3.
Ivo Jansch said:
4.
Ilia Alshanetsky said:
5.
Josh Dechant said:
6.
Chris Shiflett said:
7.
Josh Dechant said:
8.
DewChugr said:
9.
Chris Shiflett said:
10.
DewChugr said:
11.
Harry Fuecks said:
12.
joh said:
13.
Miggy said:
14.
Paul Davey said:
15.
Chris Shiflett said:
16.
Luis said:
17.
Chris Shiflett said:
18.
Steph said:
19.
Nate Klaiber said:
20.
Chris Shiflett said:
21.
Steven Roddis said:
22.
its not important to know my name said:
23.
Michael said:
24.
Mikispag said:
25.
SEO Blog said:
26.
Bourse said:
27.
Tereska said:
28.
Chris Shiflett said:
29.
Tereska said:
30.
Daniel said:
31.
Thijs Wijnmaalen said:
32.
Jim said:
33.
Miguel Vazquez Gocobachi said:
34.
XSS said:
35.
Vahagn said:
36.
Chris Shiflett said: