Skip to content

feat: 게스트 세션 토큰 발급 및 본인 검증 - #164

Merged
Kohseoyoung merged 4 commits into
mainfrom
feature/162-guest-session-token
Aug 11, 2026
Merged

feat: 게스트 세션 토큰 발급 및 본인 검증 #164
Kohseoyoung merged 4 commits into
mainfrom
feature/162-guest-session-token

Conversation

@Kohseoyoung

@Kohseoyoung Kohseoyoung commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🔗 관련 이슈 (Related Issue)

Closes #162

📝 작업 내용

게스트가 guestId(숫자)만으로 본인 확인되던 구조의 사칭 취약점을 막기 위해, 게스트 등록 시 세션 토큰을 발급하고 이후 요청마다 토큰을 검증하도록 구현했습니다.

문제

  • 기존에는 요청 body의 guestId만으로 게스트를 식별 → guestId가 노출되면 다른 사람이 그 값으로 남의 피드백/답글을 수정·삭제할 수 있었음

변경 사항

  • Guest 엔티티에 sessionToken(UUID) 컬럼 추가, 등록 시 자동 발급 (V016 마이그레이션)
  • 게스트 등록 응답(GuestCreateResDTO)에 sessionToken 포함
  • FeedbackService / FeedbackDetailServicevalidateGuestAccess에 토큰 일치 검증 추가
  • 피드백·답글 게스트 경로(작성/수정/삭제/조회)에서 X-Guest-Token 헤더를 받아 서비스로 전달
  • 토큰 불일치·누락 시 403(SHARELINK403) 반환

설계 메모

테스트 (로컬 Swagger)

  • 게스트 등록 → sessionToken 발급 (201) ✅
  • 토큰 일치 → 피드백 작성 201 ✅
  • 토큰 불일치 → 403 ✅
  • 헤더 누락 → 403 ✅

✅ PR 체크리스트

  • PR 제목은 커밋 컨벤션을 따랐습니다.
  • 관련 이슈를 연결했습니다.
  • 변경 사항에 대한 테스트를 진행했습니다.

Summary by CodeRabbit

  • 새로운 기능
    • 게스트에게 본인 확인용 세션 토큰이 발급됩니다.
    • 피드백과 답글의 작성·조회·수정·삭제에 게스트 세션 토큰을 사용할 수 있습니다.
  • 보안 개선
    • 게스트 토큰과 공유 링크 권한을 함께 확인해 타인의 피드백 및 답글 접근을 차단합니다.
    • 기존 회원 권한 검증은 유지됩니다.
  • API 변경
    • 발급된 세션 토큰이 응답에 포함되며, 이후 요청의 X-Guest-Token 헤더로 사용할 수 있습니다.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4ac6042b-41a6-4204-81b5-db9b48899c7f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

게스트 생성 시 UUID 기반 세션 토큰을 발급합니다. 원문 토큰은 응답에 포함하고 SHA-256 해시는 Guest에 저장합니다. 피드백과 답글 API는 X-Guest-Token을 받아 게스트 접근 검증에 사용합니다.

Changes

게스트 세션 토큰 저장 및 응답

