Repository navigation
Restrict certificate HTML show to owner or course updater - #137
Merged
Merged
Conversation
Require auth on the show route and drop guest access via course completion or signed URLs. Guests are redirected; only the certificate subject or a user who can update the course may view HTML. Co-authored-by: Scott Grayson <scottgrayson@users.noreply.github.com>
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.
Summary
Gates
GET lms/certificates/{course}/{user}behindauthand allows HTML only for the certificate owner or a user who can update the course, removing guest access via course completion or signed URLs.Design decisions
HTML show requires session owner or course updater
Why
Guests who knew course and user IDs could open named certificates when
completedByUserAt($userId)was true. PDF download was already behindauth; HTML needed the same privacy bar without signed URLs (PDF uses an HTML string, not a fetch of the show route).High impact
Any guest or email link that relied on public or signed HTML certificate URLs will stop working; viewers must be logged in as the certificate user or as someone who can update the course.
Files
src/Http/Controllers/CertificateController.php
routes/web.php
Auth rules for certificate HTML
Why
Product rules: allow if
Auth::id() == $userId, or ifAuth::user()?->can('update', $course). Do not keep guest access via completion alone. Admin “Click to Preview” still works because it uses the logged-in admin’s user id (owner path) while the admin session is active.Feature coverage for guest, owner, admin, stranger
Why
Locks the new gate: guests redirect to login; owner and updater get 200; another authenticated user gets 403. Signed-guest access is not required and is no longer honored.
Files
tests/Feature/CertificateControllerTest.php
Testing
Package Pest suite (no Portal deploy). From a clone with dependencies installed:
vendor/bin/pest tests/Feature/CertificateControllerTest.php./lms/certificates/{course}/{user}for a completed learner → redirected to login (not 200).authand completion or update ability.