Skip to content

Commit

Permalink
MDL-59681 file: Stop recursive file serving
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanheywood committed Mar 21, 2022
1 parent 0d0f09b commit 34efb9a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/filelib.php
Expand Up @@ -2678,6 +2678,8 @@ function send_file($path, $filename, $lifetime = null , $filter=0, $pathisstring
function send_stored_file($stored_file, $lifetime=null, $filter=0, $forcedownload=false, array $options=array()) {
global $CFG, $COURSE;

static $recursion = 0;

if (empty($options['filename'])) {
$filename = null;
} else {
Expand Down Expand Up @@ -2721,6 +2723,13 @@ function send_stored_file($stored_file, $lifetime=null, $filter=0, $forcedownloa

// handle external resource
if ($stored_file && $stored_file->is_external_file() && !isset($options['sendcachedexternalfile'])) {

// Have we been here before?
$recursion++;
if ($recursion > 10) {
throw new coding_exception('Recursive file serving detected');
}

$stored_file->send_file($lifetime, $filter, $forcedownload, $options);
die;
}
Expand Down

0 comments on commit 34efb9a

Please sign in to comment.