Prevent overwriting jQuery and other common scripts

- Block third-party programs trying to load their own version of jQuery
- Block obsolete scripts such as xe.css and xe.js
- Block minified versions of the above, too
- Increase blocking index threshold from 1,500,000 to 1,500,000,000
- Add unit tests for script blocking
This commit is contained in:
Kijin Sung 2017-07-02 00:36:19 +09:00
parent 99cc64163f
commit 21072195c0
3 changed files with 74 additions and 17 deletions

View file

@ -93,12 +93,27 @@ class FrontEndFileHandler extends Handler
{
$args = array($args);
}
$args[0] = preg_replace(array_keys(HTMLDisplayHandler::$replacements), array_values(HTMLDisplayHandler::$replacements), $args[0]);
$isCommon = preg_match(HTMLDisplayHandler::$reservedCSS, $args[0]) || preg_match(HTMLDisplayHandler::$reservedJS, $args[0]);
if($args[3] > -1500000 && $isCommon)
// Replace obsolete paths with current paths.
$args[0] = preg_replace(array_keys(HTMLDisplayHandler::$replacements), array_values(HTMLDisplayHandler::$replacements), $args[0]);
$isCommon = preg_match(HTMLDisplayHandler::$reservedCSS, $args[0]) || preg_match(HTMLDisplayHandler::$reservedJS, $args[0]);
// Prevent overwriting common scripts.
if(intval($args[3]) > -1500000000)
{
return;
}
if($isCommon)
{
return;
}
foreach(HTMLDisplayHandler::$blockedScripts as $regexp)
{
if(preg_match($regexp, $args[0]))
{
return;
}
}
}
$file = $this->getFileInfo($args[0], $args[2], $args[1], $args[4], $isCommon);
$file->index = (int)$args[3];