Feat/Member Id 주입 방식 변경#11
Merged
GoGradually merged 1 commit intomasterfrom Dec 31, 2025
Hidden character warning
The head ref may contain hidden characters: "feat/Member-Id-\uc8fc\uc785-\ubc29\uc2dd-\ubcc0\uacbd"
Merged
Conversation
| return bearerToken.substring(7); | ||
| } | ||
| return null; | ||
| return Long.parseLong(request.getHeader("X-Member-Id")); |
There was a problem hiding this comment.
문제점: JWT 토큰 기반의 인증/검증 로직이 완전히 제거되어, X-Member-Id 헤더 값을 아무런 검증 없이 신뢰하고 있습니다. 이는 심각한 보안 취약점입니다.
영향: 악의적인 사용자가 임의의 X-Member-Id 값을 헤더에 설정하여 다른 사용자로 위장할 수 있습니다. 인증/인가 없이 모든 사용자의 데이터에 접근 가능합니다.
수정 제안:
- API Gateway나 상위 레이어에서 JWT 검증 후 X-Member-Id를 주입하는 방식이라면, 해당 헤더가 신뢰할 수 있는 소스에서만 올 수 있도록 네트워크 레벨의 보안 설정이 필수적입니다.
- 또는 JWT 검증 로직을 유지하되, 검증된 토큰에서 추출한 Member ID를 사용하는 방식으로 변경해야 합니다.
Suggested change
| return Long.parseLong(request.getHeader("X-Member-Id")); | |
| String authorizationHeader = request.getHeader("Authorization"); | |
| if (authorizationHeader == null || !authorizationHeader.startsWith("Bearer ")) { | |
| log.warn("Authorization 헤더가 없거나 Bearer 토큰 형식이 아닙니다. authorizationHeader={}", authorizationHeader); | |
| throw new MemberNotFoundException("인증 정보가 유효하지 않습니다."); | |
| } | |
| String token = authorizationHeader.substring("Bearer ".length()); | |
| try { | |
| // JwtTokenProvider 를 통해 JWT 토큰을 검증하고, 검증된 토큰에서 memberId 를 추출한다. | |
| Long memberId = jwtTokenProvider.getMemberId(token); | |
| if (memberId == null) { | |
| log.warn("JWT 토큰에서 memberId 를 추출하지 못했습니다."); | |
| throw new MemberNotFoundException("유효하지 않은 사용자 정보입니다."); | |
| } | |
| return memberId; | |
| } catch (Exception e) { | |
| log.warn("JWT 토큰 검증 또는 memberId 추출에 실패했습니다.", e); | |
| throw new MemberNotFoundException("유효하지 않은 사용자 정보입니다."); | |
| } |
| return bearerToken.substring(7); | ||
| } | ||
| return null; | ||
| return Long.parseLong(request.getHeader("X-Member-Id")); |
There was a problem hiding this comment.
문제점: X-Member-Id 헤더가 null이거나 숫자가 아닌 값일 경우 NullPointerException 또는 NumberFormatException이 발생합니다.
영향: 명확하지 않은 예외 메시지로 인해 클라이언트가 문제를 파악하기 어렵고, 서버 로그에도 불필요한 스택 트레이스가 남게 됩니다.
수정 제안: 헤더 값에 대한 null 체크 및 숫자 형식 검증을 추가하고, 검증 실패 시 적절한 에러 메시지와 함께 MemberNotFoundException을 던져야 합니다.
Suggested change
| return Long.parseLong(request.getHeader("X-Member-Id")); | |
| String memberIdHeader = request.getHeader("X-Member-Id"); | |
| if (memberIdHeader == null || memberIdHeader.isBlank()) { | |
| log.info("X-Member-Id 헤더가 누락되었거나 비어 있습니다."); | |
| throw new MemberNotFoundException("유효한 사용자 정보를 찾을 수 없습니다. (X-Member-Id 헤더 누락)"); | |
| } | |
| try { | |
| return Long.parseLong(memberIdHeader); | |
| } catch (NumberFormatException e) { | |
| log.info("X-Member-Id 헤더 값이 숫자 형식이 아닙니다. value={}", memberIdHeader, e); | |
| throw new MemberNotFoundException("유효한 사용자 정보를 찾을 수 없습니다. (X-Member-Id 형식 오류)"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
변경된 점