Skip to content

fix(lms): Validate progress writes and hide unpublished courses - #1258

Open
jeromehardaway wants to merge 6 commits into
masterfrom
fix/progress-validation-course-leak
Open

fix(lms): Validate progress writes and hide unpublished courses#1258
jeromehardaway wants to merge 6 commits into
masterfrom
fix/progress-validation-course-leak

Conversation

@jeromehardaway

Copy link
Copy Markdown
Contributor

Problem

  1. Progress POST (/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.
  2. GET /api/courses applied isPublished straight from the query, so any user could pass ?isPublished=false and read unpublished courses.

Fix

  • Progress POST rejects (400) when the enrollment isn't ACTIVE, and when the lesson's module.courseId doesn't match the enrollment's course.
  • /api/courses forces where.isPublished = true for 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 forces isPublished=true for a student even with ?isPublished=false, and lets an admin filter unpublished. npm run typecheck — pass.

Closes #1190

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.
@vercel

vercel Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vets-who-code-app Ready Ready Preview, Comment Jul 21, 2026 12:57am

Request Review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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/progress validation by requiring Enrollment.status === "ACTIVE" and ensuring the lesson belongs to the enrollment’s course.
  • Force GET /api/courses to return only published courses for non-admins, while still allowing admins to filter by isPublished.
  • 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.

Comment thread src/pages/api/progress/index.ts
Comment thread __tests__/pages/api/progress-validation.test.ts
Comment thread __tests__/pages/api/progress-validation.test.ts
Comment thread __tests__/pages/api/progress-validation.test.ts Outdated
Comment thread __tests__/pages/api/progress-validation.test.ts
jeromehardaway and others added 5 commits July 20, 2026 20:53
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]>
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.

lms: Progress validation and unpublished-course leak fixes

2 participants