Thursday, October 04, 2007

Browser detection using known HTML parser bugs

If you've developed webapps then it is likely you've had to detect what browser is accessing the site and then use javascript or CSS to do something special for that browser. This dude has found a way to use known HTML parser rendering bugs to identify Firefox, IE, Safari, Opera, Lynx and other browsers using just plain HTML. Here is some sample code (I must get round to converting this to Java):


#!/usr/bin/perl
print qq{
<img /src\x00="ie.gif"
/''src\x00="firefox1_5.gif"
/''src="firefox2_0.gif"
/""src="gecko_others.gif"
"s\x00rc="safari2.gif"
"src="safari3.gif"
""src="konqueror.gif"
src\x00="w3m.gif"
src\x0c="opera.gif"
src="others.gif"
src="lynx.gif"
/> };


This technique is reported to work with many HTML tags, not just IMG. Clever hack!

No comments: