fix(security): resolve all critical, high, and medium security vulnerabilities
Deploy Canina / deploy (push) Waiting to run
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 11s

This commit is contained in:
parsa committed 2026-09-23 22:05:12 +03:30
1 parent da26dd1c8d
commit dc88677169
33 files changed
+438 -85

No files matched your search

+17 -3
View File
@@ -10,6 +10,8 @@ import { ROLES_KEY } from '../decorators/roles.decorator';
interface RequestWithUser {
user?: {
role?: string;
isApiKey?: boolean;
scopes?: string[];
};
}
@@ -33,11 +35,23 @@ export class RolesGuard implements CanActivate {
throw new ForbiddenException('شما دسترسی لازم برای این بخش را ندارید');
}
// If request originates from an API key, verify it has admin scope for admin-guarded routes
if (user.isApiKey) {
const scopes = Array.isArray(user.scopes) ? user.scopes : [];
const hasAdminScope =
scopes.includes('*') ||
scopes.includes('admin') ||
scopes.includes('all');
if (!hasAdminScope) {
throw new ForbiddenException(
'کلید API ارائه‌شده فاقد اسکوپ مدیریتی لازم برای این عملیات است',
);
}
}
const userRoleLower = user.role.toLowerCase();
const hasRole = requiredRoles.some(
(r) =>
r.toLowerCase() === userRoleLower ||
(userRoleLower.includes('admin') && r.toLowerCase().includes('admin')),
(r) => r.toLowerCase() === userRoleLower,
);
if (!hasRole) {
throw new ForbiddenException('سطح دسترسی شما کافی نیست');