MDL-71922 file: Enhance endless recursion requests protection
This commit is contained in:
committed by
Eloy Lafuente (stronk7)
parent
9aa5f7fe9b
commit
9b758d5cc8
+14
-1
@@ -36,7 +36,11 @@ require_once(__DIR__.'/locallib.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class repository_url extends repository {
|
||||
/** @var int Maximum time of recursion. */
|
||||
const MAX_RECURSION_TIME = 5;
|
||||
var $processedfiles = array();
|
||||
/** @var int Recursion counter. */
|
||||
var $recursioncounter = 0;
|
||||
|
||||
/**
|
||||
* @param int $repositoryid
|
||||
@@ -127,7 +131,16 @@ EOD;
|
||||
$url = htmlspecialchars_decode(url_to_absolute($baseurl, $relativeurl));
|
||||
}
|
||||
if (in_array($url, $this->processedfiles)) {
|
||||
// avoid endless recursion
|
||||
// Avoid endless recursion for the same URL with same parameters.
|
||||
return;
|
||||
}
|
||||
// Remove the query string before check.
|
||||
$recursioncheckurl = preg_replace('/\?.*/', '', $url);
|
||||
if (in_array($recursioncheckurl, $this->processedfiles)) {
|
||||
$this->recursioncounter++;
|
||||
}
|
||||
if ($this->recursioncounter >= self::MAX_RECURSION_TIME) {
|
||||
// Avoid endless recursion for the same URL with different parameters.
|
||||
return;
|
||||
}
|
||||
$this->processedfiles[] = $url;
|
||||
|
||||
Reference in New Issue
Block a user