Skip to content

Conversation

@ohyuchan123
Copy link
Member

@ohyuchan123 ohyuchan123 commented Jan 15, 2025

πŸ“Œ κ΄€λ ¨ 이슈

#31 μ‚¬μš©μž ν”„λ‘œν•„ 쑰회

✨ 과제 λ‚΄μš©

μ‚¬μš©μžλŠ” μžμ‹ μ˜ ν”„λ‘œν•„μ„ μ‘°νšŒν•  수 μžˆμŠ΅λ‹ˆλ‹€.

πŸ“Έ μŠ€ν¬λ¦°μƒ·(선택)

image

πŸ“š 레퍼런슀 (λ˜λŠ” μƒˆλ‘œ μ•Œκ²Œ 된 λ‚΄μš©) ν˜Ήμ€ κΆκΈˆν•œ 사항듀

Summary by CodeRabbit

  • μƒˆλ‘œμš΄ κΈ°λŠ₯

    • ν”„λ‘œν•„ 정보 쑰회 API μΆ”κ°€
    • JWT 토큰 인증 방식 λ³€κ²½ (μΏ ν‚€μ—μ„œ 헀더 기반 인증으둜 μ „ν™˜)
  • 버그 μˆ˜μ •

    • λ°μ΄ν„°λ² μ΄μŠ€ μŠ€ν‚€λ§ˆ 관리 방식 κ°œμ„  (μŠ€ν‚€λ§ˆ μž¬μƒμ„± λŒ€μ‹  μ—…λ°μ΄νŠΈ)
  • 기타 변경사항

    • 인증 및 ν”„λ‘œν•„ κ΄€λ ¨ μ„œλΉ„μŠ€ 및 컨트둀러 ꡬ쑰 κ°œμ„ 

@coderabbitai
Copy link

coderabbitai bot commented Jan 15, 2025

Warning

Rate limit exceeded

@ohyuchan123 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 18 seconds before requesting another review.

βŒ› How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between a3bffe3 and 99593bc.

πŸ“’ Files selected for processing (2)
  • src/main/java/com/mycom/socket/auth/config/SecurityConfig.java (1 hunks)
  • src/main/java/com/mycom/socket/auth/jwt/JWTFilter.java (3 hunks)

Walkthrough

이 ν’€ λ¦¬ν€˜μŠ€νŠΈλŠ” ν”„λ‘œν•„ 관리 및 인증 λ©”μ»€λ‹ˆμ¦˜μ— λŒ€ν•œ μ€‘μš”ν•œ λ³€κ²½ 사항을 ν¬ν•¨ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€. JWT 토큰 인증 방식이 μΏ ν‚€ κΈ°λ°˜μ—μ„œ 헀더 기반으둜 λ³€κ²½λ˜μ—ˆμœΌλ©°, μƒˆλ‘œμš΄ ProfileController와 ProfileResponseκ°€ μΆ”κ°€λ˜μ—ˆμŠ΅λ‹ˆλ‹€. λ˜ν•œ MemberServiceκ°€ λ„μž…λ˜μ–΄ μ‚¬μš©μž κ΄€λ ¨ μ„œλΉ„μŠ€ λ‘œμ§μ„ μ²˜λ¦¬ν•˜κ³ , 개발 ν™˜κ²½μ˜ λ°μ΄ν„°λ² μ΄μŠ€ μŠ€ν‚€λ§ˆ 관리 섀정이 μ—…λ°μ΄νŠΈλ˜μ—ˆμŠ΅λ‹ˆλ‹€.

Changes

