1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
Origin: https://github.com/horde/Text_Filter/commit/a2f67da064d7a91440b7a2448e56a6387ab94c67
Reviewed-by: Sylvain Beucler <beuc@debian.org>
Last-Update: 2021-02-18
From a2f67da064d7a91440b7a2448e56a6387ab94c67 Mon Sep 17 00:00:00 2001
From: Michael J Rubinsky <mrubinsk@horde.org>
Date: Sat, 13 Feb 2021 11:44:42 -0500
Subject: [PATCH] [mjr] SECURITY: Fix XSS via Text2Html filter
Reported by: Alex Birnberg<birnbergalex@gmail.com, CVE-2021-26929
---
.horde.yml | 1 +
composer.json | 1 +
lib/Horde/Text/Filter/Emails.php | 23 +++++++++++++++------
lib/Horde/Text/Filter/Linkurls.php | 26 ++++++++++++++++++++----
lib/Horde/Text/Filter/Text2html.php | 13 +++++++-----
test/Horde/Text/Filter/Text2htmlTest.php | 6 ++++--
6 files changed, 53 insertions(+), 17 deletions(-)
Index: php-horde-text-filter-2.3.5/Horde_Text_Filter-2.3.5/lib/Horde/Text/Filter/Emails.php
===================================================================
--- php-horde-text-filter-2.3.5.orig/Horde_Text_Filter-2.3.5/lib/Horde/Text/Filter/Emails.php
+++ php-horde-text-filter-2.3.5/Horde_Text_Filter-2.3.5/lib/Horde/Text/Filter/Emails.php
@@ -34,7 +34,8 @@ class Horde_Text_Filter_Emails extends H
*/
protected $_params = array(
'class' => '',
- 'encode' => false
+ 'encode' => false,
+ 'secret' => null
);
/**
@@ -85,9 +86,12 @@ EOR;
public function regexCallback($matches)
{
$data = $this->_regexCallback($matches);
-
+ $secret = new Horde_Secret();
+ if (empty($this->_params['secretKey'])) {
+ $this->_params['secretKey'] = $secret->setKey();
+ }
if ($this->_params['encode']) {
- $data = "\01\01\01" . base64_encode($data) . "\01\01\01";
+ $data = "\01\01\01" . base64_encode($secret->write($this->_params['secretKey'], $data)) . "\01\01\01";
}
return $matches[1] . $matches[2] . (isset($matches[9]) ? $matches[9] : '') .
@@ -119,15 +123,22 @@ EOR;
* "Decodes" the text formerly encoded by using the "encode" parameter.
*
* @param string $text An encoded text.
+ * @param string $key An optional key to use with Horde_Secret encryption.
+ * If omitted a key will be fetched from a Horde_Secret
+ * instance.
*
* @return string The decoded text.
*/
- public static function decode($text)
+ public static function decode($text, $key = null)
{
+ $secret = new Horde_Secret();
+ if (empty($key)) {
+ $key = $secret->getKey();
+ }
return preg_replace_callback(
'/\01\01\01([\w=+\/]*)\01\01\01/',
- function($hex) {
- return base64_decode($hex[1]);
+ function($hex) use ($secret, $key) {
+ return $secret->read($key, base64_decode($hex[1]));
},
$text);
}
Index: php-horde-text-filter-2.3.5/Horde_Text_Filter-2.3.5/lib/Horde/Text/Filter/Linkurls.php
===================================================================
--- php-horde-text-filter-2.3.5.orig/Horde_Text_Filter-2.3.5/lib/Horde/Text/Filter/Linkurls.php
+++ php-horde-text-filter-2.3.5/Horde_Text_Filter-2.3.5/lib/Horde/Text/Filter/Linkurls.php
@@ -29,6 +29,10 @@
* DEFAULT: false
* - target: (string) The link target.
* DEFAULT: '_blank'
+ * - secretKey: (string) A key to use for Horde_Secret encryption of encoded
+ * html tags (see the 'encode' paramter).
+ * DEFAULT: A default key will be created by an instance of
+ * Horde_Secret.
*
* Copyright 2003-2016 Horde LLC (http://www.horde.org/)
*
@@ -60,6 +64,7 @@ class Horde_Text_Filter_Linkurls extends
'encode' => false,
'nofollow' => false,
'target' => '_blank',
+ 'secretKey' => null
);
/**
@@ -172,8 +177,13 @@ END_OF_REGEX;
'<meta http-equiv="x-dns-prefetch-control" value="on" />';
}
+ $secret = new Horde_Secret();
+ if (empty($this->_params['secretKey'])) {
+ $this->_params['secretKey'] = $secret->setKey();
+ }
+
if ($this->_params['encode']) {
- $replacement = chr(0) . chr(0) . chr(0) . base64_encode($replacement) . chr(0) . chr(0) . chr(0);
+ $replacement = chr(0) . chr(0) . chr(0) . base64_encode($secret->write($this->_params['secretKey'], $replacement)) . chr(0) . chr(0) . chr(0);
}
return $replacement;
@@ -183,15 +193,23 @@ END_OF_REGEX;
* "Decodes" the text formerly encoded by using the "encode" parameter.
*
* @param string $text An encoded text.
+ * @param string $key An optional key to use with Horde_Secret encryption.
+ * If omitted a key will be fetched from a Horde_Secret
+ * instance.
*
* @return string The decoded text.
*/
- public static function decode($text)
+ public static function decode($text, $key = null)
{
+ $secret = new Horde_Secret();
+ if (empty($key)) {
+ $key = $secret->getKey();
+ }
+
return preg_replace_callback(
'/\00\00\00([\w=+\/]*)\00\00\00/',
- function($hex) {
- return base64_decode($hex[1]);
+ function($hex) use ($secret, $key) {
+ return $secret->read($key, base64_decode($hex[1]));
},
$text);
}
Index: php-horde-text-filter-2.3.5/Horde_Text_Filter-2.3.5/lib/Horde/Text/Filter/Text2html.php
===================================================================
--- php-horde-text-filter-2.3.5.orig/Horde_Text_Filter-2.3.5/lib/Horde/Text/Filter/Text2html.php
+++ php-horde-text-filter-2.3.5/Horde_Text_Filter-2.3.5/lib/Horde/Text/Filter/Text2html.php
@@ -37,7 +37,8 @@ class Horde_Text_Filter_Text2html extend
'linkurls' => false,
'text2html' => false,
'parselevel' => 0,
- 'space2html' => false
+ 'space2html' => false,
+ 'secretKey' => null
);
/**
@@ -144,7 +145,8 @@ class Horde_Text_Filter_Text2html extend
$filters = $this->_params['linkurls'];
} else {
$filters['linkurls'] = array(
- 'encode' => true
+ 'encode' => true,
+ 'secretKey' => $this->_params['secretKey']
);
}
@@ -155,7 +157,8 @@ class Horde_Text_Filter_Text2html extend
$filters += $this->_params['emails'];
} else {
$filters['emails'] = array(
- 'encode' => true
+ 'encode' => true,
+ 'secretKey' => $this->_params['secretKey']
);
}
}
@@ -201,9 +204,9 @@ class Horde_Text_Filter_Text2html extend
/* Do in-lining of http://xxx.xxx to link, xxx@xxx.xxx to email. */
if ($this->_params['parselevel'] < self::NOHTML) {
- $text = Horde_Text_Filter_Linkurls::decode($text);
+ $text = Horde_Text_Filter_Linkurls::decode($text, $this->_params['secretKey']);
if ($this->_params['parselevel'] < self::MICRO_LINKURL) {
- $text = Horde_Text_Filter_Emails::decode($text);
+ $text = Horde_Text_Filter_Emails::decode($text, $this->_params['secretKey']);
}
if ($this->_params['space2html']) {
Index: php-horde-text-filter-2.3.5/Horde_Text_Filter-2.3.5/test/Horde/Text/Filter/Text2htmlTest.php
===================================================================
--- php-horde-text-filter-2.3.5.orig/Horde_Text_Filter-2.3.5/test/Horde/Text/Filter/Text2htmlTest.php
+++ php-horde-text-filter-2.3.5/Horde_Text_Filter-2.3.5/test/Horde/Text/Filter/Text2htmlTest.php
@@ -19,8 +19,10 @@ class Horde_Text_Filter_Text2htmlTest ex
$this->assertEquals(
$expected,
Horde_Text_Filter::filter($input, 'text2html', array(
- 'parselevel' => $level
- ))
+ 'parselevel' => $level,
+ 'secretKey' => "mGmEXue4Az0YurdMK6p3alB"
+ )
+ )
);
}
|