From 98c2d69acf3001379dc008dc52b77b618c291140 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Fri, 09 Dec 2011 20:50:03 -0500
Subject: [PATCH] Be more strict in style attribute filtering

---
 tests/src/BID-26800.txt |    3 ++-
 program/lib/washtml.php |    2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/program/lib/washtml.php b/program/lib/washtml.php
index 8bbc136..f8c3251 100644
--- a/program/lib/washtml.php
+++ b/program/lib/washtml.php
@@ -168,7 +168,7 @@
                 || ($src = $this->config['cid_map'][$this->config['base_url'].$match[2]])) {
               $value .= ' url('.htmlspecialchars($src, ENT_QUOTES) . ')';
             }
-            else if (preg_match('/^(http|https|ftp):.*$/i', $match[2], $url)) {
+            else if (preg_match('!^(https?:)?//[a-z0-9/._+-]+$!i', $match[2], $url)) {
               if ($this->config['allow_remote'])
                 $value .= ' url('.htmlspecialchars($url[0], ENT_QUOTES).')';
               else
diff --git a/tests/src/BID-26800.txt b/tests/src/BID-26800.txt
index 513516c..e4e2fe7 100644
--- a/tests/src/BID-26800.txt
+++ b/tests/src/BID-26800.txt
@@ -10,13 +10,14 @@
 <h1>2 test</h1>
 <p>&lt;div&gt; block</p>
 <div style="font-style:italic">valid css</div>
+<div style="color:red; background:url('//somedomain.com/somepath/somefile.png')">
 <div style="{ left:expression( alert(&#039;expression!&#039;) ) }">
 <div style="{ background:url( alert(&#039;URL!&#039;) ) }">
 
 <h1>3 test</h1>
 <p>Inject comment text</p>
 <div style="{ left:exp/*  */ression( alert(&#039;xss3&#039;) ) }">
-<div style="{ background:u/* */rl( alert(&#039;xssurl3&#039;) ) }">
+<div style=" background:u/* */rl( alert(&#039;xssurl3&#039;) ) ">
 
 <h1>4 test</h1>
 <p>Using reverse solid to directe the codepoint</p>

--
Gitblit v1.9.1