Skip to content

feat(security): enforce role + subject ownership checks - #727

Open
sagesan2580 wants to merge 3 commits into
BlockDash-Studios:mainfrom
sagesan2580:fix/BA-018-role-subject-checks
Open

feat(security): enforce role + subject ownership checks#727
sagesan2580 wants to merge 3 commits into
BlockDash-Studios:mainfrom
sagesan2580:fix/BA-018-role-subject-checks

Conversation

@sagesan2580

Copy link
Copy Markdown

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)

closes: #586

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)
@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

# 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.
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.

BA-018 — Add role and subject checks to every protected controller

1 participant