파일 λ³€κ²½ μš”μ•½
src/main/java/com/mycom/socket/auth/jwt/JWTFilter.java - resolveTokenFromCookie λ©”μ„œλ“œ 제거
- resolveTokenFromHeader λ©”μ„œλ“œ μΆ”κ°€
- 토큰 ν•΄κ²° λ‘œμ§μ„ μΏ ν‚€μ—μ„œ ν—€λ”λ‘œ λ³€κ²½
src/main/java/com/mycom/socket/go_socket/controller/ProfileController.java - μƒˆλ‘œμš΄ ν”„λ‘œν•„ 컨트둀러 μΆ”κ°€
- /api/profile GET μ—”λ“œν¬μΈνŠΈ κ΅¬ν˜„
src/main/java/com/mycom/socket/go_socket/dto/response/ProfileResponse.java - ν”„λ‘œν•„ 응닡 λ ˆμ½”λ“œ 생성
- of 정적 νŒ©ν† λ¦¬ λ©”μ„œλ“œ μΆ”κ°€
src/main/java/com/mycom/socket/go_socket/service/MemberService.java - μƒˆλ‘œμš΄ 멀버 μ„œλΉ„μŠ€ 클래슀 μΆ”κ°€
- MemberRepository μ£Όμž…
src/main/resources/yaml/application-dev.yml - Hibernate ddl-auto 섀정을 createμ—μ„œ update둜 λ³€κ²½

Sequence Diagram

sequenceDiagram
    participant Client
    participant JWTFilter
    participant AuthenticationManager
    participant ProfileController
    participant MemberService

    Client->>JWTFilter: HTTP Request with Bearer Token
    JWTFilter->>JWTFilter: Resolve Token from Header
    JWTFilter->>AuthenticationManager: Authenticate Token
    AuthenticationManager-->>JWTFilter: Authentication Success
    Client->>ProfileController: GET /api/profile
    ProfileController->>MemberService: Retrieve Member Details
    MemberService-->>ProfileController: Return Member Information
    ProfileController-->>Client: Return ProfileResponse
Loading

Possibly related PRs

  • πŸ”€ Jwt LoginΒ #24: JWT 인증 κΈ°λŠ₯ κ°œμ„ κ³Ό μ§μ ‘μ μœΌλ‘œ κ΄€λ ¨λœ λ³€κ²½ 사항
  • πŸ”€ Jwt RefreshΒ #36: λ¦¬ν”„λ ˆμ‹œ 토큰 λ©”μ»€λ‹ˆμ¦˜ λ„μž…

Suggested labels

βœ… Test, ✨ Feature, πŸ”¨ Refactor

Poem

🐰 ν† ν°μ˜ μΆ€, 헀더에 μ‹€λ €
ν”„λ‘œν•„ 창을 ν™œμ§ μ—΄μ–΄
λ³΄μ•ˆμ˜ 문을 μ‚΄λ©°μ‹œ λ‘λ“œλ¦¬λ‹ˆ
λ°μ΄ν„°λŠ” 반짝이며 흐λ₯΄λ„€
μ½”λ“œμ˜ 토끼, μΆ€μΆ”λ“― λ…Έλž˜ν•΄! πŸŽ‰


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❀️ Share
πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ohyuchan123 ohyuchan123 self-assigned this Jan 15, 2025
@ohyuchan123 ohyuchan123 added πŸ”¨ Refactor μ½”λ“œ λ¦¬νŒ©ν† λ§ ✨ Feature κΈ°λŠ₯ 개발 labels Jan 15, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (1)
src/main/resources/yaml/application-dev.yml (1)

5-5: 파일 끝에 κ°œν–‰ 문자λ₯Ό μΆ”κ°€ν•΄μ£Όμ„Έμš”.

YAML 파일 ν‘œμ€€μ— 따라 파일 끝에 κ°œν–‰ λ¬Έμžκ°€ ν•„μš”ν•©λ‹ˆλ‹€.

 spring:
   jpa:
     show-sql: true
     hibernate:
-      ddl-auto: update
+      ddl-auto: update
+
🧰 Tools
πŸͺ› yamllint (1.35.1)

[error] 5-5: no new line character at the end of file

(new-line-at-end-of-file)

πŸ“œ Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between e009402 and a3bffe3.

