-
Notifications
You must be signed in to change notification settings - Fork 5
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
Very weak access control #15
Comments
Your AJAX handlers should make use of $USER and |
Added checks for sesskey and $USER in toggle, visible, favorite, sort files as follows: |
I do not understand what is the point of |
$USER->id is now being used instead of $userid=requried_param('userid', PARAM_INT) on master branch. Currently cannot get require_sesskey() to work, as it causes the following issue: Post: 404 (not found) on line 58 of jquery-1.9.1.min.js when put in the sort.php file, or any file attempting to make database changes to the block. |
Currently confirm_sesskey() and require_sesskey() with no parameters passed to the functions cause 404 errors. However it seems to work when confirm_sesskey($USER->sesskey) is used. |
404? that's weird is not it? |
Hi David, I made a post in the moodle dev forum a while back asking about this. I included a guess as to why it might be giving a 404 error: https://moodle.org/mod/forum/discuss.php?d=325690 Do you think this might be a bug? Thanks! |
I think this is starting to make more sense. I've updated both visible.php and sort.php on the devel branch, still working on implementing it in favorite.php. These files now make use of confirm_sesskey() with the sesskey passed in the courses.js file. |
The sesskey check is now working in visible, sort and favorite php files, code is up to date on devel branch. |
javascript handlers should now be secure passing sesskey() over HTTPS |
I don't think this is a correct fix. The code like
if wrong for several reasons:
As said above, I believe you should simply use |
HI David, |
Ok, I've changed it to require_sesskey() as you suggested. I've uploaded it to the devel branch, and will merge with master shortly. |
Master branch now up to date, closing issue. |
This issue does not appear to be fixed per @mudrd8mz . We may need to reevaluate the permissions system for this plugin to figure out if there's an alternative solution that will work properly with Ajax. @Syxton --do you know the best practice for incorporating Moodle permissions checks with ajax calls? |
I am looking at the latest version of sort.php and comparing it to lib/ajax/blocks.php. The only real difference I see is that sort.php calls !isloggedin() and the other example says require_login(). Using the $USER variable was the most important change along with sending the sessionkey via ajax param to confirm on the backend. The only other thing we could possibly do is have a permission check, to be sure the user making the request has permission to perform each action. However, this should probably be done before the user sees an (edit, move, hide, collapse, favorite) icon / link in the first place. But the user is already limited to only their own content, and each user has been given full control over their own list. So while these permissions could be added to allow for certain users to be prevented from using certain features, I don't see it as necessary for security reasons. After looking at the code and the comments, I'm unsure exactly what else needs to be done. It seems that the recommendations have been met. |
Thanks for taking a look. We thought it looked fine as well but @mudrd8mz sent me a PM on the moodle forums saying that after his last look at the code, it still didn't look like it had been fixed. I'll try to get him to read your message to see if he can offer any other feedback or if maybe he thinks it is actually okay to go. It'd be really nice to finally get this dang thing in the plugin database. |
I believe we used !isloggedin() because the require_login() kept giving us 404 errors when sending post data to the ajax handlers. |
Thanks guys for working on these improvements. I agree it looks much better than it was before. I did not manage to find the relevant messages regarding this, but I believe it was related to those parts that @Syxton refers to in
That is essential part of Moodle security and is even highlighted at https://docs.moodle.org/dev/Plugin_contribution_checklist#Security
As far as I can see, there is no way in your code to control who can actually use it. Most Moodle features can be granularly configured via capabilities and roles. So that was the part I was referring to. Anyway, in this particular case I can understand it may be seen as a missing feature that would be added in the future. The essential problems reported initially here seem to be fixed. |
Scripts like visible.php, favorite.php sort.php and others have very weak access control.
The only check you do is
isloggedin()
. Since then, you blindly rely on the passed parameters like$userid
. As a result, any logged in user can change the setting of the block of any other user.There is no protection against CSRF via sesskey.
As I understand it, these scripts are actually server side handlers for AJAX requests. Note the documentation on the recommended way to implement such scripts - e.g. https://docs.moodle.org/dev/AJAX_pre_2.9
The text was updated successfully, but these errors were encountered: