Skip to content

#5898 メンバー登録画面にて2段階認証が有効になっているメンバーの2段階認証をリセットするチェックボックスを追加#6546

Open
AioiLight wants to merge 5 commits intoEC-CUBE:4.3from
AioiLight:two-factor-auth-reset

Conversation

@AioiLight
Copy link
Copy Markdown

@AioiLight AioiLight commented Dec 25, 2025

概要(Overview・Refs Issue)

image

fixes #5898

現在2段階認証はオフにしても新しい認証が設定できるわけではなく、再度有効にしても同じ認証コードのキーが必要になります。

現時点では、ログインした後に再設定することはできますが、ログイン前ではできないため、認証コードを登録したデバイスを紛失したなどの場合においては、データベースを触らない限り再設定ができない状態になっています。

このPRは、メンバーの編集画面にて、2要素認証のキーをリセットすることができるようになります。また、 Issue にコメントしたように、既存の認証キーは有効のまま、一時的に2段階認証を無効化したいというユースケースも考えられるため、今までの無効化の挙動はそのままにしています。

方針(Policy)

メンバーの編集画面に、2段階認証をリセットするチェックボックスを作成しました。

チェックを入れて保存した場合、対象のユーザーの2段階認証キーをnullに設定して、再登録できるようになります。

メンバーの編集が可能な権限を持つ人にリセットを依頼することで、デバイスを紛失したなどの場合でも2段階認証の再設定が可能になります。

実装に関する補足(Appendix)

2段階認証が有効の場合の時のみ、チェックボックスが出現するようになっています。

テスト(Test)

確認した挙動など:

  • 2段階認証が設定されている状態で、ログイン中のメンバーを編集して、チェックを入れてから保存すると直接2段階認証の設定画面に遷移すること
  • 他のメンバーの2段階認証が設定されている状態で、ログイン中ではないメンバーを編集して、チェックを入れて保存した後、対象のメンバーでログインしたときに2段階認証の設定画面に遷移すること
  • チェックを入れないまま保存したときにリセットされないこと

相談(Discussion)

初のContributionになるので、こうした方がよいというところがありましたら教えていただけると幸いです!

マイナーバージョン互換性保持のための制限事項チェックリスト

  • 既存機能の仕様変更はありません
  • フックポイントの呼び出しタイミングの変更はありません
  • フックポイントのパラメータの削除・データ型の変更はありません
  • twigファイルに渡しているパラメータの削除・データ型の変更はありません
  • Serviceクラスの公開関数の、引数の削除・データ型の変更はありません
  • 入出力ファイル(CSVなど)のフォーマット変更はありません

レビュワー確認項目

  • 動作確認
  • コードレビュー
  • E2E/Unit テスト確認(テストの追加・変更が必要かどうか)
  • 互換性が保持されているか
  • セキュリティ上の問題がないか
    • 権限を超えた操作が可能にならないか
    • 不要なファイルアップロードがないか
    • 外部へ公開されるファイルや機能の追加ではないか
    • テンプレートでのエスケープ漏れがないか

Summary by CodeRabbit

  • 新機能
    • メンバー編集画面に2段階認証リセット機能を追加しました。2段階認証が有効なメンバーに対して、チェックボックスを操作することで2段階認証をリセットし、認証アプリに登録された設定を削除できるようになります。

@dotani1111
Copy link
Copy Markdown
Contributor

@AioiLight
PRありがとうございます!
ご対応助かります。
こちら確認いたします。

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 26, 2025

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.37%. Comparing base (028898e) to head (2493f19).
⚠️ Report is 10 commits behind head on 4.3.

Files with missing lines Patch % Lines
...ntroller/Admin/Setting/System/MemberController.php 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                4.3    #6546      +/-   ##
============================================
+ Coverage     78.65%   79.37%   +0.71%     
+ Complexity     6824     6670     -154     
============================================
  Files           476      476              
  Lines         27074    26705     -369     
============================================
- Hits          21295    21196      -99     
+ Misses         5779     5509     -270     
Flag Coverage Δ
Unit 79.37% <83.33%> (+0.71%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dotani1111 dotani1111 added the improvement 機能改善 label Jan 7, 2026
@dotani1111 dotani1111 added this to the 4.4.0 milestone Jan 7, 2026
Comment thread src/Eccube/Resource/locale/messages.ja.yaml Outdated
@dotani1111
Copy link
Copy Markdown
Contributor

以下、動作確認を致しました。
問題ありませんでした。
・2段階認証の登録→リセット→再登録→ログインの一連の流れを確認
・新規登録画面および2段階認証が無効なメンバーの編集画面では、「2段階認証をリセット」が表示されないことを確認

@dotani1111
Copy link
Copy Markdown
Contributor

@AioiLight
細かいですが、1点コメントを致しました。
ご確認お願い致します!

@AioiLight
Copy link
Copy Markdown
Author

@dotani1111
該当部分変更してから再度Pushしています。よろしくお願いいたします。

@dotani1111 dotani1111 self-assigned this Mar 18, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 18, 2026

📝 Walkthrough

Walkthrough

メンバー編集フロー内に二要素認証リセット機能を追加しました。チェックボックス追加、リセット時に2FAキーをクリア、対応する翻訳キー追加、テンプレートに条件付き表示を実装しました。

Changes

Cohort / File(s) Summary
二要素認証リセット機能の実装
src/Eccube/Controller/Admin/Setting/System/MemberController.php, src/Eccube/Form/Type/Admin/MemberType.php, src/Eccube/Resource/template/admin/Setting/System/member_edit.twig
二要素認証リセットチェックボックスを追加し、有効時にそのボックスがチェックされている場合、2FAキー(two_factor_auth_key)をクリアする機能を実装。テンプレートでは2FA有効時のみリセット項目を表示。
翻訳キー追加
src/Eccube/Resource/locale/messages.en.yaml, src/Eccube/Resource/locale/messages.ja.yaml
英語と日本語ロケールにadmin.setting.system.member.two_factor_auth_resetおよびtooltip.setting.system.member.two_factor_auth_resetの翻訳キーを追加。リセット機能のラベルと詳細説明を含む。

Sequence Diagram(s)

sequenceDiagram
    participant Admin as 管理者
    participant Form as メンバーフォーム
    participant Controller as MemberController
    participant DB as メンバーDB

    Admin->>Form: 2FAリセットをチェック
    Form->>Controller: フォーム送信
    Controller->>Controller: two_factor_auth_resetの値を確認
    alt two_factor_auth_resetがTrueで2FAが有効な場合
        Controller->>DB: two_factor_auth_keyをクリア
    end
    Controller->>DB: メンバー情報を保存
    DB-->>Controller: 保存完了
    Controller-->>Admin: 処理完了
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰✨ リセットボタンで問題解決、
スマホなくしても再登録できる、
QRコード新しく生まれ変わり、
メンバーさん笑顔で認証かな! 🔐🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed タイトルは2段階認証をリセットするチェックボックス追加という変更の主要な目的を明確に説明しており、プルリクエストの内容と完全に関連しています。
Linked Issues check ✅ Passed プルリクエストは#5898の要件を満たしており、2FA有効メンバーの2FAをリセット可能にし、新規登録を可能にします。
Out of Scope Changes check ✅ Passed すべての変更は2FAリセット機能の実装に関連しており、スコープ外の変更は含まれていません。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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 and usage tips.

Tip

CodeRabbit can use OpenGrep to find security vulnerabilities and bugs across 17+ programming languages.

OpenGrep is compatible with Semgrep configurations. Add an opengrep.yml or semgrep.yml configuration file to your project to enable OpenGrep analysis.

Copy link
Copy Markdown

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Eccube/Controller/Admin/Setting/System/MemberController.php`:
- Around line 169-171: 現在の条件は Member->isTwoFactorAuthEnabled() と AND
になっているため、同一送信で2FAを無効化した場合に two_factor_auth_reset が無視され旧キーが残ります。MemberController
の該当箇所で two_factor_auth_reset の値を先に確認し、true のときは isTwoFactorAuthEnabled() に依存せず必ず
Member->setTwoFactorAuthKey(null) を呼ぶように修正してください(つまり two_factor_auth_reset
のチェックを独立させるか、条件式をリセットフラグ優先に変更してください)。

In `@src/Eccube/Resource/locale/messages.en.yaml`:
- Line 1779: The tooltip text for key
tooltip.setting.system.member.two_factor_auth_reset contains awkward English
("unable to use your authentication app some reasons"); update the string to
natural, professional English such as: "Checking this box will reset the
two-factor authentication for this member. If you reset it, the code stored in
their authentication app will no longer be valid and the device will no longer
be registered. If you cannot use your authentication app for any reason, reset
it and re-register on a new device." Replace the existing value for
tooltip.setting.system.member.two_factor_auth_reset with this corrected sentence
while preserving YAML formatting and punctuation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0a9edf85-d35f-4f06-b55a-7f5f69cfedef

📥 Commits

Reviewing files that changed from the base of the PR and between 438abbf and 2493f19.

📒 Files selected for processing (5)
  • src/Eccube/Controller/Admin/Setting/System/MemberController.php
  • src/Eccube/Form/Type/Admin/MemberType.php
  • src/Eccube/Resource/locale/messages.en.yaml
  • src/Eccube/Resource/locale/messages.ja.yaml
  • src/Eccube/Resource/template/admin/Setting/System/member_edit.twig

Comment on lines +169 to +171
if ($Member->isTwoFactorAuthEnabled() && $form->get('two_factor_auth_reset')->getData()) {
$Member->setTwoFactorAuthKey(null);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

two_factor_auth_enabled とのAND条件でリセット要求が無視されます

Line 169 の条件だと、同一送信で2FAを無効化した場合に、two_factor_auth_reset をチェックしていても鍵が消えません。結果として「リセットしたつもり」で旧キーが残るため、再登録フローの期待とずれます。two_factor_auth_reset が true のときは enabled 状態に依存せず鍵をクリアするのが安全です。

💡 修正案
-            if ($Member->isTwoFactorAuthEnabled() && $form->get('two_factor_auth_reset')->getData()) {
+            if ($form->get('two_factor_auth_reset')->getData()) {
                 $Member->setTwoFactorAuthKey(null);
             }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Eccube/Controller/Admin/Setting/System/MemberController.php` around lines
169 - 171, 現在の条件は Member->isTwoFactorAuthEnabled() と AND
になっているため、同一送信で2FAを無効化した場合に two_factor_auth_reset が無視され旧キーが残ります。MemberController
の該当箇所で two_factor_auth_reset の値を先に確認し、true のときは isTwoFactorAuthEnabled() に依存せず必ず
Member->setTwoFactorAuthKey(null) を呼ぶように修正してください(つまり two_factor_auth_reset
のチェックを独立させるか、条件式をリセットフラグ優先に変更してください)。

tooltip.setting.system.member.authority: You can select the authorization you have set under Authorization.
tooltip.setting.system.member.work: You can set customers to inactive temporarily. If they are no longer necessary, please delete from All Customers.
tooltip.setting.system.member.two_factor_auth_enabled: If enabled, you must log in using two-factor authentication. You will be able to login after setting up two-factor authentication.
tooltip.setting.system.member.two_factor_auth_reset: Checking this box will reset the two-factor authentication for this member. If you reset it, the code currently stored in the authentication app will no longer be usable and will no longer be registered. If you are unable to use your authentication app some reasons, reset it and re-register on a new device.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

英語ツールチップに文法不備があります

Line 1779 の "unable to use your authentication app some reasons" は不自然な英語です。管理画面文言として修正したほうがよいです。

✍️ 修正案
-tooltip.setting.system.member.two_factor_auth_reset: Checking this box will reset the two-factor authentication for this member. If you reset it, the code currently stored in the authentication app will no longer be usable and will no longer be registered. If you are unable to use your authentication app some reasons, reset it and re-register on a new device.
+tooltip.setting.system.member.two_factor_auth_reset: Checking this box will reset two-factor authentication for this member. After reset, the code currently registered in the authentication app will no longer be usable. If you are unable to use your authentication app for some reason, reset it and re-register on a new device.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Eccube/Resource/locale/messages.en.yaml` at line 1779, The tooltip text
for key tooltip.setting.system.member.two_factor_auth_reset contains awkward
English ("unable to use your authentication app some reasons"); update the
string to natural, professional English such as: "Checking this box will reset
the two-factor authentication for this member. If you reset it, the code stored
in their authentication app will no longer be valid and the device will no
longer be registered. If you cannot use your authentication app for any reason,
reset it and re-register on a new device." Replace the existing value for
tooltip.setting.system.member.two_factor_auth_reset with this corrected sentence
while preserving YAML formatting and punctuation.

@dotani1111
Copy link
Copy Markdown
Contributor

@AioiLight
確認ありがとうございます!

追加で、こちらの対応することは可能でしょうか?
https://github.com/EC-CUBE/ec-cube/pull/6546/changes#r2951529795

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

Labels

improvement 機能改善

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2段階認証の無効→有効時に認証用のQRコードが生成されない

2 participants