πŸ“’ Files selected for processing (5)
  • src/main/java/com/mycom/socket/auth/jwt/JWTFilter.java (2 hunks)
  • src/main/java/com/mycom/socket/go_socket/controller/ProfileController.java (1 hunks)
  • src/main/java/com/mycom/socket/go_socket/dto/response/ProfileResponse.java (1 hunks)
  • src/main/java/com/mycom/socket/go_socket/service/MemberService.java (1 hunks)
  • src/main/resources/yaml/application-dev.yml (1 hunks)
🧰 Additional context used
πŸͺ› yamllint (1.35.1)
src/main/resources/yaml/application-dev.yml

[error] 5-5: no new line character at the end of file

(new-line-at-end-of-file)

πŸ”‡ Additional comments (1)
src/main/resources/yaml/application-dev.yml (1)

5-5: λ°μ΄ν„°λ² μ΄μŠ€ μŠ€ν‚€λ§ˆ 관리 μ „λž΅ 변경에 λŒ€ν•œ κ²€ν† κ°€ ν•„μš”ν•©λ‹ˆλ‹€.

ddl-auto: update 섀정은 κΈ°μ‘΄ 데이터λ₯Ό λ³΄μ‘΄ν•˜λ©΄μ„œ μŠ€ν‚€λ§ˆλ₯Ό μ—…λ°μ΄νŠΈν•˜λ―€λ‘œ 개발 κ³Όμ •μ—μ„œ 데이터 지속성을 κ°œμ„ ν•©λ‹ˆλ‹€. ν•˜μ§€λ§Œ λ‹€μŒ 사항을 κ³ λ €ν•΄μ£Όμ„Έμš”:

  1. μŠ€ν‚€λ§ˆ λ³€κ²½ 이λ ₯ 관리λ₯Ό μœ„ν•΄ Flywayλ‚˜ Liquibase 같은 λ§ˆμ΄κ·Έλ ˆμ΄μ…˜ 도ꡬ λ„μž…μ„ κ²€ν† ν•΄λ³΄μ„Έμš”.
  2. ν”„λ‘œλ•μ…˜ ν™˜κ²½μ—μ„œλŠ” validate λͺ¨λ“œ μ‚¬μš©μ„ ꢌμž₯λ“œλ¦½λ‹ˆλ‹€.

λ‹€μŒ 슀크립트둜 ν˜„μž¬ ν”„λ‘œμ νŠΈμ˜ ν”„λ‘œν•„λ³„ 섀정을 ν™•μΈν•΄λ³΄μ„Έμš”:

βœ… Verification successful

λ°μ΄ν„°λ² μ΄μŠ€ ꡬ성이 μ μ ˆν•˜κ²Œ μ„€μ •λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€.

κΈ°λ³Έ ν”„λ‘œνŒŒμΌμ—μ„œ ddl-auto: none을 μ‚¬μš©ν•˜κ³  개발 ν”„λ‘œνŒŒμΌμ—μ„œλ§Œ update λͺ¨λ“œλ₯Ό ν™œμ„±ν™”ν•˜λŠ” ν˜„μž¬ 섀정은 μ•ˆμ „ν•˜κ³  μ μ ˆν•©λ‹ˆλ‹€. λ‹€λ§Œ, μ œμ•ˆ λ“œλ¦° λŒ€λ‘œ ν–₯ν›„ λ°μ΄ν„°λ² μ΄μŠ€ λ§ˆμ΄κ·Έλ ˆμ΄μ…˜ 도ꡬ λ„μž…μ„ κ³ λ €ν•΄λ³΄μ‹œλ©΄ μ’‹κ² μŠ΅λ‹ˆλ‹€.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check database configuration across different profiles

echo "Checking database configuration across profiles..."
fd -e yml -e yaml . src/main/resources | xargs grep -l "ddl-auto"

Length of output: 255


Script:

