feat(security): enforce role + subject ownership checks - #727
Open
sagesan2580 wants to merge 3 commits into
Open
feat(security): enforce role + subject ownership checks#727sagesan2580 wants to merge 3 commits into
sagesan2580 wants to merge 3 commits into
Conversation
Adds authorization for role-gated and subject-owned routes: - New guards: JwtAuthGuard, JwtAdminGuard, JwtLearnerGuard, JwtTutorGuard, RolesGuard, SubjectOwnershipGuard - assertSameSubject / assertOwnerOrStaff helpers and @Ownership decorator for JWT-vs-entity ownership verification - Subject-scoped enforcement on user/tutor profiles, submission review/grading, and progress endpoints; reviewer/rater/grader identities are always bound to the JWT subject - Integration suite (33 cases) exercising real controllers/guards - Fix DI/compile blockers exposed while wiring the suites: auth-session duplicate constructor and refreshTokenHash leak in getActiveSessions, audit duplicate guard param, rewards incrementCounter call against MonitoringService - Install missing runtime deps (ioredis, prom-client, @willsoto/nestjs-prometheus)
|
@sagesan2580 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
# Conflicts: # BackendAcademy/src/auth/auth-session.service.ts # BackendAcademy/src/auth/guards/jwt-admin.guard.ts # BackendAcademy/src/auth/guards/jwt-learner.guard.ts # BackendAcademy/src/auth/guards/jwt-tutor.guard.ts # BackendAcademy/src/rewards/rewards.service.ts
Resolve 4 conflicts: - auth-session.service.ts: keep BA-018 clean rewrite as base; inject exported RedisService (RedisModule has no REDIS_CLIENT provider, so ioredis @Inject was unresolvable) with @optional audit; graft main's security hooks (onPasswordChanged/onPasswordReset/onPrivilegeChanged/ onAccountDeleted), reason-based revokeAllUserSessions, and token_reuse revoke-all on refresh replay. Drops main's corrupted duplicate blocks, refreshTokenThash, undefined-data/duplicate setSession/getSession. - auth-session.controller.ts: async Promise<Omit<Session,'refreshTokenHash'>[]>. - users.service.ts: keep trackUserUpload + main's onPasswordChanged/Reset. - audit.service.ts: keep ?? nullish-coalescing log line. Also fix auto-merge artifacts (not git-flagged conflicts): - auth.module.ts: duplicate useFactory in JwtModule.registerAsync dropped (kept BA-023 clock-tolerance factory). - config/config.module.ts: dead inline Joi.object validationSchema (no Joi import, TS2304) removed; canonical envValidationSchema is the single source of truth as documented.
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.
Adds authorization for role-gated and subject-owned routes:
closes: #586