beefproject/beef — Issue #27: Internet Explorer 9 is incorrectly reported as Internet Explorer 7
Author: passbe
Created: 2011-12-10 21:12:06+00:00
State: open

[*] Issue:

Internet Explorer 9 (and maybe 8) is incorrectly reported as Internet Explorer 7 on pages containing malformed HTML.

Internet Explorer uses Compatibility Mode (Quirks Mode) for pages containing invalid markup.

The chances of a BeEF hook residing within a malformed HTML document are quite high as XSS vectors quite often break the markup.

[*] Cause:

The browser detection for Internet Explorer 8/9 in core/main/client/browser.js is as follows:

/**
* Returns true if IE8.
* @example: beef.browser.isIE8()
*/
isIE8: function() {
$j("body").append('<!--[if IE 8]> <div id="beefiecheck" class="ie ie8"></div> <![endif]-->');
return ($j('#beefiecheck').hasClass('ie8'))?true:false;
},

/**
* Returns true if IE9.
* @example: beef.browser.isIE9()
*/
isIE9: function() {
$j("body").append('<!--[if IE 9]> <div id="beefiecheck" class="ie ie9"></div> <![endif]-->');
return ($j('#beefiecheck').hasClass('ie9'))?true:false;
},

Unfortunately the conditional HTML comments for IE8 and IE9 are not triggered in compatibility mode resulting in isIE8() and isIE9() returning false.

[*] Fix:

This could be fixed by using detection methods similar to those used for other browsers, for example:

/**
* Returns true if IE8.
* @example: beef.browser.isIE8()
*/
isIE8: function() {
return !!window.chrome && !!window.opera && window.navigator.userAgent.match(/MSIE 8\.0;/) != null;
},

/**
* Returns true if IE9.
* @example: beef.browser.isIE9()
*/
isIE9: function() {
return !!window.chrome && !!window.opera && window.navigator.userAgent.match(/MSIE 9\.0;/) != null;
},

This approach has the added benefit of not adding HTML comments to the DOM which are quite obvious to anyone viewing the DOM in a debugger.

However if it was that simple we would have done that in the first place... I hope... Please tell me there's a good reason we didn't :(
Google Code Issue: http://code.google.com/p/beef/issues/detail?id=589