#!/bin/bash
# Check the database configuration in both files
echo "=== Default Profile (application.yml) ==="
rg -A 5 -B 5 "ddl-auto" src/main/resources/application.yml

echo -e "\n=== Dev Profile (application-dev.yml) ==="
rg -A 5 -B 5 "ddl-auto" src/main/resources/yaml/application-dev.yml

Length of output: 518

🧰 Tools
πŸͺ› yamllint (1.35.1)

[error] 5-5: no new line character at the end of file

(new-line-at-end-of-file)

Comment on lines +11 to +14
public class MemberService {

private final MemberRepository memberRepository;
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

μ„œλΉ„μŠ€ ν΄λž˜μŠ€μ— ν•„μš”ν•œ λ©”μ„œλ“œ κ΅¬ν˜„μ΄ λˆ„λ½λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

ν˜„μž¬ MemberService ν΄λž˜μŠ€κ°€ λΉ„μ–΄μžˆμŠ΅λ‹ˆλ‹€. ν”„λ‘œν•„ 쑰회 κΈ°λŠ₯을 μœ„ν•΄ λ‹€μŒκ³Ό 같은 λ©”μ„œλ“œλ“€μ˜ κ΅¬ν˜„μ΄ ν•„μš”ν•©λ‹ˆλ‹€:

  • νšŒμ› ν”„λ‘œν•„ 쑰회
  • νšŒμ› 쑴재 μ—¬λΆ€ 확인
  • μ˜ˆμ™Έ 처리 둜직

λ‹€μŒκ³Ό 같은 λ©”μ„œλ“œ κ΅¬ν˜„μ„ μ œμ•ˆλ“œλ¦½λ‹ˆλ‹€:

 @Service
 @RequiredArgsConstructor
 @Transactional(readOnly = true)
 public class MemberService {
     private final MemberRepository memberRepository;
+    
+    public Member getMemberByEmail(String email) {
+        return memberRepository.findByEmail(email)
+            .orElseThrow(() -> new EntityNotFoundException("νšŒμ›μ„ 찾을 수 μ—†μŠ΅λ‹ˆλ‹€."));
+    }
+    
+    public boolean existsByEmail(String email) {
+        return memberRepository.existsByEmail(email);
+    }
 }

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +10 to +16
public static ProfileResponse of(Member member) {
return new ProfileResponse(
member.getEmail(),
member.getNickname(),
member.getIntro()
);
}
Copy link

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

νŒ©ν† λ¦¬ λ©”μ„œλ“œμ— μœ νš¨μ„± 검사와 λ¬Έμ„œν™”κ°€ ν•„μš”ν•©λ‹ˆλ‹€.

of λ©”μ„œλ“œμ— λ‹€μŒ 사항듀이 λˆ„λ½λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€:

