@@ -237,6 +237,7 @@ def quickSetScore
237237 # find existing score for this problem, if there's one
238238 # otherwise, create it
239239 score = Score . find_or_initialize_by_submission_id_and_problem_id ( sub_id , prob_id )
240+ return head :forbidden unless submission_belongs_to_current_course ( score . submission )
240241
241242 score . grader_id = @cud . id
242243 score . score = params [ :score ] . to_f
@@ -266,6 +267,7 @@ def quickSetScoreDetails
266267 # find existing score for this problem, if there's one
267268 # otherwise, create it
268269 score = Score . find_or_initialize_by_submission_id_and_problem_id ( sub_id , prob_id )
270+ return head :forbidden unless submission_belongs_to_current_course ( score . submission )
269271
270272 score . grader_id = @cud . id
271273 score . feedback = params [ :feedback ]
@@ -286,6 +288,7 @@ def quickSetScoreDetails
286288
287289 def submission_popover
288290 submission = Submission . find_by ( id : params [ :submission_id ] . to_i )
291+ return head :forbidden unless submission_belongs_to_current_course ( submission )
289292 if submission
290293 render partial : "popover" , locals : { s : submission }
291294 else
@@ -300,6 +303,7 @@ def score_grader_info
300303 redirect_to action : :show
301304 return
302305 end
306+ return head :forbidden unless submission_belongs_to_current_course ( score . submission )
303307
304308 grader = ( if score then score . grader else nil end )
305309 grader_info = ""
@@ -321,8 +325,10 @@ def quickGetTotal
321325
322326 # get submission and problem IDs
323327 sub_id = params [ :submission_id ] . to_i
328+ submission = Submission . find ( sub_id )
329+ return head :forbidden unless submission_belongs_to_current_course ( submission )
324330
325- render plain : Submission . find ( sub_id ) . final_score ( @cud )
331+ render plain : submission . final_score ( @cud )
326332 end
327333
328334 def statistics
@@ -538,4 +544,13 @@ def load_gradesheet_data
538544 @submissions = cache . latest_submissions . values
539545 @section_filter = params [ :section ]
540546 end
547+
548+ def submission_belongs_to_current_course ( submission )
549+ # Returns true if the provided submission belongs to the current @course, false otherwise.
550+ # This is used to ensure a user can only view or modify scores in courses where they have
551+ # permission, since the `action_auth_level ***, :course_assistant` only verifies that they're
552+ # a CA for the course in the URL. It doesn't verify that the score they're trying to modify
553+ # is in a course they're a CA in.
554+ submission . course_user_datum . course == @course
555+ end
541556end
0 commit comments