fix(lms): Validate progress writes and hide unpublished courses - #1258
Open
jeromehardaway wants to merge 6 commits into
Open
fix(lms): Validate progress writes and hide unpublished courses#1258jeromehardaway wants to merge 6 commits into
jeromehardaway wants to merge 6 commits into
Conversation
Progress POST only checked the lesson existed — not that it belonged to the enrollment's course or that the enrollment was ACTIVE, so a student could record progress on arbitrary lessons. GET /api/courses also honored ?isPublished=false for anyone. Progress now rejects (400) inactive enrollments and cross-course lessons; courses forces published-only for non-admins.
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
3 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses two LMS security/authorization gaps: preventing illegitimate progress writes and ensuring unpublished courses are not exposed to non-admin users via query parameters.
Changes:
- Tighten
POST /api/progressvalidation by requiringEnrollment.status === "ACTIVE"and ensuring the lesson belongs to the enrollment’s course. - Force
GET /api/coursesto return only published courses for non-admins, while still allowing admins to filter byisPublished. - Add Vitest coverage for both the progress-write validation and unpublished-course filtering behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/pages/api/progress/index.ts | Adds enrollment status check and cross-course lesson validation before writing progress. |
| src/pages/api/courses/index.ts | Forces isPublished=true for non-admin requests regardless of query param; admin filtering preserved. |
| tests/pages/api/progress-validation.test.ts | Adds tests for progress validation and unpublished-course leak prevention. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
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.
Problem
/api/progress) verified the enrollment belonged to the user and that the lesson existed, but not that the lesson belonged to the enrollment's course or that the enrollment was ACTIVE. A student could record progress against arbitrary lessons and against dropped/paused enrollments.isPublishedstraight from the query, so any user could pass?isPublished=falseand read unpublished courses.Fix
ACTIVE, and when the lesson'smodule.courseIddoesn't match the enrollment's course./api/coursesforceswhere.isPublished = truefor non-admins; admins may still filter.Verification
New tests (
__tests__/pages/api/progress-validation.test.ts, 5 passing): progress rejects a non-active enrollment and a cross-course lesson (no upsert), accepts a valid write; courses forcesisPublished=truefor a student even with?isPublished=false, and lets an admin filter unpublished.npm run typecheck— pass.Closes #1190