  • null 체크
  • JavaDoc λ¬Έμ„œν™”
  • λ―Όκ°ν•œ 정보 λ…ΈμΆœ κ°€λŠ₯μ„± κ²€ν† 

λ‹€μŒκ³Ό 같이 κ°œμ„ μ„ μ œμ•ˆλ“œλ¦½λ‹ˆλ‹€:

+    /**
+     * Member μ—”ν‹°ν‹°λ‘œλΆ€ν„° ProfileResponseλ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
+     *
+     * @param member ν”„λ‘œν•„ 정보λ₯Ό κ°€μ Έμ˜¬ νšŒμ› μ—”ν‹°ν‹° (null이 μ•„λ‹ˆμ–΄μ•Ό 함)
+     * @return μƒμ„±λœ ProfileResponse 객체
+     * @throws IllegalArgumentException memberκ°€ null인 경우
+     */
     public static ProfileResponse of(Member member) {
+        if (member == null) {
+            throw new IllegalArgumentException("Member must not be null");
+        }
+        
         return new ProfileResponse(
                 member.getEmail(),
                 member.getNickname(),
                 member.getIntro()
         );
     }
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public static ProfileResponse of(Member member) {
return new ProfileResponse(
member.getEmail(),
member.getNickname(),
member.getIntro()
);
}
/**
* Member μ—”ν‹°ν‹°λ‘œλΆ€ν„° ProfileResponseλ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
*
* @param member ν”„λ‘œν•„ 정보λ₯Ό κ°€μ Έμ˜¬ νšŒμ› μ—”ν‹°ν‹° (null이 μ•„λ‹ˆμ–΄μ•Ό 함)
* @return μƒμ„±λœ ProfileResponse 객체
* @throws IllegalArgumentException memberκ°€ null인 경우
*/
public static ProfileResponse of(Member member) {
if (member == null) {
throw new IllegalArgumentException("Member must not be null");
}
return new ProfileResponse(
member.getEmail(),
member.getNickname(),
member.getIntro()
);
}

Comment on lines +16 to +19
@GetMapping
public ProfileResponse getProfile(@AuthenticationPrincipal MemberDetails memberDetails) {
return ProfileResponse.of(memberDetails.getMember());
}
Copy link

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

μ»¨νŠΈλ‘€λŸ¬μ— μ˜ˆμ™Έ μ²˜λ¦¬μ™€ API λ¬Έμ„œν™”κ°€ ν•„μš”ν•©λ‹ˆλ‹€.

λ‹€μŒ 사항듀이 λˆ„λ½λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€:

