Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: echo "::set-output name=directory::$(composer config cache-dir)"

- name: Cache composer dependencies
uses: actions/cache@v3.3.1
uses: actions/cache@v3.4.0
with:
path: ${{ steps.composer-cache.outputs.directory }}
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
Expand Down
30 changes: 20 additions & 10 deletions src/voku/helper/AntiXSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ private function _compact_exploded_javascript($str)
//
// That way valid stuff like "dealer to!" does not become "dealerto".

$str = (string) \preg_replace_callback(
$tmp = \preg_replace_callback(
'#(?<before>[^\p{L}]|^)(?<word>' . \str_replace(
['#', '.'],
['\#', '\.'],
Expand All @@ -531,6 +531,7 @@ function ($matches) {
},
$str
);
$str = $tmp ?? $str;
}

return $str;
Expand Down Expand Up @@ -631,13 +632,14 @@ private function _decode_string($str)
&&
\preg_match($regExForHtmlTags, $str)
) {
$str = (string) \preg_replace_callback(
$tmp = \preg_replace_callback(
$regExForHtmlTags,
function ($matches) {
return $this->_decode_entity($matches);
},
$str
);
$str = $tmp ?? $str;
} else {
$str = UTF8::rawurldecode($str);
}
Expand Down Expand Up @@ -687,7 +689,8 @@ private function _do($str)

// remove all >= 4-Byte chars if needed
if ($this->_stripe_4byte_chars) {
$str = (string) \preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $str);
$tmp = \preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $str);
$str = $tmp ?? $str;
}

// backup the string (for later comparison)
Expand Down Expand Up @@ -762,11 +765,12 @@ private function _do_never_allowed($str)
}
}
if (\count($replaceNeverAllowedCall) > 0) {
$str = (string) \preg_replace(
$tmp = \preg_replace(
'#([^\p{L}]|^)(?:' . \implode('|', $replaceNeverAllowedCall) . ')\s*:(?:.*?([/\\\;()\'">]|$))#ius',
'$1' . $this->_replacement . '$2',
$str
);
$str = $tmp ?? $str;
}

// ---
Expand All @@ -779,23 +783,25 @@ private function _do_never_allowed($str)
continue;
}

$str = (string) \preg_replace(
$tmp = \preg_replace(
'#' . $regex . '#iUus',
$replacement,
$str
);
$str = $tmp ?? $str;
}

if (!$this->_cache_never_allowed_regex_string || $regex_combined !== []) {
$this->_cache_never_allowed_regex_string = \implode('|', $regex_combined);
}

if ($this->_cache_never_allowed_regex_string) {
$str = (string) \preg_replace(
$tmp = \preg_replace(
'#' . $this->_cache_never_allowed_regex_string . '#ius',
$this->_replacement,
$str
);
$str = $tmp ?? $str;
}

return $str;
Expand Down Expand Up @@ -848,13 +854,14 @@ private function _do_never_allowed_afterwards($str)
do {
$count = $temp_count = 0;

$str = (string) \preg_replace(
$tmp = \preg_replace(
'#' . $regex . '#ius',
'$1' . $this->_replacement . '$2',
$str,
-1,
$temp_count
);
$str = $tmp ?? $str;
$count += $temp_count;
} while ($count);

Expand Down Expand Up @@ -1143,11 +1150,12 @@ private function _js_removal_callback($match, $search)
$foundSomethingBad = true;
$this->_xss_found = true;

$replacer = (string) \preg_replace(
$tmp = \preg_replace(
$pattern,
$search . '="' . $this->_replacement . '"',
$replacer
);
$replacer = $tmp ?? $replacer;
}
}
}
Expand All @@ -1163,11 +1171,12 @@ private function _js_removal_callback($match, $search)
$pattern = '#' . $search . '=.*(?:' . $patternTmp . \implode('|', $this->_never_allowed_js_callback_regex) . ')#ius';
$matchInner = [];
if (\preg_match($pattern, $match[1], $matchInner)) {
$replacer = (string) \preg_replace(
$tmp = \preg_replace(
$pattern,
$search . '="' . $this->_replacement . '"',
$replacer
);
$replacer = $tmp ?? $replacer;
}
}
}
Expand Down Expand Up @@ -1402,13 +1411,14 @@ private function _remove_evil_attributes($str)
do {
$count = $temp_count = 0;

$str = (string) \preg_replace(
$tmp = \preg_replace(
'/(<[^>]+)(?<!\p{L})(style\s*=\s*"(?:[^"]*?)"|style\s*=\s*\'(?:[^\']*?)\')/iu',
'$1' . $this->_replacement,
$str,
-1,
$temp_count
);
$str = $tmp ?? $str;
$count += $temp_count;
} while ($count);
}
Expand Down