Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent protected files from being modified by unprivileged users. #2430

Merged

Conversation

drgrice1
Copy link
Member

By "protected files" I mean the files listed in the $uneditableCourseFiles list in the course environemt that is originally defined in defaults.config. This usually contains the files course.conf and simple.conf.

As before, only users with the "edit_restricted_files" permission can edit these files. The only change here is that Mojo::File::realpath is used instead of the File::Spec::canonpath. This is a more reliable method since it properly resolves to a path without .. (canonpath does not do this). It is possible to use .. to create a filename that wouild still resolve to one of the protected files. For instance, templates/../course.conf could be used to overwrite course.conf. The canonpath method would not correctly realize that those are the same file paths.

If a user that does not have the permission to "edit_restricted_files", and the user attempts to upload a file in the list, then the user will be forced to choose a new name for the upload, or cancel. The overwrite option will not be given. Users with the "edit_restricted_files" permission can still overwrite the file.

If a user that does not have the permission to "edit_restricted_files" extracts an archive that would overwrite a file in the list, then that file will be skipped and will not be extracted. A message will notify the user that this file from the archive is not extracted.

Deletion or renaming of one of the files in the list is not allowed. Not even for users that have the "edit_restricted_files" permission. These files are required, and there is no reason that this should ever be done.

Finally, required course directories (all directories in the courseDirs hash in the course environment) are not allowed to be deleted or renamed by any user. These directories are required, and so there is not reason that even a user with the "edit_restricted_files" permission should be allowed to do this.

This is intended to resolve discussion #2427.

Copy link
Contributor

@Alex-Jordan Alex-Jordan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested all the things mentioned in the description and they all work.

@drgrice1 drgrice1 force-pushed the file-manager-protected-files branch 2 times, most recently from 1a405b3 to b8a7fb8 Compare June 13, 2024 02:52
@drgrice1
Copy link
Member Author

I added a second commit to this that addresses #2437. I also slightly tweaked how protected file uploads are handled. Instead of just refusing to do it, it now gives the user a chance to rename it.

@drgrice1 drgrice1 force-pushed the file-manager-protected-files branch 3 times, most recently from 2595912 to 9a571ad Compare June 25, 2024 19:13
@drgrice1 drgrice1 force-pushed the file-manager-protected-files branch from 9a571ad to 82b855a Compare July 2, 2024 19:38
@drgrice1 drgrice1 force-pushed the file-manager-protected-files branch from 82b855a to 1b2b9bf Compare July 23, 2024 22:19
drgrice1 added 2 commits July 30, 2024 13:13
By "protected files" I mean the files listed in the
`$uneditableCourseFiles` list in the course environemt that is
originally defined in `defaults.config`.  This usually contains the
files `course.conf` and `simple.conf`.

As before, only users with the "edit_restricted_files" permission can
edit these files.  The only change here is that `Mojo::File::realpath`
is used instead of the `File::Spec::canonpath`.  This is a more reliable
method since it properly resolves to a path without `..` (canonpath does
not do this). It is possible to use `..` to create a filename that
wouild still resolve to one of the protected files.  For instance,
`templates/../course.conf` could be used to overwrite `course.conf`.
The canonpath method would not correctly realize that those are the
same file paths.

If a user that does not have the permission to "edit_restricted_files",
and the user attempts to upload a file in the list, then the user will
be forced to choose a new name for the upload, or cancel.  The overwrite
option will not be given.  Users with the "edit_restricted_files"
permission can still overwrite the file.

If a user that does not have the permission to "edit_restricted_files"
extracts an archive that would overwrite a file in the list, then that
file will be skipped and will not be extracted.  A message will notify
the user that this file from the archive is not extracted.

Deletion or renaming of one of the files in the list is not allowed.
Not even for users that have the "edit_restricted_files" permission.
These files are required, and there is no reason that this should ever
be done.

Finally, required course directories (all directories in the
`courseDirs` hash in the course environment) are not allowed to be
deleted or renamed by any user.  These directories are required, and so
there is not reason that even a user with the "edit_restricted_files"
permission should be allowed to do this.
invalid file names, rather than attempting to fix and return a workable
file name.

Also, instead of just giving a message if a user attempts to upload a
protected file, give the user a chance to rename it.
@drgrice1 drgrice1 force-pushed the file-manager-protected-files branch from 1b2b9bf to 165fa8e Compare July 30, 2024 18:13
@Alex-Jordan Alex-Jordan merged commit e144640 into openwebwork:WeBWorK-2.19 Jul 30, 2024
2 checks passed
@drgrice1 drgrice1 deleted the file-manager-protected-files branch July 30, 2024 21:56
@Alex-Jordan
Copy link
Contributor

The changes to checkName here are related to #2487. It seems checkName is used two places outside of this file that will need adjustment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants