Skip to content

Fix: Add authentication and admin authorization guards to RolesController - #1149

Merged
RUKAYAT-CODER merged 3 commits into
rinafcode:mainfrom
Ultra-Tech-code:fix/rbac-roles-966
Jul 30, 2026
Merged

Fix: Add authentication and admin authorization guards to RolesController#1149
RUKAYAT-CODER merged 3 commits into
rinafcode:mainfrom
Ultra-Tech-code:fix/rbac-roles-966

Conversation

@Ultra-Tech-code

Copy link
Copy Markdown
Contributor

Closes #966

Overview

This PR addresses a critical authorization gap in the RBAC implementation where the RolesController CRUD endpoints were missing authentication and authorization guards. Previously, these endpoints were reachable by any unauthenticated caller, allowing for potential privilege escalation to administrator.

Changes Made

  • Secured Controller: Applied @UseGuards(JwtAuthGuard, RolesGuard) and @Roles('admin') at the RolesController class level.
  • Swagger Documentation: Added @ApiBearerAuth() so the Swagger contract reflects the authorization requirement.
  • DTO Validation: Replaced loose parameter bindings with CreateRoleDto and UpdateRoleDto (using @IsString, @IsOptional, and @IsUUID({ each: true })), enabling the global ValidationPipe whitelist.
  • Audit Logging: Endpoints now extract the actor's context (id/sub, email, ipAddress, and userAgent) from the request and pass it to the RolesService to properly record role and permission changes with the acting principal.
  • E2E Testing: Added an e2e test (test/security/roles-rbac.e2e-spec.ts) asserting that POST /roles returns a 401 without a token and a 403 with a non-admin token.

@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@Ultra-Tech-code 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

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Kindly resolve conflict

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thank you for contributing to the project.

@RUKAYAT-CODER
RUKAYAT-CODER merged commit e77d22c into rinafcode:main Jul 30, 2026
2 of 3 checks passed
@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thank you for contributing to the project.

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.

Add authentication and admin authorization guards to RolesController RBAC CRUD endpoints

2 participants