Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] feat: GroupAccessCode를 암호화 #456

Closed
wants to merge 9 commits into from

Conversation

donghoony
Copy link
Contributor

@donghoony donghoony commented Aug 20, 2024


🚀 어떤 기능을 구현했나요 ?

  • 해싱을 활용해 평문을 DB에 저장하지 않도록 했습니다.

🔥 어떻게 해결했나요 ?

  • SHA-256 해싱을 적용했습니다.
  • 검증 책임을 인코더에게 넘겼습니다. 어색한가요?
  • 이에 따라 Embedded가 사라지고, 다시 원복됐어요.

중요하게 바뀐 사안

  • 리뷰 패키지와 리뷰그룹 패키지가 긴밀하게 협력하고 있으나, ReviewService에서 ReviewGroupRepository를 가져오는 건 두 패키지를 나누는 기준을 흐리게 만든다고 생각해요.
  • 따라서 코드로 리뷰 그룹을 찾거나, 권한 검증하는 것을 ReviewGroupFinder에서 진행합니다. (ReviewGroupService에서 하려고 했는데, ReviewGroup을 리턴하는 ReviewGroupFinder와 Web Response를 리턴하는 ReviewGroupService가 헷갈릴 것이라고 생각했어요)
  • 프론트와 협의해서 403을 내려주는 것이 괜찮다고 해서, 권한 검증에 대한 건 403을 내리도록 했습니다. UnAuthorizedException이 살아났어요.
  • 패키지를 올바르게 옮겼습니다. 이미 예외 클래스에서부터 리팩터링 냄새가 나기 시작했었습니다 (ReviewGroup의 예외를 Review 패키지에서 가지고 있는 등..)

📝 어떤 부분에 집중해서 리뷰해야 할까요?

  • 이해하기 쉬운지 모르겠네요 😕
  • 궁금한 것 있다면 언제든 고고

📚 참고 자료, 할 말

  • 영어 대소문자와 숫자로만 이루어져 있어 Rainbow table attack에 취약할 수 있습니다. salt와 같은 보안 강화 대책이 필요해요.

@donghoony donghoony added this to the 4차 스프린트: 최종 milestone Aug 20, 2024
@donghoony donghoony self-assigned this Aug 20, 2024
@donghoony donghoony linked an issue Aug 20, 2024 that may be closed by this pull request
Copy link

github-actions bot commented Aug 20, 2024

Test Results

72 tests   72 ✅  3s ⏱️
24 suites   0 💤
24 files     0 ❌

Results for commit 3ff04d2.

♻️ This comment has been updated with latest results.

@donghoony donghoony requested review from skylar1220, Kimprodp and nayonsoso and removed request for skylar1220 and Kimprodp August 20, 2024 04:10
@donghoony donghoony closed this Aug 20, 2024
@donghoony donghoony reopened this Aug 20, 2024
@donghoony donghoony marked this pull request as ready for review August 20, 2024 04:30
Copy link
Contributor

@nayonsoso nayonsoso left a comment

Choose a reason for hiding this comment

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

일단 예외 패키지 부분만 코멘트 드렸습니다~ 🙇🏻‍♀️

Copy link
Contributor

@Kimprodp Kimprodp left a comment

Choose a reason for hiding this comment

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

상호 서비스간에 의존을 하는 finder를 사용해야하는가에 대한 고민이 많아지네요.. RC 확인 부탁드립니다!

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class ReviewGroupFinder {
Copy link
Contributor

Choose a reason for hiding this comment

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

ReviewService 에서는 Group을 찾기 위해서 사용되고 있지만,
ReviewDetailLookupService 에서는 사용되지 않고 있어요. Review 패키지의 서비스에서 group을 찾을 때 어떤 경우에는 사용하고 어떤 경우에는 사용하지 않는지 헷갈릴 것 같아요..

단순히 groupAccessCode를 검증해서 찾는 것이 Group의 책임이라 느껴져서 사용하는 것이라면 두가지 방식에 대한 제안이 있습니다!

  1. ReviewGroup에 직접 물어보는 방식
  2. ReviewGroup 패키지에 ReviewGroupAuthService를 두고, 인증이 필요한 경로에서 ArgumentResolverReviewGroupAuthService로 그룹을 검증해서 찾아서 컨트롤러에 파라미터로 전달하는 방식 (ReviewService에서는 ReviewGroup 연관이 없어짐)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

이 부분은 제가 확인을 못 했네요. 제 의도는 Review 패키지에서 ReviewGroup repository를 참조하지 않게 하는 것이 목적입니다. 다른 패키지니 API와 같이 서비스 레이어에서 주고받으면 좋을 것이라고 생각했어요.

Copy link
Contributor

@skylar1220 skylar1220 left a comment

Choose a reason for hiding this comment

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

짱짱 암호화 방식 새로 배워갑니다 총총😋😋
repo 의존에 대한 건 얘기 더 나눠봐요!

@@ -10,9 +10,9 @@ public interface ReviewGroupRepository extends JpaRepository<ReviewGroup, Long>

Optional<ReviewGroup> findByReviewRequestCode(String reviewRequestCode);

Optional<ReviewGroup> findByReviewRequestCodeAndGroupAccessCode_Code(String reviewRequestCode, String groupAccessCode);
Optional<ReviewGroup> findByReviewRequestCodeAndGroupAccessCode(String reviewRequestCode, String groupAccessCode);
Copy link
Contributor

Choose a reason for hiding this comment

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

사용하지 않는 메서드네요!


boolean existsByReviewRequestCode(String reviewRequestCode);

boolean existsByReviewRequestCodeAndGroupAccessCode_Code(String reviewRequestCode, String groupAccessCode);
boolean existsByReviewRequestCodeAndGroupAccessCode(String reviewRequestCode, String groupAccessCode);
Copy link
Contributor

Choose a reason for hiding this comment

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

여기도 마찬가지로 사용하지 않는 메서드네요!

Copy link
Contributor

Choose a reason for hiding this comment

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

java의 MessageDigest를 이용해서 해시코드를 생성할 수 있군요 알아갑니당😋😋

Comment on lines +19 to +22
public String encode(String groupAccessCode) {
validateGroupAccessCode(groupAccessCode);
return encoder.encode(SHA_256, groupAccessCode);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

encdoe 로직 내부에서 코드의 형식 검증을 하는 것이 적절한지 고민이에요.
현재 encode는 리뷰 그룹 생성할 때, 비밀번호 check 할 때 두 곳에서 쓰입니다.

  1. 리뷰 그룹 생성할 때는 사용자가 입력해 저장되기 전이기때문에 형식 검증을 하는 것이 당연히 맞다고 생각해요.
  2. 하지만 비밀번호 check 할 때는 형식을 틀리게 입력해도 상관없습니당. 어차피 일치하는 groupAccessCode가 있는지 확인하기 때문이죠. 그렇기에 형식 검증이 이 경우에는 없어도 된다고 생각해요!

따라서, 리뷰 그룹 생성할 때만 형식 검증이 필요하니
검증 로직을 encode할 때가 아닌 리뷰 그룹 생성 로직에만 넣는 것은 어떨까요?

@donghoony
Copy link
Contributor Author

#489 으로 마무리합니다, 패키지 이야기는 의논을 꾸준히 해 볼게요

@donghoony donghoony closed this Aug 21, 2024
@donghoony donghoony deleted the be/feature/443-encrypt-code branch August 23, 2024 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[BE] 비밀번호를 해싱해 저장한다.
4 participants