Issue Details (XML | Word | Printable)

Key: MDL-11905
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Tim Hunt
Reporter: Jamie Pratt
Votes: 0
Watchers: 2
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

user may not have access to quiz backup course files area when exporting questions

Created: 25/Oct/07 06:08 PM   Updated: 08/Jul/08 07:24 PM
Return to search
Component/s: Questions, Quiz
Affects Version/s: 1.9
Fix Version/s: 1.9.2

File Attachments: 1. Text File 1.9_question_export.patch.txt (9 kB)
2. Text File send_temp_file2.patch (3 kB)


Participants: Eloy Lafuente (stronk7), Jamie Pratt, Petr Skoda and Tim Hunt
Security Level: None
Resolved date: 08/Jul/08
Affected Branches: MOODLE_19_STABLE
Fixed Branches: MOODLE_19_STABLE


 Description  « Hide
When a user has the moodle/question:view capability for a question, they can export it. However, unless they also have have moodle/site:backup, they will not be able to download the exported file which is saved in the backupdata area of course files. (this is because normally, you don't want students to be able to download questions.

 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Tim Hunt added a comment - 10/Mar/08 08:24 PM
My suggested fix for this is as follows:

Around line 77 of file.php, where it says:

// security: only editing teachers can access backups
if (!has_capability('moodle/site:backup', ...

And an "or has_capability('moodle/question:view', ...". This will let people download question export files they have created. However, we will not change file/index.php, so that still only people with moodle/site:backup will be able to browse that folder.

This is not properly secure because it will let people with moodle/question:view download course backups, if they can guess the file name. However, those file names are hard to guess.

I was going to say that I did not think this was a very big security risk, because file accesses are logged, so if someone is naughty, we can catch them. However, now I look, I find that they are not logged. Weird. Sam wrote some code to log file accesses in our code. I told him to put a patch in the tracker.

Of course, in Moodle 2.0, we will be able to fix this securely with the repository API, using the access control lists it provides, but I think it is important to get this fixed in 1.9.x

Petr, please can you review this suggestion with your security hat on. Thanks.


Tim Hunt added a comment - 10/Mar/08 11:11 PM
Actually, we can do a better job than this. Quiz exports are actually stored in /backupdata/quiz, so we just need to allow download from there if the user has moodle/question:view, and security is much less of a problem.

Eloy Lafuente (stronk7) added a comment - 11/Mar/08 09:50 AM
Yup. I think separate dirs is definitively better! In fact, if they are disjoint dirs... BETTER. FYC.

Ciao


Tim Hunt added a comment - 11/Mar/08 07:13 PM
Well the directory names are just what the code currently uses, and I don't really want to change it - at least until we move to the repository API. Changing would probably just confuse users on a stable branch.

Petr Skoda added a comment - 11/Mar/08 08:26 PM
my 10 for this it is IMO a major security problem, backup contains very sensitive info including password hashes, preventing browsing is definitely not enough because the filenames are in expected format

I think there should be a different folder for this


Petr Skoda added a comment - 12/Mar/08 06:41 AM
sending a patch with send_temp_file() that we discussed today..

Petr Skoda added a comment - 12/Mar/08 06:47 AM
the idea is to create the export file in moodledata/temp/export/quiz/userid/something and use send_temp_file() which deletes the file after sending to user,
benefits are:
  • we no not have to care about security much
  • no wasting of space in moodledata
  • simple use in various export scripts

Tim Hunt added a comment - 12/Mar/08 08:19 AM
Looks good to me. Please can we put this in 1.9 and 2.0, then I will do the rest.

Tim Hunt added a comment - 12/Mar/08 08:29 AM
Oh, just one other thought. To make it even easier for developers, should we make another function something like

get_temp_file_name($mod, $userid = 0) {\
global $CFG, $USER;
if (!$userid) {
$userid = $USER->id;
}
$folder = "$CFG->dataroot/temp/export/$mod/$userid";
ensure_directory_exists($folder);
return tempnam($folder, '');

(Sorry can't remember if our function is actually called ensure_directory_exists.)


This whole scheme will leave lots of empty directories lying around?


Tim Hunt added a comment - 23/Apr/08 11:45 PM
Petr, where have we got to with this? What is preventing us from committing your patch? Thanks.

Petr Skoda added a comment - 05/Jul/08 11:35 PM
send temp file support in cvs

Tim Hunt added a comment - 08/Jul/08 12:41 AM
OK, the attached patch should finish off this bug. The patch is against 1.9 stable. Please can you review it, and in particular say whether you think this should go in before or after 1.9.2.

It does not change behaviour for people with 'moodle/site:backup' capability. For people without it, it saves the export file in a temporary area, and automatically starts the download using JavaScript with a fallback link, via a new question/exportfile.php stript.

Some security is provided because the temp file name contains the $USER->id, but the question/exportfile.php URL does not.

If this does go in to 1.9.2, I will merge it to head, and file a new track issue to re-write this bit of code using the file API, once that is done.


Petr Skoda added a comment - 08/Jul/08 06:56 AM
seems ok, +1 for commit,
I am really looking forward to the new file API that should solve all these problems nicely

thanks


Tim Hunt added a comment - 08/Jul/08 07:24 PM
Note that once the Files API is finished, this fix will need to be redone. I have created MDL-15573 to track that.