MDL-69028 repository: Put a rate limit on draft file uploads

This commit is contained in:
Shamim Rezaie 2020-09-10 11:57:34 +10:00 committed by Jenkins
parent 5b7d2a1992
commit c4e993d546
7 changed files with 168 additions and 1 deletions

View file

@ -334,6 +334,11 @@ case 'download':
unlink($thefile['path']);
print_error('maxareabytes');
}
// Ensure the user does not upload too many draft files in a short period.
if (file_is_draft_areas_limit_reached($USER->id)) {
unlink($thefile['path']);
print_error('maxdraftitemids');
}
try {
$info = repository::move_to_filepool($thefile['path'], $record);
redirect($home_url, get_string('downloadsucc', 'repository'));

View file

@ -309,6 +309,10 @@ switch ($action) {
if (file_is_draft_area_limit_reached($itemid, $areamaxbytes, filesize($downloadedfile['path']))) {
throw new file_exception('maxareabytes');
}
// Ensure the user does not upload too many draft files in a short period.
if (file_is_draft_areas_limit_reached($USER->id)) {
throw new file_exception('maxdraftitemids');
}
$info = repository::move_to_filepool($downloadedfile['path'], $record);
if (empty($info)) {

View file

@ -199,6 +199,10 @@ class repository_upload extends repository {
if (file_is_draft_area_limit_reached($record->itemid, $areamaxbytes, filesize($_FILES[$elname]['tmp_name']))) {
throw new file_exception('maxareabytes');
}
// Ensure the user does not upload too many draft files in a short period.
if (file_is_draft_areas_limit_reached($USER->id)) {
throw new file_exception('maxdraftitemids');
}
$record->contextid = $context->id;
$record->userid = $USER->id;