Skip to content

fix(users): 세션 없이 비밀번호 설정 화면에 접근하면 500 대신 로그인으로 보냄 - #1193

Open
stadia wants to merge 1 commit into
mainfrom
fix/password-setup-session
Open

stadia wants to merge 1 commit into
mainfrom
fix/password-setup-session

Conversation

@stadia

@stadia stadia commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Closes #1172

원인

Users::RegistrationsController는 before_action :authenticate_user!로 password 액션을 막으려 했습니다. 하지만 Devise 컨트롤러 안에서 authenticate_user!는 force: true 없이 호출하면 아무것도 하지 않습니다(warden.authenticate! if !devise_controller? || opts.delete(:force)).

그래서 세션이 없거나 만료된 사용자가 GET /account/password에 들어오면 resource가 nil인 채로 렌더링으로 넘어갑니다. 이어서 PwdForm의 form_with(model: nil)이 ArgumentError: Passed nil to the :model argument를 내 500이 됐습니다. edit·update·destroy는 Devise의 authenticate_scope!가 막고 있어서 문제가 없었습니다.

수정

  • 효과가 없던 authenticate_user!와 set_current_user_resource를 지웠습니다.
  • prepend_before_action :authenticate_scope!를 password에도 걸었습니다. 이 콜백은 force 인증을 하고 resource를 설정합니다.
  • 같은 이름의 콜백을 다시 선언하면 Devise의 only 목록을 덮어씁니다. 그래서 네 액션을 모두 적었습니다. password 하나만 적어 봤을 때 나머지 액션 테스트 7개가 nil 오류로 실패해서 확인한 부분입니다.

테스트

  • 추가: 비로그인 GET password → 로그인 페이지로 리다이렉트. 수정 전에는 운영과 같은 ArgumentError로 RED였습니다.
  • 유지: 로그인 사용자 폼 렌더링 테스트(기존).

검증

  • bin/rails test: 1763 runs, 0 failures
  • rspec: 70 examples, 0 failures
  • srb tc, rubocop: OK
  • bin/rake quality: 4/4 (line 82.16%, branch 64.47%, flog method 79.69, class 287.75)

운영 로그로 당시 요청이 비로그인 상태였는지는 확인하지 않았습니다. 코드상 nil resource가 생기는 경로는 이 경우뿐입니다.

🤖 Generated with Claude Code

https://claude.ai/code/session_013Hry66K6wzb2UhKgHmAjuR

Summary by CodeRabbit

  • 버그 수정
    • 로그인하지 않은 상태에서 비밀번호 페이지에 접근하면 로그인 페이지로 이동합니다.

Closes #1172

Users::RegistrationsController는 before_action :authenticate_user!로 password 액션을 막으려 했다.
그러나 Devise 컨트롤러 안의 authenticate_user!는 force 없이는 아무것도 하지 않는다
(`warden.authenticate! if !devise_controller? || opts.delete(:force)`). 그래서 세션이 없거나 만료된
사용자가 GET /account/password에 들어오면 resource가 nil로 남는다. 이어 PwdForm의 form_with(model: nil)이
ArgumentError를 내 500이 났다. edit·update·destroy는 Devise의 authenticate_scope!가 지켜 왔다.

- 효과가 없던 authenticate_user!와 set_current_user_resource를 지운다.
- Devise의 authenticate_scope!(force 인증 + resource 설정)를 password에도 건다.
  같은 이름의 콜백을 다시 선언하면 Devise의 only 목록을 덮으므로 네 액션을 모두 적는다.
- 요청 테스트: 비로그인 GET password → 로그인 페이지로 리다이렉트. 수정 전에는 같은 ArgumentError로
  RED였다. 로그인 사용자 폼 렌더링 테스트는 기존 것을 유지했다.

검증: bin/rails test 1763 runs 0 failures, rspec 70 examples 0 failures, srb tc OK,
rubocop OK, bin/rake quality 4/4 (line 82.16%, branch 64.47%, flog method 79.69, class 287.75).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013Hry66K6wzb2UhKgHmAjuR
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

비밀번호 관련 액션의 인증 콜백을 authenticate_scope!로 변경했습니다. 세션 없이 비밀번호 화면을 요청하면 로그인 페이지로 리다이렉트되는지 확인하는 테스트를 추가했습니다.

Changes: 비밀번호 화면 인증

