-
-
Notifications
You must be signed in to change notification settings - Fork 165
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
Add an authentication session. #2334
Add an authentication session. #2334
Conversation
1fc5c48
to
885811d
Compare
0775adf
to
c40b9e7
Compare
ed7461d
to
b97e361
Compare
This is a stopgap measure since this is already fixed in openwebwork#2334, but this was missed in openwebwork#2333. openwebwork#2334 completely rewrites this module.
This is a stopgap measure since this is already fixed in openwebwork#2334, but this was missed in openwebwork#2333. openwebwork#2334 completely rewrites this module.
b97e361
to
710e7d3
Compare
I have read the description of this and I mostly understand it, and it sounds good. I skimmed the code changes, but ttbh I was just looking for typos and not trying to follow the code. I am reluctant to actually test this because I'd need to alter the key tables for all courses, and then alter them back later. But am I overthinking it? Is it actually pretty risk-free to do drop the set_id column? |
You can test this without dropping the That is all assuming you aren't testing this on a production server (hopefully not). |
710e7d3
to
3ba2fc7
Compare
If I had |
Yeah, that is expected behavior. That is the same as with the develop branch currently as well, and I believe it works that way with 2.18 and before as well. Note that What is happening when you change the setting from "session_cookie" to "key" is that the cookie is still there. So it thinks it is supposed to "Remember Me" and gets the session key from the cookie. Thus continuing the session. Note that the other way around will also (somewhat) work. If you set Note that the session will not really be entirely preserved with this pull request. Only the "user_id" and "key" columns in the database are actually shared between the two sessions. When using a "session_cookie" the rest of the session is in the cookie, and when using the "key" management approach the session is saved in the database. So there are things that would get messed up if this change is made on a production server. So I would not recommend making this type of change on a production server, particularly once courses are in progress. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked out the branch and tried logging into courses under both session management options, and I had no issues. Is there anything I should specifically test?
If you have a way to test LTI authentication for a student with the Also test proctor authentication. That uses the session as well. There is no proctor key in the database anymore. The proctor authentication module is completely rewritten. |
This requires another change to the `key` table. The `set_id` column has been removed, and in its place is a `session` key. This column is a JSON column and holds all session values. Note there are really two sessions that can be used. A cookie session (for this the Mojolicious session is used) or a database session. Which is used is determined by the `manage_session_via` course environment setting. The database session works by saving a hash in the stash key named 'webwork2.database_session'. This hash is saved to the database in the `after_dispatch` hook. This means that regardless of which session is used, session values can be set anytime after the session is created in authentication and before the `after_dispatch` hook is called. That is pretty much at anytime in a content generator module. Do not directly use the `Mojolicious::Controller::session` method (which will only set cookie session values) except in the authentication modules. Instead call the `WeBWorK::Authen::session` method which takes care of setting the values for the correct session type (database or cookie). One value the session now holds is what the `set_id` column stored before. In addition proctor authentication is completely reworked. Instead of the hack to use a separate proctor key, session values are used. There are some additional security measures implemented to make it harder for a student to hijack the session and gain access to a test after a proctoring session without having submitted the test as observed in openwebwork#2243 and openwebwork#2244. First, the proctor username and password (and the submit button) must come from a POST request. Parameters from a GET request are ignored for these things. It is a little harder to construct a POST request than a GET request. Second, the data saved in the session is specific to the set and version. So it is not possible for a student to open a new version of a test anymore, only to regain access to the version that was being worked. Third, the proctor_user is no longer saved in a hidden field in the GatewayQuiz form. If proctor authorization has been granted, then the authorization is saved in the session, and so the proctor_user is not needed. Some of the derived authentication modules will need some changes to work with this. Of course the LTIAdvantage, LTIAdvanced, and Proctor modules have already been changed and tested. Looking at the LDAP and CAS code, it seems that they should still work with this, but I can't test those. Most likely Cosign, Moodle, and Shibboleth will need changes. I don't know if anyone still uses the Moodle module. They really shouldn't, and should use LTI instead. I think that module should be deleted.
…ment_via is "cookie_session". This means that the session key is not visible anywhere in the DOM or in URL parameters when using cookies for session management, and JavaScript has no access to it. This is something that malicious javascript can exploit. Of course this also means that webwork2's own javascript can't access it either. So for this to work, the rpc endpoints used by webwork2 need to have cookies enabled so that the endpoints used by the library browser and such still work. However, the html2xml endpoint still has cookies always disabled. For the render_rpc endpoint, the disableCookies parameter can be set to disable cookies. Note that an authentication module can disable cookies by setting the disable_cookies stash value. This is how the html2xml endpoint disables cookies. The Cosign and Shibboleth authentication modules have been adapted to use this as well, instead of overriding the `WeBWorK::Authen` cookie methods. In fact overriding those methods won't disable cookies anymore entirely. The Proctor authen module overrides those methods for a different reason. It does not disable cookies, but does not set the user_id, key, and timestamp authentication values in the cookie. Note that the "theme" hidden field has also been removed. That isn't even an authentication parameter, and doesn't work anyway.
3ba2fc7
to
6ded4b5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked both key and session_cookie modes of session handling.
Also, checked the proctoring--seems to work well and checked that both the set_id and the version is stored for proctor authorization.
There is a new limitation that this change introduces that I just discovered. That is the number of courses that you can be signed into at the same time for the same webwork server. This is caused by the size of the header which is increased considerably by this change, and the increase is due to cookie size. Previously the session cookie was roughly 100 bytes (and the total header size roughly 700 to 800 bytes). With this change the session cookie size is around 1500 bytes (and the total header size typically more than 2000 bytes). Mojolicious places a limit of 8192 bytes on the header size. Note that if you are signed in to multiple courses for the same domain, then the session cookies for all courses are included in all requests. So the size of the cookies are cumulative for the total header size. This means that previously you could easily sign in to 60 or more courses for the same webwork server at the same time. Now 4 is pretty much the max, and you might not be able to get that if there are other session values in the cookie (for instance once #2337 is merged cookies will temporarily grow for a single request when flash values are added). Generally, I don't think this is too much of a problem as you usually are only signed in to one or two courses at a time (and you can still easily sign in to 3 at a time, and maybe another). However, if you sign into one course, and close the tab or window without signing out, then the cookie is still there and will affect the limit when signing into other courses. So if you often use more than one webwork course from the same server, you will want to remember to sign out. If it is still a problem, the limit can be increased. For Mojolicious (and hypnotoad or morbo) this can be increased using the This is another downside of webwork2's structure with courses being separate instances. However, from the browser standpoint, they aren't since they all share the same domain. Note that technically the webwork2 path limits what is included as well. So cookies that are dedicated to another path (like By the way, once this limit is exceeded you will end up being kicked out of first course that tries to make a request such that the header exceeds the size limit. If serving directly you will see errors such as |
Can you point me in the right direction to delete cookies I need to delete after hitting this issue? This got me thinking about something like a computer in a student computer lab. How likely is it that this will become a problem in that environment? |
Do the students log into a university account in this computer lab? It is rather rare that computer labs on institution campuses don't require that students sign in to their institution account. If they are signed in to an account like that they don't use the same browser sessions. So it won't affect them. The cookies that one user has in their browser session won't show up in another user's browser session. If these computers are truly public workstations that anyone can just walk in and use, and students are not signing out ... then we have a problem. That is a massive security vulnerability. However, then the session limitation would become a problem. |
To delete cookies for a specific site, I use the developer tools. In Firefox this is under the "Storage" tab in the developer tools. Select "Cookies" under that, and then the domain, and then all cookies are listed. You can right click on one to delete it. In Chrome cookies are under the "Application" tab. The interface is the same as for Firefox though. |
What you say about computer labs makes sense, students do have to sign in to something like Windows365 (or something like that, I'm not sure what it actually is called.)
Here is a rare but not impossible scenario. Am instructor manages separate WW courses for homework and quizzes (to help shut off access to homework during a proctored quiz). In a classroom, a student signs into the homework course for review before a quiz. Then into the quiz course because the class is starting the quiz. Then there is a login_proctor login, and then at the end the actual proctor (the instructor?) gives credentials for grading to commence. Do those last two sign-ins create cookies? |
Proctor authentication no longer uses cookies at all. So no, that is not a problem. |
Proctor authentication uses the user's session. So that is all in the first cookie. |
This requires another change to the
key
table. Theset_id
column has been removed, and in its place is asession
key. This column is a JSON column and holds all session values.Note there are really two sessions that can be used. A cookie session (for this the Mojolicious session is used) or a database session. Which is used is determined by the
manage_session_via
course environment setting.The database session works by saving a hash in the stash key named 'webwork2.database_session'. This hash is saved to the database in the
after_dispatch
hook. This means that regardless of which session is used, session values can be set anytime after the session is created in authentication and before theafter_dispatch
hook is called. That is pretty much at anytime in a content generator module. Do not directly use theMojolicious::Controller::session
method (which will only set cookie session values) except in the authentication modules. Instead call theWeBWorK::Authen::session
method which takes care of setting the values for the correct session type (database or cookie).One value the session now holds is what the
set_id
column stored before.In addition proctor authentication is completely reworked. Instead of the hack to use a separate proctor key, session values are used. There are some additional security measures implemented to make it harder for a student to hijack the session and gain access to a test after a proctoring session without having submitted the test as observed in #2243 and #2244. First, the proctor username and password (and the submit button) must come from a POST request. Parameters from a GET request are ignored for these things. It is a little harder to construct a POST request than a GET request. Second, the data saved in the session is specific to the set and version. So it is not possible for a student to open a new version of a test anymore, only to regain access to the version that was being worked. Third, the proctor_user is no longer saved in a hidden field in the GatewayQuiz form. If proctor authorization has been granted, then the authorization is saved in the session, and so the proctor_user is not needed.
Some of the derived authentication modules will need some changes to work with this. Of course the LTIAdvantage, LTIAdvanced, and Proctor modules have already been changed and tested. Looking at the LDAP and CAS code, it seems that they should still work with this, but I can't test those. Most likely Cosign, Moodle, and Shibboleth will need changes. I don't know if anyone still uses the Moodle module. They really shouldn't, and should use LTI instead. I think that module should be deleted.
The session key is no longer saved in a hidden field in forms when session_management_via is "cookie_session". This means that the session key is not visible anywhere in the DOM or in URL parameters when using cookies for session management, and JavaScript has no access to it. This is something that malicious javascript can exploit. Of course this also means that webwork2's own javascript can't access it either. So for this to work, the rpc endpoints used by webwork2 need to have cookies enabled so that the endpoints used by the library browser and such still work. However, the html2xml endpoint still has cookies always disabled. For the render_rpc endpoint, the disableCookies parameter can be set to disable cookies.
Note that an authentication module can disable cookies by setting the disable_cookies stash value. This is how the html2xml endpoint disables cookies. The Cosign and Shibboleth authentication modules have been adapted to use this as well, instead of overriding the
WeBWorK::Authen
cookie methods. In fact overriding those methods won't disable cookies anymore entirely. The Proctor authen module overrides those methods for a different reason. It does not disable cookies, but does not set the user_id, key, and timestamp authentication values in the cookie.Note that the "theme" hidden field has also been removed. That isn't even an authentication parameter, and doesn't work anyway.
This builds on #2333, and is part 2 of 3 of the authentication system revamp.