Layer / File(s) Summary
게스트 세션 토큰 저장 및 응답
src/main/java/com/slatto/domain/sharelink/..., src/main/java/com/slatto/global/util/TokenHasher.java, src/main/resources/db/migration/*
게스트 생성 시 원문 UUID 토큰을 응답하고 SHA-256 해시를 저장합니다. 데이터베이스 컬럼을 VARCHAR(64) NOT NULL로 변경합니다.

피드백 접근 인증

Layer / File(s) Summary
피드백 토큰 전달 및 검증
src/main/java/com/slatto/domain/feedback/controller/FeedbackController.java, src/main/java/com/slatto/domain/feedback/service/FeedbackService.java, src/test/java/com/slatto/domain/feedback/service/FeedbackActivityLogConnectionTest.java
피드백 생성, 수정, 삭제, 목록 조회 API가 X-Guest-Token을 전달합니다. FeedbackService는 해시 토큰을 저장 토큰과 비교합니다.

답글 접근 인증

Layer / File(s) Summary
답글 토큰 전달 및 검증
src/main/java/com/slatto/domain/feedback/controller/FeedbackDetailController.java, src/main/java/com/slatto/domain/feedback/service/FeedbackDetailService.java, src/test/java/com/slatto/domain/feedback/service/FeedbackActivityLogConnectionTest.java
답글 생성, 목록 조회, 수정, 삭제 API가 X-Guest-Token을 전달합니다. FeedbackDetailService는 게스트 토큰을 검증한 뒤 기존 공유 링크와 영상 접근 검증을 수행합니다.

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: 피드백 처리 결과
Loading

Possibly related PRs

  • SLAT-TO/SLATE-TO-BE#157: FeedbackServiceFeedbackDetailService의 게스트 접근 검증 흐름과 관련됩니다.

Suggested labels: feature

Suggested reviewers: guingguing, young0206, chazy-d

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 제목이 게스트 세션 토큰 발급과 본인 검증이라는 주요 변경 사항을 명확하게 설명합니다.
Description check ✅ Passed 관련 이슈, 작업 내용, 설계 메모, 테스트 결과와 체크리스트를 모두 포함합니다.
Linked Issues check ✅ Passed [162]의 토큰 발급·저장·응답·검증과 피드백 및 답글 경로 적용 요구사항을 변경 사항이 충족합니다.
Out of Scope Changes check ✅ Passed 변경 사항이 게스트 세션 토큰 발급, 저장, 검증 및 관련 API·마이그레이션 범위에 포함됩니다.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between bafa0e8 and 803ad66.

📒 Files selected for processing (9)
  • src/main/java/com/slatto/domain/feedback/controller/FeedbackController.java
  • src/main/java/com/slatto/domain/feedback/controller/FeedbackDetailController.java
  • src/main/java/com/slatto/domain/feedback/service/FeedbackDetailService.java
  • src/main/java/com/slatto/domain/feedback/service/FeedbackService.java
  • src/main/java/com/slatto/domain/sharelink/converter/ShareLinkConverter.java
  • src/main/java/com/slatto/domain/sharelink/dto/response/ShareLinkResponse.java
  • src/main/java/com/slatto/domain/sharelink/entity/Guest.java
  • src/main/resources/db/migration/V016__guest_session_token.sql
  • src/test/java/com/slatto/domain/feedback/service/FeedbackActivityLogConnectionTest.java

Comment thread src/main/java/com/slatto/domain/sharelink/entity/Guest.java Outdated
Comment on lines +3 to +5
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

기존 게스트의 접근 권한이 배포 후 즉시 끊깁니다.

이 마이그레이션은 기존 guest 행에 새 토큰을 생성하지만, 기존 클라이언트에는 그 값을 전달하지 않습니다. 이후 FeedbackServiceFeedbackDetailService는 누락되거나 일치하지 않는 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.

@Kohseoyoung Kohseoyoung self-assigned this Aug 11, 2026
@Kohseoyoung

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 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

📥 Commits

Reviewing files that changed from the base of the PR and between bafa0e8 and 51ceef3.

📒 Files selected for processing (12)
  • src/main/java/com/slatto/domain/feedback/controller/FeedbackController.java
  • src/main/java/com/slatto/domain/feedback/controller/FeedbackDetailController.java
  • src/main/java/com/slatto/domain/feedback/service/FeedbackDetailService.java
  • src/main/java/com/slatto/domain/feedback/service/FeedbackService.java
  • src/main/java/com/slatto/domain/sharelink/converter/ShareLinkConverter.java
  • src/main/java/com/slatto/domain/sharelink/dto/response/ShareLinkResponse.java
  • src/main/java/com/slatto/domain/sharelink/entity/Guest.java
  • src/main/java/com/slatto/domain/sharelink/service/ShareLinkService.java
  • src/main/java/com/slatto/global/util/TokenHasher.java
  • src/main/resources/db/migration/V016__guest_session_token.sql
  • src/main/resources/db/migration/V017__guest_session_token_hash.sql
  • src/test/java/com/slatto/domain/feedback/service/FeedbackActivityLogConnectionTest.java

@Kohseoyoung
Kohseoyoung merged commit bc65a3c into main Aug 11, 2026
2 checks passed
@guingguing guingguing added the feature 새로운 기능 추가 label Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature 새로운 기능 추가

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FEAT: 게스트 세션 토큰 발급 및 본인 검증

3 participants