Skip to content

fix(fe): harden session security - #3668

Draft
minngyuseong wants to merge 2 commits into
mainfrom
t2817-harden-session-security
Draft

fix(fe): harden session security#3668
minngyuseong wants to merge 2 commits into
mainfrom
t2817-harden-session-security

Conversation

@minngyuseong

@minngyuseong minngyuseong commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Description

프론트엔드 세션 보안과 토큰 재발급 과정을 개선합니다. 혹시 코드 궁금한 거 있으면 질문 부담없이 해주세요

  • 클라이언트에 노출되는 NextAuth 세션에서 refreshTokenrefreshTokenExpires 제거
  • refresh token은 서버에서만 읽을 수 있는 NextAuth JWT 내부에 유지
  • 정적 파일 요청에서는 middleware가 실행되지 않도록 제한
  • 토큰 재발급 전에 refresh token 만료 여부 확인
  • 동일 서버 인스턴스에서 발생한 중복 토큰 재발급 요청을 하나로 통합
  • 토큰 재발급 실패 시 세션 쿠키를 삭제하고 로그인 페이지로 이동
  • middleware의 토큰 재발급 로직을 별도 모듈로 분리
  • 동시 토큰 재발급 요청에 대한 회귀 테스트 추가

closes TAS-2817


Before submitting the PR, please make sure you do the following

@minngyuseong minngyuseong self-assigned this Jul 29, 2026
@minngyuseong
minngyuseong requested a review from egg-zz July 29, 2026 08:45
@minngyuseong minngyuseong changed the title fix(fe): harden session security fix(fe): harden session security Jul 29, 2026
@minngyuseong
minngyuseong requested review from Copilot and seoeun9 July 29, 2026 08:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

프론트엔드의 NextAuth 세션 노출 범위를 줄이고(특히 refresh token 비노출), 미들웨어에서의 액세스 토큰 재발급 흐름을 더 안전하고 견고하게 만드는 PR입니다. 재발급 로직을 모듈로 분리하고, 만료/실패 시 처리 및 정적 리소스 경로에서의 미들웨어 실행을 제한하는 방향으로 보안/운영 안정성을 강화합니다.

Changes:

  • NextAuth Session에 refreshToken, refreshTokenExpires를 제거하고 JWT 내부에만 유지하도록 타입/세션 구성 변경
  • middleware에서 재발급 실패 처리(쿠키 삭제/로그인 이동) 및 정적 파일 요청 제외 matcher 추가
  • 동일 인스턴스 내 동시 재발급 요청을 reissueAccessToken에서 coalesce하고 회귀 테스트 추가

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
apps/frontend/types/next-auth.d.ts Session에 노출되는 token 타입을 AccessToken으로 제한
apps/frontend/mocks/handlers.ts mock session payload에서 refresh 관련 필드 제거
apps/frontend/middleware.ts 재발급 로직 분리/정리, 실패 처리 강화, matcher로 정적 요청 제외
apps/frontend/libs/auth/reissueAccessToken.ts 재발급 요청 coalescing 모듈 추가
apps/frontend/libs/auth/reissueAccessToken.spec.ts 동시 재발급 coalescing 회귀 테스트 추가
apps/frontend/libs/auth/authOptions.ts session callback에서 refresh 관련 값 비노출로 변경

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +56 to +72
const handleReissueFailure = (req: NextRequest) => {
const { pathname } = req.nextUrl
const isAuthRequest = pathname.startsWith('/next-auth/api/auth/')

if (pathname === '/login' || isAuthRequest) {
return clearSession(
req,
NextResponse.next({
request: {
headers: new Headers(req.headers)
}
})
)
}

return clearSession(req, NextResponse.redirect(createLoginUrl(req)))
}
Comment on lines +15 to +30
const requestReissue = async (
refreshToken: string
): Promise<ReissuedTokens> => {
const response = await fetch(`${baseUrl}/auth/reissue`, {
headers: {
cookie: `refresh_token=${refreshToken}`
},
cache: 'no-store'
})

if (!response.ok) {
throw new Error('Failed to reissue token')
}

return getJWTFromResponse(response)
}
@minngyuseong
minngyuseong marked this pull request as draft July 29, 2026 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants