fix(sprint-006): Critical 보안 이슈 5건 수정

B1(Critical): JWT_SECRET 'changeme' fallback 3곳 전부 제거
- auth.service.ts / auth.module.ts / events.module.ts: 미설정 시 throw
- events.gateway.ts: 미설정 시 client.disconnect()

B2(Critical): User.role 기본값 'admin' → 'viewer'
- Prisma schema @default('viewer')
- RoleGuard 신규 생성 (Roles 데코레이터)
- AdminController / CostsController @Roles('admin') 적용

B3: WebSocket JWT 실패/미제공 시 client.disconnect()
- 토큰 없으면 즉시 disconnect
- 토큰 있지만 검증 실패해도 disconnect
- FE useSocket: access token을 auth.token으로 전달

B4: refresh endpoint throw Error → BadRequestException (400)

B5: register Throttle 추가 (3회/분, 초대코드 brute-force 방지)
This commit is contained in:
2026-04-04 15:16:12 +09:00
parent 1294987314
commit bd2f52ddcd
10 changed files with 69 additions and 21 deletions

View File

@@ -16,12 +16,14 @@ export function useSocket(options: UseSocketOptions = {}) {
// next.config.ts rewrites가 없는 경우를 위해 빈 origin 처리
// 브라우저에서 WebSocket은 rewrites 대상이 아니므로 직접 BE URL 필요
const wsUrl = process.env.NEXT_PUBLIC_WS_URL ?? window.location.origin;
const token = localStorage.getItem('hanarang_access_token') ?? '';
const socket = io(`${wsUrl}/ws`, {
path: '/socket.io',
transports: ['websocket', 'polling'],
reconnectionAttempts: 5,
reconnectionDelay: 3000,
auth: { token },
});
socket.on('connect', () => {