com php-src: Fix #78814: strip_tags allows / in tag name => whitelist bypass: NEWS ext/standard/ string.c ext/standard/tests/strings/bug78814.ph pt
| From: | Christoph Michael Becker | Date: | Mon, 02 Dec 2019 10:37:25 +0000 |
| Subject: | com php-src: Fix #78814: strip_tags allows / in tag name => whitelist bypass: NEWS ext/standard/ string.c ext/standard/tests/strings/bug78814.ph pt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-109352@lists.php.net to get a copy of this message | ||
Commit: 600f1f898f9771d13880255e74ea1c10590f5fd5
Author: Christoph M. Becker <cmbecker69@gmx.de> Sun, 17 Nov 2019 14:14:59 +0100
Parents: db420cb6a141876b2f7d101051fb01934a28071a
Branches: PHP-7.2 PHP-7..3 PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=600f1f898f9771d13880255e74ea1c10590f5fd5
Log:
Fix #78814: strip_tags allows / in tag name => whitelist bypass
When normalizing tags to check whether they are contained in the set
of allowable tags, we must not strip slashes, unless they come
immediately after the opening
<, or immediately before the closing
>.
Bugs:
https://bugs.php.net/78814
Changed paths:
M NEWS
M ext/standard/string.c
A ext/standard/tests/strings/bug78814.phpt
Diff:
diff --git a/NEWS b/NEWS
index 8bb7aa5b1c1..6ecf8ad34c4 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,8 @@ PHP NEWS
. Fixed bug #78759 (array_search in $GLOBALS). (Nikita)
. Fixed bug #78833 (Integer overflow in pack causes out-of-bound access).
(cmb)
+ . Fixed bug #78814 (strip_tags allows / in tag name => whitelist bypass).
+ (cmb)
21 Nov 2019, PHP 7.2.25
diff --git a/ext/standard/string.c b/ext/standard/string.c
index dcf9cb44c76..da51cd0966f 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -4663,7 +4663,7 @@ int php_tag_find(char *tag, size_t len, const char *set) {
if (state == 0) {
state=1;
}
- if (c != '/') {
+ if (c != '/' || (*(t-1) != '<' && *(t+1) != '>'))
{
*(n++) = c;
}
} else {
diff --git a/ext/standard/tests/strings/bug78814.phpt b/ext/standard/tests/strings/bug78814.phpt
new file mode 100644
index 00000000000..c8ad8373e06
--- /dev/null
+++ b/ext/standard/tests/strings/bug78814.phpt
@@ -0,0 +1,8 @@
+--TEST--
+Bug #78814 (strip_tags allows / in tag name => whitelist bypass)
+--FILE--
+<?php
+echo strip_tags("<s/trong>b</strong>", "<strong>");
+?>
+--EXPECT--
+b</strong>