HTML Formatter Exploit
Just as an example. The code used is
Looking through the HTML Formatter's code, I noticed it didn't replace a lot of the possible events one could hide javascript in. I'd recommend replacing all on* attributes in each tag with html entities, or just removing them all together.
<img src="blabla.png" onerror="alert('Hello There');" width=0 height=0>Looking through the HTML Formatter's code, I noticed it didn't replace a lot of the possible events one could hide javascript in. I'd recommend replacing all on* attributes in each tag with html entities, or just removing them all together.
0
This discussion has been closed.
Comments
$String = preg_replace("#<(.*) on(.*)=(.*)>#si", "<\\1 on\\2=\\3>", $String);$String = preg_replace(array("<(.*?)on(.*?)>", "<(.*?)On(.*?)>"), array("\\1on\\2", "\\1Ln\\2"), $String);Whoops, that replaces all 'o's now. Hmm... this is getting annoying.
function Execute($String) { $AllowedProtocols = array('http', 'ftp', 'https', 'irc', 'gopher'); $Patterns = array( "/o(?i)(n)/", //block all js events, but keep it as exact as possible in case "/O(?i)(n)/", //we're mistaking it for a url or something "/<a(.+?)href\s*=(\W*)([\w\d\x0a\x0d#&;]+?):([^>]+?)>/esi", //on some browsers the js protocol will still work even if it //contains html entities or a newline seperating 'java' and 'script' "/s(?i)(cript)/", //now we can go through and cancel out any script tags "/S(?i)(cript)/" ); $Replacements = array( "o\\1", "L\\1", '$this->CheckProtocol("\\3", $AllowedProtocols, "href="."\\2", "<a"."\\1", "\\4".">")', "s\\1", "P\\1" ); return preg_replace($Patterns, $Replacements, $String); }Then you'd want to add in this function in the same class as well:function CheckProtocol($Check, $Allow, $Extra, $Prefix, $Suffix) { $sReturn = stripslashes($Prefix); if(!in_array($Check, $Allow)) $sReturn .= ($Extra.'http://'); else $sReturn .= ($Extra.$Check.':'); $sReturn .= stripslashes($Suffix); return $sReturn; }lol, just as I thought; the current HTML parser dosn't fix the fact that most browsers'll still parse the js protocol even if it has entities in it:Click Me
So that's three bugs discovered so far, hopefully all fixed in this revision.
no wonder it didn't work
*gives mark donuts