Skip to content

Commit 600f1f8

Browse files
committed
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 `>`.
1 parent db420cb commit 600f1f8

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ PHP NEWS
1616
. Fixed bug #78759 (array_search in $GLOBALS). (Nikita)
1717
. Fixed bug #78833 (Integer overflow in pack causes out-of-bound access).
1818
(cmb)
19+
. Fixed bug #78814 (strip_tags allows / in tag name => whitelist bypass).
20+
(cmb)
1921

2022
21 Nov 2019, PHP 7.2.25
2123

ext/standard/string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4663,7 +4663,7 @@ int php_tag_find(char *tag, size_t len, const char *set) {
46634663
if (state == 0) {
46644664
state=1;
46654665
}
4666-
if (c != '/') {
4666+
if (c != '/' || (*(t-1) != '<' && *(t+1) != '>')) {
46674667
*(n++) = c;
46684668
}
46694669
} else {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
Bug #78814 (strip_tags allows / in tag name => whitelist bypass)
3+
--FILE--
4+
<?php
5+
echo strip_tags("<s/trong>b</strong>", "<strong>");
6+
?>
7+
--EXPECT--
8+
b</strong>

0 commit comments

Comments
 (0)