Skip to content

Commit

Permalink
Fix #78814: strip_tags allows / in tag name => whitelist bypass
Browse files Browse the repository at this point in the history
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
`>`.
  • Loading branch information
cmb69 committed Dec 2, 2019
1 parent db420cb commit 600f1f8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions ext/standard/tests/strings/bug78814.phpt
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 600f1f8

Please sign in to comment.