Layer / File(s) Summary
인증 콜백 및 요청 테스트
app/controllers/users/registrations_controller.rb, test/controllers/users/registrations_controller_test.rb
edit, password, update, destroy 액션에 authenticate_scope!를 먼저 실행하도록 변경했습니다. set_current_user_resource 메서드를 삭제했습니다. 세션 없이 account_password_path를 요청하면 로그인 페이지로 리다이렉트되는지 테스트합니다.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Merge Risk: Minimal · up to ac65e

Unauthenticated users requesting the password screen are now redirected to login instead of hitting a server error. The change is small, tested, and easy to revert, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 제목은 변경의 핵심을 설명합니다. 세션이 없는 사용자가 비밀번호 설정 화면에 접근하면 500 오류 대신 로그인 흐름으로 보내도록 수정하는 내용입니다. raw_summary의 변경 내용(authenticate_user!와 set_current_user_resource 콜백 제거, password 액션을 포함한 네 액션에 authenticate_scope! 적…
Linked Issues check Passed [#1172] 완료 기준 1: 로그인 사용자의 비밀번호 설정 폼 표시. prepend_before_action :authenticate_scope!는 Devise 표준 동작대로 warden.authenticate!(force: true)를 수행하고 resource를 current_user로 설정합니다. 기존 로그인 사용자 폼 렌더링 테스트가 …
Out of Scope Changes check Passed 변경은 app/controllers/users/registrations_controller.rb와 test/controllers/users/registrations_controller_test.rb에 한정됩니다. 제거된 authenticate_user!와 set_current_user_resource는 Devise 컨트롤러에서 효과가 없거나 …
Full details: Title check

Explanation

제목은 변경의 핵심을 설명합니다. 세션이 없는 사용자가 비밀번호 설정 화면에 접근하면 500 오류 대신 로그인 흐름으로 보내도록 수정하는 내용입니다. raw_summary의 변경 내용(authenticate_user!와 set_current_user_resource 콜백 제거, password 액션을 포함한 네 액션에 authenticate_scope! 적용, 비로그인 GET password 리다이렉트 테스트 추가)과 PR 목표(#1193, 이슈 #1172)가 모두 이 제목과 일치합니다. 제목은 한 문장이며 간결하고 구체적입니다. 다만 'fix(users):' 접두사는 Conventional Commits 형식이며 제목의 의미와 무관하게 충족되는 형식 요건이므로 감점 사유가 되지 않습니다.

Full details: Linked Issues check

Explanation

[#1172] 완료 기준 1: 로그인 사용자의 비밀번호 설정 폼 표시. prepend_before_action :authenticate_scope!는 Devise 표준 동작대로 warden.authenticate!(force: true)를 수행하고 resource를 current_user로 설정합니다. 기존 로그인 사용자 폼 렌더링 테스트가 유지됩니다.
[#1172] 완료 기준 2: 세션이 없거나 만료된 사용자 처리. password가 authenticate_scope! 목록에 포함되어 비로그인 요청은 인증 실패 흐름으로 이동합니다. 추가된 테스트 GET password without session redirects to login이 new_user_session_path로의 리다이렉트를 검증합니다.
[#1172] 완료 기준 3: 두 동작의 요청 테스트. 두 동작을 확인하는 요청 테스트가 존재합니다.
edit, update, destroy도 동일한 authenticate_scope! 경로를 사용하므로 기존 보호 동작이 유지됩니다. 코드 확인 범위는 diff와 테스트 diff로 한정되었고, 실행 결과는 PR 설명의 보고에 의존합니다.

Full details: Out of Scope Changes check

Explanation

변경은 app/controllers/users/registrations_controller.rb와 test/controllers/users/registrations_controller_test.rb에 한정됩니다. 제거된 authenticate_user!와 set_current_user_resource는 Devise 컨트롤러에서 효과가 없거나 authenticate_scope!와 중복되는 콜백입니다. 추가된 prepend_before_action과 주석은 #1172의 원인 수정에 직접 해당합니다. 추가된 테스트도 같은 요청 경로를 검증합니다. 이슈와 무관한 변경은 확인되지 않았습니다.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

토끼가 비밀번호 화면을 살펴보네
로그인 길을 또렷이 밝혀 두네
세션이 없으면 문 앞에서 안내하고
테스트가 그 길을 확인하네
깡충, 페이지가 안전히 이어지네

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 86f4dcaf-38d5-4fbe-a443-51676127ade1
Commits

Reviewing files that changed from the base of the PR and between a5032c6 and ac65e01.

Files selected for processing: 2

  • app/controllers/users/registrations_controller.rb
  • test/controllers/users/registrations_controller_test.rb

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T23:36:14.927663Z ac65e01 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

계정의 비밀번호 설정 화면 렌더링 오류 처리

1 participant