security problem

security problem

by Abigail Barzilai -
Number of replies: 12
Hi,

I found out that  students can type a link with a name of a file (from the file directory) and get the file even though  we did not make the file available via "resource".  As far as I know, the system manual does not say anything about this problem .

Please help!


Abigail
 

Average of ratings: -
In reply to Abigail Barzilai

Re: security problem

by Ken Wilson -

Hi Abigail

I've tried to replicate this. The way I've done it is by making a directory available - and so students can copy and paste the link to the file, even though it has not been added to the resource list on the course page. Is this what you mean?

Ken

In reply to Ken Wilson

Re: security problem

by Abigail Barzilai -
Dear Ken,
Thanks a lot for your immediate reply.
I think I did not make myself clear.
What I meant was that students can access a file from the files in the administration block even though it has not been added to the resource list on the course page. I do'nt want the student to be able to do it. We have files (like solutions to exercises) that students should not see. Anyhow the access to the files
in the administration block should be to teachers only.
By writting
http://www.technion.ac.il/moodle/file.php/course_id_no/filename
they can see the file.
Any Idea?

THanks again,
Abigail

In reply to Abigail Barzilai

Re: security problem

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
If you put the file in the 'file folder' of a course, you are telling Moodle you want anyone with access to the course to be able to see and download the file in question. Think of it as a 'public file folder' for this course.

There is no need to 'publish' the file as a ressource to see and download it. One just needs to click in the 'file' icon of the course menu.

In other words, if you don't want your users to see the file, don't put it there.

Saludos. Iñaki.
In reply to Abigail Barzilai

Re: security problem

by Ken Wilson -

Hi Abigail

I understand the problem now. A couple of points:

  1. When I login as a student, I cannot see the administration block. So this means that students are copying and pasting the link to the file. This is discussed in http://moodle.org/mod/forum/discuss.php?d=26326.
  2. When I try to write the URL as http://..../file.php/course_id_no/filename, I get a 404 Not found error. So can you please check the permissions in the course folder.
  3. Moodle has a method of protecting access to files so that only teachers can see them. Try this:
    - Edit the moodle config.php and add this line before the directorypermissions line:

    $CFG->preventaccesstohiddenfiles = Yes;

    - In the course directory folder, create a folder called ".protected" (or anything as long as it has a full-stop as the first character).
    - Copy any files that you do not want students to see into this folder.

Hope this helps!

Ken

In reply to Ken Wilson

Re: security problem

by Abigail Barzilai -

Hi,

As far as I understand from the forum you directed me to, it means that the problem still exist. Do you know if there is ane intention to fix it?

It means that to use the "hide tool" is not safe.

In any case if I would like to display the protected file I will have to copy it to another directory, right?

 

Thanks again,

Abigail

 

In reply to Abigail Barzilai

Re: security problem

by Ken Wilson -

Yes. Create a protected directory as in the previous post and students will not see the files.

Ken

In reply to Ken Wilson

Re: security problem

by Abigail Barzilai -

Dear Ken,

Sorry it's me again.

I did exactly how you told me but it did not work.

Any suggestions?

 

Best,

Abigail

 

In reply to Abigail Barzilai

Re: security problem

by Ken Wilson -

Abigail

Can you please try as follows:

  1. Created a new course (testcourse)
  2. Created a test student (teststudent)
  3. Create a test teacher (testteacher)
  4. Login as testteacher. Click My Courses, Test Course, Administration, Files, Make a folder called .protected.
  5. Upload a file into this folder (you'll need to select the file and move to the .protected folder after uploading).
  6. Logout and login again as the testteacher. Select Test course, turn editing on and try to add the file in the .protected folder. You should not be able to do this.

So, this means that only staff can access the files in the .protected folder. I have not tried to copy and paste the URL of a protected file - so please try this also!

Ken

In reply to Ken Wilson

Re: security problem

by Abigail Barzilai -

Hi,

Thanks for being so patient. I did exactly what you told me.

Here is the path in my local computer

The address in the administration block : http://127.0.0.1/file.php/2/.protected/moodlep1.ppt

I was able to link this file to the course page

the address is : http://127.0.0.1/mod/resource/view.php?id=39

I entered as a student and could see the file with

http://127.0.0.1/file.php/2/.protected/moodlep1.ppt

I attached my config.php

I am curious.............

Abigail

 

 

 

In reply to Ken Wilson

Re: security problem

by Steve Hyndman -

Ken,

This doesn't work. Below is a link to a file I've uploaded to a course files area. The course is set to allow guest access and autologin guests. So, when you click on the link, it should take you directly to the file.

http://www.kentuckyclassroom.com/teacher/file.php/223/.protected/hello.pdf

Here is the link to that course

http://www.kentuckyclassroom.com/teacher/course/view.php?id=223

Also, my moodle_data directory is outside the public_html folder.

It looks like moodle allows anyone with access to a course, to have access to any file in the files directory...all the student need do is figure out the url.

I don't think this is a security problem as far as Moodle goes, but I do think this in not well understood by most people...I've been working with Moodle for a few years and I didn't understand it until this post. It seems to me that "logic" would lead a person to believe anything they placed in the files folder in the teachers administration area would only be available to teachers of that course (and site admin of course) unless they made the file available to others...but, it seems that is not the way it works. Bottom line....there is no "protected" files storage area in Moodle for teachers (at least in a default install), without maybe creating a closed course (with no students) and using that to store files.

It's logical that teachers would want to store private files in their courses....quiz keys, memos, student evaluations, etc, and it's logical that they would "assume" the files area would be a place to do that....however, as we see here, that will not work....(well, it will work, but their students could access them)

There has always been the warning that files placed in the "site files" area are available to everyone. It seems that files placed in the course files area are available to everyone in the course. This makes more sense to me now...bottom line, if a person has access to a course (and the site--frontpage of Moodle--is just another course--course 1), then they have access to all files stored in that course.

Maybe there is a way to protect a subdirectory in the files area, but it seems that placing a "." at the beginning of the directory doesn't do it.

Now, all of this could be wrong....this is just the the way I understand it from my experimenting.

Steve

In reply to Ken Wilson

Re: security problem

by Ken Wilson -

Abigail & Steve

After spending the last few days retrying this, I have to apologise and agree that it does not work.

I originally got the idea from these lines of code in edit.php:

// security: some protection of hidden resource files
// warning: it may break backwards compatibility
if ((!empty($CFG->preventaccesstohiddenfiles))
    and (count($args) >= 2)
    and (!isteacher($course->id))) {
       $reference = ltrim($relativepath, "/{$args[0]}/");
       $sql = "SELECT COUNT(r.id) " .
          "FROM {$CFG->prefix}resource r, " .
          "{$CFG->prefix}course_modules cm, " .
          "{$CFG->prefix}modules m " .
          "WHERE r.course = '{$course->id}' " .
          "AND m.name = 'resource' " .
          "AND cm.module = m.id " .
          "AND cm.instance = r.id " .
          "AND cm.visible = 0 " .
          "AND r.type = 'file' " .
          "AND r.reference = '{$reference}'";
       if (count_records_sql($sql)) {
          error('Access not allowed');
       }
}

When I tried this, it appeared to work - but I can confirm that it was an issue with the server I was using (!) Maybe a developer with greater knowledge than I have can tell me why the code does not work.

From Abigail's initial post, it seems as if this would be a good feature suggestion! Agree?

Ken