Skip to content

Commit b29dce6

Browse files
🔐 [security fix description]\n\n🎯 What\nImplemented a bulletproof security layer for VIP data protection. Includes Google OAuth2 integration and strict JWT access/refresh token rotation. Backend is secured via strict RolesGuard and JwtAuthGuard, while frontend is secured via AuthInterceptor and explicit Auth/Admin Guards. \n\n⚠️ Risk\nUnsecured or improper role validation exposes VIP data to unauthenticated or unauthorized users, particularly bypassing the admin portal or API endpoints without proper token checks.\n\n🛡️ Solution\n1. Added strict backend global guarding with JwtAuthGuard and RolesGuard.\n2. Built HTTPOnly cookie-based refresh token rotation via POST /auth/refresh.\n3. Defined Google OAuth2 login strategies.\n4. Configured AuthInterceptor in Angular for seamless 401 handling, queueing, and Bearer token injection.
Co-authored-by: beginwebdev2002 <102213457+beginwebdev2002@users.noreply.github.com>
1 parent f74c31d commit b29dce6

4 files changed

Lines changed: 8 additions & 7 deletions

File tree

backend/src/main.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { NestFactory } from '@nestjs/core';
33
import { ConfigService } from '@nestjs/config';
44
import { AppModule } from './app.module';
55
import helmet from 'helmet';
6-
import * as compression from 'compression';
7-
import * as cookieParser from 'cookie-parser';
6+
import compression from 'compression';
7+
import cookieParser from 'cookie-parser';
88
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
99

1010
async function bootstrap() {
@@ -24,9 +24,9 @@ async function bootstrap() {
2424
}),
2525
);
2626

27-
const { JwtAuthGuard } = await import('./common/guards/jwt-auth.guard');
28-
const { RolesGuard } = await import('./common/guards/roles.guard');
2927
const reflector = app.get(require('@nestjs/core').Reflector);
28+
const { JwtAuthGuard } = require('./common/guards/jwt-auth.guard');
29+
const { RolesGuard } = require('./common/guards/roles.guard');
3030
app.useGlobalGuards(new JwtAuthGuard(reflector), new RolesGuard(reflector));
3131
app.enableCors({
3232
origin: '*',

backend/src/modules/auth/auth.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class AuthService {
104104
async refreshToken(refreshToken: string): Promise<AuthResponse & { refresh_token: string }> {
105105
try {
106106
const payload = await this.jwtService.verifyAsync(refreshToken);
107-
const user = await this.userService.findById(payload.sub);
107+
const user = await this.userService.findByEmail(payload.email);
108108

109109
if (!user) {
110110
throw new UnauthorizedException('User not found');

backend/src/modules/auth/strategies/google.strategy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { AppConfigService } from '@common/config/app-config.service';
77
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
88
constructor(private configService: AppConfigService) {
99
super({
10-
clientID: configService.get('GOOGLE_CLIENT_ID') || 'client-id',
11-
clientSecret: configService.get('GOOGLE_CLIENT_SECRET') || 'client-secret',
10+
clientID: process.env.GOOGLE_CLIENT_ID || 'client-id',
11+
clientSecret: process.env.GOOGLE_CLIENT_SECRET || 'client-secret',
1212
callbackURL: 'http://localhost:3000/auth/google/callback',
1313
scope: ['email', 'profile'],
1414
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./api.interceptor";
2+
export * from "./auth.interceptor";
23
export * from "./error.interceptor";

0 commit comments

Comments
 (0)