From bb8d0799e0fd80a189b275d8b517749ddf9d27dd Mon Sep 17 00:00:00 2001 From: graf25 Date: Tue, 18 Jun 2002 00:19:25 +0000 Subject: [PATCH] Further XSS improvements plus a bugfix. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@2961 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/mime.php | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/functions/mime.php b/functions/mime.php index 68d82a43..aa321aaa 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -1347,10 +1347,12 @@ function sq_getnxtag($body, $offset){ * A comment or an SGML declaration. */ if (substr($body, $pos+1, 2) == "--"){ - $gt = strpos($body, "-->", $pos)+2; + $gt = strpos($body, "-->", $pos); if ($gt === false){ $gt = strlen($body); - } + } else { + $gt += 2; + } return Array(false, false, false, $lt, $gt); } else { $gt = sq_findnxstr($body, $pos, ">"); @@ -1759,10 +1761,14 @@ function sq_fixstyle($message, $id, $content){ } /** - * Fix stupid expression: declarations which lead to vulnerabilities + * Fix stupid css declarations which lead to vulnerabilities * in IE. */ - $content = preg_replace("/expression\s*:/si", "idiocy:", $content); + $match = Array('/expression/si', + '/behaviou*r/si', + '/binding/si'); + $replace = Array('idiocy', 'idiocy', 'idiocy'); + $content = preg_replace($match, $replace, $content); return $content; } @@ -1871,6 +1877,11 @@ function sq_sanitize($body, $open_tags = Array(); $trusted = "\n"; $skip_content = false; + /** + * Take care of netscape's stupid javascript entities like + * &{alert('boo')}; + */ + $body = preg_replace("/&(\{.*?\};)/si", "&\\1", $body); while (($curtag=sq_getnxtag($body, $curpos)) != FALSE){ list($tagname, $attary, $tagtype, $lt, $gt) = $curtag; @@ -2035,7 +2046,9 @@ function magicHTML($body, $id, $message){ "/.*/" => Array( "/target/si", - "/^on.*/si" + "/^on.*/si", + "/^dynsrc/si", + "/^data.*/si" ) ); @@ -2047,22 +2060,30 @@ function magicHTML($body, $id, $message){ Array( Array( "|^([\'\"])\s*\.\./.*([\'\"])|si", - "/^([\'\"])\s*\S+script\s*:.*([\'\"])/si" + "/^([\'\"])\s*\S+script\s*:.*([\'\"])/si", + "/^([\'\"])\s*mocha\s*:*(.*)([\'\"])/si", + "/^([\'\"])\s*about\s*:(.*)([\'\"])/si" ), Array( "\\1$secremoveimg\\2", - "\\1$secremoveimg\\2" + "\\1$secremoveimg\\2", + "\\1$secremoveimg\\2", + "\\1$secremoveimg\\2" ) ), "/^style/si" => Array( Array( - "/expression\s*:/si", + "/expression/si", + "/binding/si", + "/behaviou*r/si", "|url\(([\'\"])\s*\.\./.*([\'\"])\)|si", "/url\(([\'\"])\s*\S+script:.*([\'\"])\)/si" ), Array( - "idiocy:", + "idiocy", + "idiocy", + "idiocy", "url(\\1$secremoveimg\\2)", "url(\\1$secremoveimg\\2)" ) -- 2.25.1