feat: 게스트 세션 토큰 발급 및 본인 검증 - #164
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthrough게스트 생성 시 UUID 기반 세션 토큰을 발급합니다. 원문 토큰은 응답에 포함하고 SHA-256 해시는 Changes게스트 세션 토큰 저장 및 응답
피드백 접근 인증
답글 접근 인증
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Guest
participant ShareLinkService
participant FeedbackController
participant FeedbackService
participant TokenHasher
participant GuestEntity
Guest->>ShareLinkService: 게스트 생성 요청
ShareLinkService->>TokenHasher: UUID 토큰 해시
ShareLinkService->>GuestEntity: 해시 토큰 저장
ShareLinkService-->>Guest: sessionToken 포함 응답
Guest->>FeedbackController: X-Guest-Token 포함 요청
FeedbackController->>FeedbackService: guestToken 전달
FeedbackService->>TokenHasher: 요청 토큰 해시
FeedbackService->>GuestEntity: 저장 토큰 비교
FeedbackService-->>FeedbackController: 피드백 처리 결과
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/test/java/com/slatto/domain/feedback/service/FeedbackActivityLogConnectionTest.java (1)
114-121: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win토큰 거부 경로를 테스트하세요.
현재 테스트는 일치하는 토큰만 검증합니다. 누락된 토큰과 다른 토큰이
ShareLinkErrorCode.GUEST_ACCESS_DENIED를 발생시키고 저장 및 활동 로그 생성을 하지 않는지 검증하세요.
src/test/java/com/slatto/domain/feedback/service/FeedbackActivityLogConnectionTest.java#L114-L121: 게스트 피드백 생성에 누락 및 불일치 토큰 테스트를 추가하세요.src/test/java/com/slatto/domain/feedback/service/FeedbackActivityLogConnectionTest.java#L161-L168: 게스트 답글 생성에 누락 및 불일치 토큰 테스트를 추가하세요.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/test/java/com/slatto/domain/feedback/service/FeedbackActivityLogConnectionTest.java` around lines 114 - 121, In src/test/java/com/slatto/domain/feedback/service/FeedbackActivityLogConnectionTest.java lines 114-121, extend the guest feedback creation tests to cover both a missing token and a mismatched token, asserting ShareLinkErrorCode.GUEST_ACCESS_DENIED and verifying neither feedback saving nor activity-log creation occurs. In the same file lines 161-168, add equivalent missing- and mismatched-token cases for guest reply creation, with the same exception and no-persistence assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main/java/com/slatto/domain/sharelink/entity/Guest.java`:
- Around line 29-40: Update Guest session-token handling so create generates a
raw token only for the one-time response while storing only its one-way digest
in sessionToken; ensure request X-Guest-Token values are digested before
comparison and never expose the stored digest in response DTOs. Adjust
Guest.create and the related authentication/response mapping symbols
accordingly, preserving token-based guest verification.
In `@src/main/resources/db/migration/V016__guest_session_token.sql`:
- Around line 3-5: Update the V016 migration and its guest-session rollout flow
so existing guests do not lose access when session_token is introduced. Define
and implement either an explicit session-expiration policy or, if existing
guests must remain supported, a safe token reissue path based on their
already-verifiable credentials, ensuring FeedbackService and
FeedbackDetailService continue accepting authorized requests without requiring
undistributed random tokens.
---
Nitpick comments:
In
`@src/test/java/com/slatto/domain/feedback/service/FeedbackActivityLogConnectionTest.java`:
- Around line 114-121: In
src/test/java/com/slatto/domain/feedback/service/FeedbackActivityLogConnectionTest.java
lines 114-121, extend the guest feedback creation tests to cover both a missing
token and a mismatched token, asserting ShareLinkErrorCode.GUEST_ACCESS_DENIED
and verifying neither feedback saving nor activity-log creation occurs. In the
same file lines 161-168, add equivalent missing- and mismatched-token cases for
guest reply creation, with the same exception and no-persistence assertions.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 21478c97-4eef-4208-a23f-e292c098b690
📒 Files selected for processing (9)
src/main/java/com/slatto/domain/feedback/controller/FeedbackController.javasrc/main/java/com/slatto/domain/feedback/controller/FeedbackDetailController.javasrc/main/java/com/slatto/domain/feedback/service/FeedbackDetailService.javasrc/main/java/com/slatto/domain/feedback/service/FeedbackService.javasrc/main/java/com/slatto/domain/sharelink/converter/ShareLinkConverter.javasrc/main/java/com/slatto/domain/sharelink/dto/response/ShareLinkResponse.javasrc/main/java/com/slatto/domain/sharelink/entity/Guest.javasrc/main/resources/db/migration/V016__guest_session_token.sqlsrc/test/java/com/slatto/domain/feedback/service/FeedbackActivityLogConnectionTest.java
| ALTER TABLE guest ADD COLUMN session_token VARCHAR(36); | ||
| UPDATE guest SET session_token = UUID() WHERE session_token IS NULL; | ||
| ALTER TABLE guest MODIFY COLUMN session_token VARCHAR(36) NOT NULL UNIQUE; No newline at end of file |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
기존 게스트의 접근 권한이 배포 후 즉시 끊깁니다.
이 마이그레이션은 기존 guest 행에 새 토큰을 생성하지만, 기존 클라이언트에는 그 값을 전달하지 않습니다. 이후 FeedbackService와 FeedbackDetailService는 누락되거나 일치하지 않는 X-Guest-Token을 거부합니다. 따라서 기존 게스트는 자신이 작성한 피드백과 답글을 조회, 수정, 삭제할 수 없습니다.
배포 전에 기존 게스트 세션의 종료 정책 또는 안전한 토큰 재발급 절차를 정의하세요. 기존 게스트를 지원해야 하면, 기존 게스트가 이미 보유한 검증 가능한 자격 증명을 기반으로 토큰을 발급해야 합니다.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/main/resources/db/migration/V016__guest_session_token.sql` around lines 3
- 5, Update the V016 migration and its guest-session rollout flow so existing
guests do not lose access when session_token is introduced. Define and implement
either an explicit session-expiration policy or, if existing guests must remain
supported, a safe token reissue path based on their already-verifiable
credentials, ensuring FeedbackService and FeedbackDetailService continue
accepting authorized requests without requiring undistributed random tokens.
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/test/java/com/slatto/domain/feedback/service/FeedbackActivityLogConnectionTest.java (1)
120-128: 🔒 Security & Privacy | 🔵 Trivial | 🏗️ Heavy lift게스트 토큰 거부 테스트를 추가하세요.
서비스 단위 테스트에서 토큰 누락 및 불일치 시
GUEST_ACCESS_DENIED를 검증하세요. 별도의MockMvc통합 테스트에서 피드백 작성과 답글 작성 API의X-Guest-Token전달, HTTP 403,SHARELINK403응답을 검증하세요.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/test/java/com/slatto/domain/feedback/service/FeedbackActivityLogConnectionTest.java` around lines 120 - 128, Add service-level tests around FeedbackActivityLogConnectionTest covering missing and mismatched guest tokens, asserting GUEST_ACCESS_DENIED. Add separate MockMvc integration tests for feedback creation and reply creation that verify X-Guest-Token is supplied and invalid or absent tokens produce HTTP 403 with a SHARELINK403 response.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@src/test/java/com/slatto/domain/feedback/service/FeedbackActivityLogConnectionTest.java`:
- Around line 120-128: Add service-level tests around
FeedbackActivityLogConnectionTest covering missing and mismatched guest tokens,
asserting GUEST_ACCESS_DENIED. Add separate MockMvc integration tests for
feedback creation and reply creation that verify X-Guest-Token is supplied and
invalid or absent tokens produce HTTP 403 with a SHARELINK403 response.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 4cb031a6-18f4-4430-9d4b-f31cd987291c
📒 Files selected for processing (12)
src/main/java/com/slatto/domain/feedback/controller/FeedbackController.javasrc/main/java/com/slatto/domain/feedback/controller/FeedbackDetailController.javasrc/main/java/com/slatto/domain/feedback/service/FeedbackDetailService.javasrc/main/java/com/slatto/domain/feedback/service/FeedbackService.javasrc/main/java/com/slatto/domain/sharelink/converter/ShareLinkConverter.javasrc/main/java/com/slatto/domain/sharelink/dto/response/ShareLinkResponse.javasrc/main/java/com/slatto/domain/sharelink/entity/Guest.javasrc/main/java/com/slatto/domain/sharelink/service/ShareLinkService.javasrc/main/java/com/slatto/global/util/TokenHasher.javasrc/main/resources/db/migration/V016__guest_session_token.sqlsrc/main/resources/db/migration/V017__guest_session_token_hash.sqlsrc/test/java/com/slatto/domain/feedback/service/FeedbackActivityLogConnectionTest.java
🔗 관련 이슈 (Related Issue)
Closes #162
📝 작업 내용
게스트가
guestId(숫자)만으로 본인 확인되던 구조의 사칭 취약점을 막기 위해, 게스트 등록 시 세션 토큰을 발급하고 이후 요청마다 토큰을 검증하도록 구현했습니다.문제
guestId만으로 게스트를 식별 →guestId가 노출되면 다른 사람이 그 값으로 남의 피드백/답글을 수정·삭제할 수 있었음변경 사항
Guest엔티티에sessionToken(UUID) 컬럼 추가, 등록 시 자동 발급 (V016마이그레이션)GuestCreateResDTO)에sessionToken포함FeedbackService/FeedbackDetailService의validateGuestAccess에 토큰 일치 검증 추가X-Guest-Token헤더를 받아 서비스로 전달SHARELINK403) 반환설계 메모
X-Guest-Token헤더 (회원 JWT와 분리)테스트 (로컬 Swagger)
sessionToken발급 (201) ✅✅ PR 체크리스트
Summary by CodeRabbit
X-Guest-Token헤더로 사용할 수 있습니다.