Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 이 Pull Request는 이메일 발송 기능을 비동기 처리로 전환하여 사용자 경험을 개선하고 서버의 응답성을 향상시키는 것을 목표로 합니다. 기존에는 이메일 발송이 동기적으로 처리되어 응답 지연을 유발할 수 있었으나, 이제는 별도의 스레드 풀에서 메일 발송 작업을 처리함으로써 메인 스레드의 부하를 줄이고 즉각적인 응답을 제공할 수 있게 됩니다. 또한, 메일 발송 실패 시에도 서비스의 안정성을 유지하도록 에러 처리 방식이 개선되었습니다. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
이 PR은 메일 발송 로직을 비동기로 전환하여 사용자 경험을 개선하는 좋은 변경입니다. 하지만, 인증 서비스의 보안 및 규정 준수를 위해 해결해야 할 몇 가지 중요한 보안 취약점이 발견되었습니다. 특히, 인증 시도 제한의 레이스 컨디션으로 인해 무차별 대입 공격이 가능하며, 이메일 발송 속도 제한의 누락된 증가 로직으로 인해 무제한 이메일 요청이 발생할 수 있습니다. 또한, 개인 식별 정보(PII)인 이메일 주소가 실패 시 평문으로 로깅되고 있습니다. 전반적으로 코드 구조는 잘 개선되었으나, 예외 로깅을 좀 더 상세하게 하고 에러 코드 사용의 일관성을 높이는 방향으로 수정하면 더 좋을 것 같습니다.
| if (rateLimitRepository.isAttemptExceeded(request.getEmail())) { | ||
| throw new BusinessException(AuthErrorStatus.VERIFICATION_ATTEMPT_EXCEEDED); | ||
| } | ||
| }); | ||
|
|
||
| String storedCode = executeRedisOperation(() -> | ||
| verificationCodeRepository.findByEmail(request.getEmail()).orElse(null) | ||
| ); | ||
|
|
||
| if (storedCode == null || !storedCode.equals(request.getVerificationCode())) { | ||
| executeRedisOperationVoid(() -> rateLimitRepository.incrementAttempt(request.getEmail())); |
There was a problem hiding this comment.
The verifyEmailWithCode method implements rate limiting for verification attempts using a "check-then-act" pattern that is not atomic. The check for exceeded attempts happens on line 76, while the increment of the attempt counter happens on line 86 after the code verification fails. An attacker can send multiple concurrent requests that all pass the isAttemptExceeded check before any of them increment the attempt counter, effectively bypassing the brute-force protection. This could allow an attacker to attempt more verification codes than intended within a short window.
Remediation: The check and increment operations should be performed atomically. Consider using a Redis-based atomic increment and check (e.g., using a Lua script or the INCR command followed by a check) to ensure the rate limit is enforced correctly across concurrent requests.
|
|
||
| executeRedisOperationVoid(() -> { | ||
| verificationCodeRepository.save(request.getEmail(), verificationCode); | ||
| if (rateLimitRepository.isRateLimited(request.getEmail())) { |
There was a problem hiding this comment.
The sendVerificationCode method checks if the email sending is rate-limited on line 60, but it never seems to increment the rate limit counter. In contrast, the verifyEmailWithCode method explicitly calls incrementAttempt on line 86. Without an increment operation, the isRateLimited check will always return false (assuming it's a simple check), allowing an attacker to send an unlimited number of verification emails. This can lead to resource exhaustion, increased costs, and potential blacklisting of the mail server's IP address.
Remediation: Ensure that the rate limit counter is incremented every time a verification email is successfully requested. This should be done atomically with the check to avoid race conditions.
| ); | ||
| javaMailSender.send(mimeMessage); | ||
| } catch (Exception e) { | ||
| log.error("이메일 발송 실패 - email: {}, error: {}", email, e.getMessage()); |
There was a problem hiding this comment.
이메일 발송 실패 시 사용자 이메일 주소가 평문으로 로깅되고 있습니다. 이메일 주소는 개인 식별 정보(PII)로 간주되며, PII를 평문으로 로깅하는 것은 보안 및 규정 준수 문제를 야기할 수 있습니다. 또한, 비동기 작업에서 예외 발생 시 원인 파악을 용이하게 하기 위해 전체 스택 트레이스를 로깅하는 것이 좋습니다. e.getMessage()만 기록할 경우 상세 정보를 놓칠 수 있습니다. SLF4J의 로거는 마지막 인자로 Throwable을 받으면 스택 트레이스를 자동으로 출력해줍니다. 이메일 주소는 마스킹 처리하고, 예외 발생 시 스택 트레이스를 함께 로깅하도록 수정해주세요.
| log.error("이메일 발송 실패 - email: {}, error: {}", email, e.getMessage()); | |
| log.error("이메일 발송 실패 - email: {}, error: {}", email.replaceAll("(?<=.{3}).(?=.*@)", "*"), e.getMessage(), e); |
|
|
||
| private void sendForSignup(EmailVerificationRequestDto request) { | ||
| if (userRepository.existsByEmail(request.getEmail())) { | ||
| throw new BusinessException(AuthErrorStatus.DUPLICATE_EMAIL); |
There was a problem hiding this comment.
sendForEmailChange 메서드(53라인)에서는 중복 이메일에 대해 UserErrorStatus.DUPLICATE_EMAIL을 사용하고 있습니다. 코드의 일관성을 높이고 에러 코드의 역할을 명확히 하기 위해, 회원가입 시 중복 이메일 검사에서도 동일한 UserErrorStatus.DUPLICATE_EMAIL을 사용하도록 변경하는 것을 제안합니다. 중복 이메일은 인증(Auth)보다는 사용자(User) 도메인의 책임에 더 가깝다고 볼 수 있습니다.
이 변경사항을 적용하려면 MailVerificationServiceImplTest의 중복_이메일_SIGNUP_예외_발생 테스트 케이스도 함께 수정해야 합니다.
| throw new BusinessException(AuthErrorStatus.DUPLICATE_EMAIL); | |
| throw new BusinessException(UserErrorStatus.DUPLICATE_EMAIL); |
Summary
AsyncMailSender컴포넌트 추가 —@Async("mailTaskExecutor")로 SMTP 발송 백그라운드 처리AsyncConfig추가 —@EnableAsync및mailTaskExecutor스레드 풀 설정 (core 2, max 5, queue 100)MailVerificationServiceImpl수정 — 레이트 리밋·코드 저장은 동기 유지, SMTP 발송만 비동기 위임log.error만 기록 → FE 재발송 버튼으로 재시도MailVerificationServiceImplTest수정 —AsyncMailSendermock으로 교체Test plan
MailVerificationServiceImplTest전체 통과 확인