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

Improve exam mode security #9743

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

nwalters512
Copy link
Contributor

This PR closes an unlikely and obscure access issue where we allowed a student with a checked-in PrairieTest reservation to access Exam-mode assessment without an exam_uuid. This behavior existed to support the legacy exam_mode_networks functionality.

Now, we propagate the reason we consider a user to be in Exam mode so that we can use that to determine if we should allow access to assessments with out exam_uuid:

  • If we're in Exam mode because of PrairieTest, block access to assessments without exam_uuid.
  • If we're in Exam mode for any other reason, fall back to normal access checks that don't consider exam_uuid.

As discussed on #1974.

Copy link
Contributor

github-actions bot commented Apr 18, 2024

All images

Image Platform Old Size New Size Change
prairielearn/executor:43179420bbe36aafced60a830acd7a2784372077 null 1645.00 MB 1645.00 MB -0.00%
prairielearn/prairielearn:43179420bbe36aafced60a830acd7a2784372077 linux/amd64 1645.01 MB 1645.00 MB -0.00%

@@ -348,6 +350,9 @@ export async function authzCourseOrInstance(req, res) {
res.locals.is_administrator = res.locals.authz_data.is_administrator;

res.locals.authz_data.mode = effectiveParams.req_mode;
res.locals.authz_data.mode_reason = req.cookies.pl_requested_mode
? 'Requested'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I need to think a little more about what values we want to use when overrides are in place.

I think our handling of mode above on line 352 is actually a little weird. effectiveParams.req_mode takes into account req.cookies.pl_requested_mode, but in this branch, we specifically don't want to take that into account, does that sound right? Or... now that I think about this, I think we actually need this to take into account the cookie so that instructorEffectiveUser can display the effective mode. 🥴

coalesce($req_mode, (access_mode.mode)) AS mode,
(
CASE
WHEN $req_mode IS NOT NULL THEN 'Override'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤷 we could also leave this as NULL? We really only care whether or not the value is PrairieTest; what the "or not" value is doesn't really matter.

Comment on lines +3 to +9
access_mode AS (
SELECT
mode,
mode_reason
FROM
ip_to_mode ($ip, $req_date, $user_id)
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could also just join on ip_to_mode?

course_role: 'None',
course_instance_role: 'None',
user_id: '1000',
uid: 'valid@example.com',
date: '2010-07-07 06:06:06-00',
display_timezone: 'US/Central',
});
assert.isTrue(authorized);
assert.isFalse(authorized);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a change in behavior. Is it desirable? I think so! My guess is that this test meant to test an Exam-mode assessment that wasn't linked to a PT exam at all. We could always add another test for that? Though I'm pretty sure this is already covered by the "without PrairieTest" block above.

Copy link

codecov bot commented May 17, 2024

Codecov Report

Attention: Patch coverage is 64.70588% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 66.43%. Comparing base (6cf6a1e) to head (4317942).

Files Patch % Lines
apps/prairielearn/src/ee/lib/terms.ts 16.66% 5 Missing ⚠️
...irielearn/src/middlewares/authzCourseOrInstance.js 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9743      +/-   ##
==========================================
- Coverage   66.43%   66.43%   -0.01%     
==========================================
  Files         453      453              
  Lines       70289    70301      +12     
  Branches     5648     5649       +1     
==========================================
+ Hits        46694    46701       +7     
- Misses      23170    23178       +8     
+ Partials      425      422       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

None yet

1 participant