Secure progress and leaderboard endpoints#1023
Open
tanvishdesai wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Security: protect progress mutation and leaderboard endpoints
Summary
This PR tightens two progress-related endpoints:
leaderboard/no-authroute into an authenticated compatibility alias and removes email exposure from the no-auth response shape/service path.Where the problem was
backend/src/modules/users/controllers/ProgressController.tsPOST /users/progress/watch-time/bulkGET /users/progress/courses/:courseId/versions/:versionId/leaderboard/no-authbackend/src/modules/users/classes/validators/ProgressValidators.tsbackend/src/modules/users/services/ProgressService.tsRoot cause
The bulk watch-time endpoint was a mutation route without
@Authorized()and without a CASL ability check. It acceptedcourseId,versionId, anduserIdfrom the request body and delegated directly tocreateBulkWatchiTimeDocs.The leaderboard route was explicitly labelled as a temporary no-auth endpoint. Its service path loaded user records and returned names and email addresses in leaderboard rows.
Redacted vulnerable shape before this change:
Risk
An unauthenticated mutation endpoint can allow progress/watch-time records to be created without a verified actor or permission context. This can affect learner progress integrity and course completion records.
The public leaderboard route can expose private learner metadata and allows course participation data to be enumerated without login.
What changed
@Authorized()toPOST /progress/watch-time/bulk.courseId/versionIdvalidation guard.@Ability(getProgressAbility)and requireability.can('manage', subject('Progress', ...))before backfilling watch-time records.@Authorized()to the deprecatedleaderboard/no-authroute.getLeaderboardservice method.myStats.emailfromLeaderboardNoAuthResponse.getLeaderboardNoAuthso the legacy service path is also sanitized if it is accidentally used elsewhere.Why this fixes it
The bulk endpoint now requires a logged-in actor and applies the same course-scoped permission model already used by the progress controller. Students keep normal self-progress capabilities, but cannot call the maintenance backfill operation because it requires
manageon the course progress subject.The deprecated leaderboard route remains available for compatibility, but it now requires authentication and returns the same privacy-preserving shape as the normal leaderboard endpoint.
Both leaderboard routes now require the requester to have
viewormanagepermission on the requested course/version progress subject, preventing an arbitrary logged-in user from enumerating another course's leaderboard.Safe validation plan
Run these checks only against a local development instance or an authorized staging environment:
POST /users/progress/watch-time/bulkshould return401 Unauthorized.403 Forbidden.401 Unauthorized.403 Forbidden.emailfield in any row.Files changed
backend/src/modules/users/controllers/ProgressController.tsbackend/src/modules/users/classes/validators/ProgressValidators.tsbackend/src/modules/users/services/ProgressService.ts