  • 응닡 μƒνƒœ μ½”λ“œ λͺ…μ‹œ
  • Swagger/OpenAPI λ¬Έμ„œν™”
  • μ˜ˆμ™Έ 처리
  • λ‘œκΉ…

λ‹€μŒκ³Ό 같이 κ°œμ„ μ„ μ œμ•ˆλ“œλ¦½λ‹ˆλ‹€:

+    private final Logger log = LoggerFactory.getLogger(ProfileController.class);
+
+    /**
+     * ν˜„μž¬ 인증된 μ‚¬μš©μžμ˜ ν”„λ‘œν•„ 정보λ₯Ό μ‘°νšŒν•©λ‹ˆλ‹€.
+     *
+     * @param memberDetails 인증된 μ‚¬μš©μž 정보
+     * @return μ‚¬μš©μž ν”„λ‘œν•„ 정보
+     */
     @GetMapping
+    @ResponseStatus(HttpStatus.OK)
+    @Operation(summary = "ν”„λ‘œν•„ 쑰회", description = "ν˜„μž¬ λ‘œκ·ΈμΈν•œ μ‚¬μš©μžμ˜ ν”„λ‘œν•„ 정보λ₯Ό μ‘°νšŒν•©λ‹ˆλ‹€.")
+    @ApiResponse(responseCode = "200", description = "ν”„λ‘œν•„ 쑰회 성곡")
+    @ApiResponse(responseCode = "401", description = "μΈμ¦λ˜μ§€ μ•Šμ€ μ‚¬μš©μž")
     public ProfileResponse getProfile(@AuthenticationPrincipal MemberDetails memberDetails) {
+        log.debug("ν”„λ‘œν•„ 쑰회 μš”μ²­: {}", memberDetails.getUsername());
+        if (memberDetails == null) {
+            throw new UnauthorizedException("인증 정보가 μ—†μŠ΅λ‹ˆλ‹€.");
+        }
         return ProfileResponse.of(memberDetails.getMember());
     }

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines 33 to 36
// Bearer 토큰 확인
String bearerToken = resolveTokenFromHeader(request);
if (StringUtils.hasText(bearerToken) && jwtUtil.validateToken(bearerToken, "ACCESS_TOKEN")) {
setAuthentication(bearerToken);
Copy link

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

JWT 토큰 처리 둜직 λ³΄μ•ˆ κ°•ν™”κ°€ ν•„μš”ν•©λ‹ˆλ‹€.

ν˜„μž¬ κ΅¬ν˜„μ—μ„œ λ‹€μŒκ³Ό 같은 λ³΄μ•ˆ κ΄€λ ¨ κ°œμ„ μ‚¬ν•­μ΄ ν•„μš”ν•©λ‹ˆλ‹€:

  • Bearer 접두사 μƒμˆ˜ν™”
  • 토큰 ν˜•μ‹ 검증 κ°•ν™”
  • ꡬ체적인 μ˜ˆμ™Έ 처리

λ‹€μŒκ³Ό 같이 κ°œμ„ μ„ μ œμ•ˆλ“œλ¦½λ‹ˆλ‹€:

+    private static final String BEARER_PREFIX = "Bearer ";
+    private static final String TOKEN_TYPE = "ACCESS_TOKEN";
+
     try {
-        // Bearer 토큰 확인
         String bearerToken = resolveTokenFromHeader(request);
-        if (StringUtils.hasText(bearerToken) && jwtUtil.validateToken(bearerToken, "ACCESS_TOKEN")) {
+        if (isValidBearerToken(bearerToken)) {
             setAuthentication(bearerToken);
         }
     } catch (Exception e) {
private boolean isValidBearerToken(String token) {
    return StringUtils.hasText(token) &&
           token.matches("^[A-Za-z0-9-_=]+\\.[A-Za-z0-9-_=]+\\.?[A-Za-z0-9-_.+/=]*$") &&
           jwtUtil.validateToken(token, TOKEN_TYPE);
}

Comment on lines 46 to 50
private String resolveTokenFromHeader(HttpServletRequest request) {
String bearerToken = request.getHeader("Authorization");
if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) {
return bearerToken.substring(7);
}
Copy link

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

토큰 μΆ”μΆœ λ©”μ„œλ“œμ˜ λ³΄μ•ˆμ„± κ°•ν™”κ°€ ν•„μš”ν•©λ‹ˆλ‹€.

토큰 μΆ”μΆœ μ‹œ λ‹€μŒκ³Ό 같은 λ³΄μ•ˆ 검증이 μΆ”κ°€λ˜μ–΄μ•Ό ν•©λ‹ˆλ‹€:

  • 헀더 쑴재 μ—¬λΆ€ 검증
  • 토큰 길이 μ œν•œ
  • XSS λ°©μ§€λ₯Ό μœ„ν•œ λ¬Έμžμ—΄ μ΄μŠ€μΌ€μ΄ν”„

λ‹€μŒκ³Ό 같이 κ°œμ„ μ„ μ œμ•ˆλ“œλ¦½λ‹ˆλ‹€:

     private String resolveTokenFromHeader(HttpServletRequest request) {
         String bearerToken = request.getHeader("Authorization");
-        if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) {
-            return bearerToken.substring(7);
+        if (!StringUtils.hasText(bearerToken)) {
+            return null;
+        }
+        if (!bearerToken.startsWith(BEARER_PREFIX)) {
+            log.warn("잘λͺ»λœ 토큰 ν˜•μ‹: Bearer 접두사 μ—†μŒ");
+            return null;
+        }
+        String token = bearerToken.substring(BEARER_PREFIX.length());
+        if (token.length() > 1000) {  // μ΅œλŒ€ 토큰 길이 μ œν•œ
+            log.warn("토큰 길이 초과");
+            return null;
         }
-        return null;
+        return HtmlUtils.htmlEscape(token);
     }

Committable suggestion skipped: line range outside the PR's diff.

@ohyuchan123 ohyuchan123 merged commit 22fa66a into develop Jan 15, 2025
2 checks passed
@ohyuchan123 ohyuchan123 changed the title Profile Search πŸ”€ Profile Search Jan 15, 2025
@ohyuchan123 ohyuchan123 deleted the feature/profile-search branch January 15, 2025 09:26
@coderabbitai coderabbitai bot mentioned this pull request Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ Feature κΈ°λŠ₯ 개발 πŸ”¨ Refactor μ½”λ“œ λ¦¬νŒ©ν† λ§

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants