Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private GoogleUserInfoResponse getGoogleUserInfo(String code) {
}

private User findOrCreateGoogleUser(GoogleUserInfoResponse userInfo) {
return userRepository.findByGoogleSub(userInfo.sub())
return userRepository.findByEmail(userInfo.email())
Copy link
Contributor

Choose a reason for hiding this comment

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

security-critical critical

이 변경은 Google OAuth 사용자를 이메일로 조회하도록 수정합니다. Google의 sub 필드는 사용자에게 고유하고 변경되지 않는 식별자인 반면, 이메일은 변경될 수 있습니다. 만약 한 사용자가 Google 계정의 이메일을 다른 기존 사용자의 이메일로 변경하는 경우, 이 로직은 잘못된 사용자 계정을 반환하여 **계정 탈취(account hijacking)**로 이어질 수 있는 심각한 보안 취약점을 발생시킵니다. Google sub를 사용하여 사용자를 먼저 조회하는 것이 더 안전합니다.

Suggested change
return userRepository.findByEmail(userInfo.email())
return userRepository.findByGoogleSub(userInfo.sub())

.orElseGet(() -> {
User user = User.createGoogleUser(
userInfo.sub(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@
@Repository
public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByEmail(String email);
Optional<User> findByGoogleSub(String googleSub);
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void googleLogin_success_existingUser() {

given(googleOauth.requestAccessToken(code)).willReturn(tokenResponse);
given(googleOauth.requestUserInfo("google-access-token")).willReturn(userInfo);
given(userRepository.findByGoogleSub(googleSub)).willReturn(Optional.of(user));
given(userRepository.findByEmail("google@test.com")).willReturn(Optional.of(user));
Copy link
Contributor

Choose a reason for hiding this comment

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

security-critical critical

이 테스트는 userRepository.findByEmail을 사용하여 기존 사용자를 조회하도록 변경되었습니다. OauthService의 변경 사항이 보안 취약점을 야기하므로, 이 테스트는 Google sub를 사용하여 사용자를 조회하는 이전 로직을 반영하도록 수정되어야 합니다.

Suggested change
given(userRepository.findByEmail("google@test.com")).willReturn(Optional.of(user));
given(userRepository.findByGoogleSub(googleSub)).willReturn(Optional.of(user));


given(authService.issueTokens(userId)).willReturn(
Map.of(
Expand Down Expand Up @@ -123,15 +123,15 @@ void googleLogin_success_newUser() {

GoogleUserInfoResponse userInfo = new GoogleUserInfoResponse(
googleSub,
"new@test.com",
"google@test.com",
"newUser",
null,
true
);

given(googleOauth.requestAccessToken(code)).willReturn(tokenResponse);
given(googleOauth.requestUserInfo("google-access-token")).willReturn(userInfo);
given(userRepository.findByGoogleSub(googleSub)).willReturn(Optional.empty());
given(userRepository.findByEmail("google@test.com")).willReturn(Optional.empty());
Copy link
Contributor

Choose a reason for hiding this comment

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

security-critical critical

이 테스트는 userRepository.findByEmail을 사용하여 신규 사용자를 조회하도록 변경되었습니다. OauthService의 변경 사항이 보안 취약점을 야기하므로, 이 테스트는 Google sub를 사용하여 사용자를 조회하는 이전 로직을 반영하도록 수정되어야 합니다.

Suggested change
given(userRepository.findByEmail("google@test.com")).willReturn(Optional.empty());
given(userRepository.findByGoogleSub(googleSub)).willReturn(Optional.empty());

given(passwordEncoder.encode(anyString())).willReturn("encoded-password");

given(userRepository.save(any(User.class)))
Expand Down