Skip to content

fix: TOTP の認証失敗で 500 Internal Server Error が返ってくる#17536

Open
nekochanfood wants to merge 5 commits into
misskey-dev:developfrom
nekochanfood:fix/totp-invalid-credential-error
Open

fix: TOTP の認証失敗で 500 Internal Server Error が返ってくる#17536
nekochanfood wants to merge 5 commits into
misskey-dev:developfrom
nekochanfood:fix/totp-invalid-credential-error

Conversation

@nekochanfood
Copy link
Copy Markdown
Contributor

@nekochanfood nekochanfood commented Jun 3, 2026

What

Backend

TOTP認証失敗時に500エラーが返される問題を修正し、適切なAPIエラーを返すようになります。
また、パスワードとTOTPでの認証のエラーを統一し、どちらの認証が失敗したかを外部から判別できないようになります。

コード 用途
INVALID_CREDENTIAL パスワード+TOTP認証でどちらかが誤っていたとき用(どちらが誤りか曇らせる)
VERIFICATION_FAILED 2FAセットアップ時のTOTP検証失敗用
2FA_SETUP_NOT_INITIATED 2FAセットアップが未開始の状態でi/2fa/doneを呼んだとき用
INCORRECT_PASSWORD パスワードのみの認証で誤っていたとき用(change-password, delete-accountに新規追加)

Frontend

2FA解除時にエラーオブジェクトがそのままダイアログに渡されていた問題を修正しています。

Why

fix #17522

Additional info (optional)

エラーの確認用リスト:

  • パスキー登録(i/2fa/register-key)
  • パスキー登録完了(i/2fa/key-done)
  • パスキー削除(i/2fa/remove-key)
  • 2FAセットアップ(TOTP再登録)(i/2fa/register)
  • 2FAセットアップの完了(i/2fa/done)
  • 2FA解除(i/2fa/unregister)
  • パスワード変更(i/change-password)
  • アカウント削除(i/delete-account)
  • メールアドレス変更(i/update-email)

Checklist

  • Read the contribution guide
  • Test working in a local environment
  • (If needed) Add story of storybook
  • (If needed) Update CHANGELOG.md
  • (If possible) Add tests

パスワード・TOTP検証エラーをINVALID_CREDENTIALに統合し、
どちらが間違っているか判別できないようにした

Closes misskey-dev#17522
apiWithDialogが既にエラーダイアログを表示するため、
冗長な.catch()を削除
TOTP有効時のみINVALID_CREDENTIALに統合し、
パスワード単体認証時はINCORRECT_PASSWORDを返す
@github-actions github-actions Bot added packages/frontend Client side specific issue/PR packages/backend Server side specific issue/PR labels Jun 3, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 3, 2026

Codecov Report

❌ Patch coverage is 1.85185% with 53 lines in your changes missing coverage. Please review.
✅ Project coverage is 24.92%. Comparing base (e50603e) to head (09581bb).
⚠️ Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
...kend/src/server/api/endpoints/i/change-password.ts 0.00% 5 Missing and 2 partials ⚠️
...ckend/src/server/api/endpoints/i/delete-account.ts 0.00% 5 Missing and 2 partials ⚠️
...backend/src/server/api/endpoints/i/2fa/key-done.ts 0.00% 4 Missing and 2 partials ⚠️
...end/src/server/api/endpoints/i/2fa/register-key.ts 0.00% 4 Missing and 2 partials ⚠️
...backend/src/server/api/endpoints/i/2fa/register.ts 0.00% 4 Missing and 2 partials ⚠️
...ckend/src/server/api/endpoints/i/2fa/remove-key.ts 0.00% 4 Missing and 2 partials ⚠️
...ckend/src/server/api/endpoints/i/2fa/unregister.ts 0.00% 4 Missing and 2 partials ⚠️
...backend/src/server/api/endpoints/i/update-email.ts 0.00% 4 Missing and 2 partials ⚠️
...ges/backend/src/server/api/endpoints/i/2fa/done.ts 0.00% 2 Missing ⚠️
packages/backend/src/core/UserAuthService.ts 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #17536      +/-   ##
===========================================
- Coverage    24.93%   24.92%   -0.01%     
===========================================
  Files         1158     1160       +2     
  Lines        39539    39608      +69     
  Branches     11011    11037      +26     
===========================================
+ Hits          9858     9872      +14     
- Misses       23780    23817      +37     
- Partials      5901     5919      +18     

☔ View full report in Codecov by Harness.
📢 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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

このPRによるapi.jsonの差分

差分はこちら
--- base
+++ head
@@ -53573,6 +53573,24 @@
                   "$ref": "#/components/schemas/Error"
                 },
                 "examples": {
+                  "2FA_SETUP_NOT_INITIATED": {
+                    "value": {
+                      "error": {
+                        "message": "2fa setup has not been initiated.",
+                        "code": "2FA_SETUP_NOT_INITIATED",
+                        "id": "283f18c1-5b84-4699-a7a4-2beec808b74c"
+                      }
+                    }
+                  },
+                  "VERIFICATION_FAILED": {
+                    "value": {
+                      "error": {
+                        "message": "Verification failed. Please try again.",
+                        "code": "VERIFICATION_FAILED",
+                        "id": "90a0971b-f73a-4993-b224-8307ba7421e7"
+                      }
+                    }
+                  },
                   "INVALID_PARAM": {
                     "value": {
                       "error": {
@@ -53761,6 +53779,15 @@
                       }
                     }
                   },
+                  "INVALID_CREDENTIAL": {
+                    "value": {
+                      "error": {
+                        "message": "Invalid credential.",
+                        "code": "INVALID_CREDENTIAL",
+                        "id": "430da61f-f346-411b-8aa0-fdeb0736dbe4"
+                      }
+                    }
+                  },
                   "TWO_FACTOR_NOT_ENABLED": {
                     "value": {
                       "error": {
@@ -54113,6 +54140,15 @@
                       }
                     }
                   },
+                  "INVALID_CREDENTIAL": {
+                    "value": {
+                      "error": {
+                        "message": "Invalid credential.",
+                        "code": "INVALID_CREDENTIAL",
+                        "id": "4ccb213e-227e-4c18-8ddb-f2dddb31a9d0"
+                      }
+                    }
+                  },
                   "INVALID_PARAM": {
                     "value": {
                       "error": {
@@ -54288,6 +54324,15 @@
                       }
                     }
                   },
+                  "INVALID_CREDENTIAL": {
+                    "value": {
+                      "error": {
+                        "message": "Invalid credential.",
+                        "code": "INVALID_CREDENTIAL",
+                        "id": "a1189f08-e4a2-462e-b5de-647c312efadb"
+                      }
+                    }
+                  },
                   "TWO_FACTOR_NOT_ENABLED": {
                     "value": {
                       "error": {
@@ -54460,6 +54505,15 @@
                       }
                     }
                   },
+                  "INVALID_CREDENTIAL": {
+                    "value": {
+                      "error": {
+                        "message": "Invalid credential.",
+                        "code": "INVALID_CREDENTIAL",
+                        "id": "c1c5fa72-f66a-4935-b36a-cb8259e4b03e"
+                      }
+                    }
+                  },
                   "INVALID_PARAM": {
                     "value": {
                       "error": {
@@ -54619,6 +54673,15 @@
                       }
                     }
                   },
+                  "INVALID_CREDENTIAL": {
+                    "value": {
+                      "error": {
+                        "message": "Invalid credential.",
+                        "code": "INVALID_CREDENTIAL",
+                        "id": "5ce7354e-d1d0-4305-b37c-9825b766f03f"
+                      }
+                    }
+                  },
                   "INVALID_PARAM": {
                     "value": {
                       "error": {
@@ -55337,6 +55400,24 @@
                   "$ref": "#/components/schemas/Error"
                 },
                 "examples": {
+                  "INCORRECT_PASSWORD": {
+                    "value": {
+                      "error": {
+                        "message": "Incorrect password.",
+                        "code": "INCORRECT_PASSWORD",
+                        "id": "d46ffe5c-200b-4471-aca2-4d0ef197368f"
+                      }
+                    }
+                  },
+                  "INVALID_CREDENTIAL": {
+                    "value": {
+                      "error": {
+                        "message": "Invalid credential.",
+                        "code": "INVALID_CREDENTIAL",
+                        "id": "1e5d4005-3eb0-43f8-b466-87ad864b9fd6"
+                      }
+                    }
+                  },
                   "INVALID_PARAM": {
                     "value": {
                       "error": {
@@ -55711,6 +55792,24 @@
                   "$ref": "#/components/schemas/Error"
                 },
                 "examples": {
+                  "INCORRECT_PASSWORD": {
+                    "value": {
+                      "error": {
+                        "message": "Incorrect password.",
+                        "code": "INCORRECT_PASSWORD",
+                        "id": "9d72604c-9d55-4511-9b96-de11900925c7"
+                      }
+                    }
+                  },
+                  "INVALID_CREDENTIAL": {
+                    "value": {
+                      "error": {
+                        "message": "Invalid credential.",
+                        "code": "INVALID_CREDENTIAL",
+                        "id": "d5af1163-2248-404f-a3d9-7b8c9e019723"
+                      }
+                    }
+                  },
                   "INVALID_PARAM": {
                     "value": {
                       "error": {
@@ -63518,6 +63617,15 @@
                       }
                     }
                   },
+                  "INVALID_CREDENTIAL": {
+                    "value": {
+                      "error": {
+                        "message": "Invalid credential.",
+                        "code": "INVALID_CREDENTIAL",
+                        "id": "b8231819-bd85-4c24-83f1-657a3e0efad8"
+                      }
+                    }
+                  },
                   "UNAVAILABLE": {
                     "value": {
                       "error": {

Get diff files from Workflow Page

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

Backend memory usage comparison

Before GC

Metric base (MB) head (MB) Diff (MB) Diff (%)
VmRSS 307.56 MB 305.57 MB -1.98 MB -0.64%
VmHWM 307.56 MB 305.57 MB -1.98 MB -0.64%
VmSize 23172.73 MB 23170.14 MB -2.59 MB -0.01%
VmData 1372.86 MB 1370.72 MB -2.13 MB -0.15%

After GC

Metric base (MB) head (MB) Diff (MB) Diff (%)
VmRSS 307.56 MB 305.59 MB -1.97 MB -0.64%
VmHWM 307.56 MB 305.59 MB -1.97 MB -0.64%
VmSize 23172.73 MB 23170.64 MB -2.09 MB 0%
VmData 1372.86 MB 1371.22 MB -1.63 MB -0.11%

After Request

Metric base (MB) head (MB) Diff (MB) Diff (%)
VmRSS 307.94 MB 306.11 MB -1.82 MB -0.59%
VmHWM 307.94 MB 306.11 MB -1.82 MB -0.59%
VmSize 23172.73 MB 23170.80 MB -1.92 MB 0%
VmData 1372.86 MB 1371.39 MB -1.47 MB -0.10%

See workflow logs for details

@nekochanfood nekochanfood changed the title Fix/totp invalid credential error fix: TOTP の認証失敗で 500 Internal Server Error が返ってくる Jun 3, 2026
@nekochanfood
Copy link
Copy Markdown
Contributor Author

nekochanfood commented Jun 3, 2026

パスキー追加後(i/2fa/key-done)に求められる認証ではパスワードないしはTOTPが間違っていても通るようになっている 🤔
パスキー追加する前に行った認証の結果を使いまわしている?

追記: Issue に書いた #17537

@nekochanfood nekochanfood marked this pull request as ready for review June 3, 2026 13:45
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 3, 2026
@nekochanfood
Copy link
Copy Markdown
Contributor Author

nekochanfood commented Jun 4, 2026

失敗系のエラーのコードを400から401にしようと思います

@nekochanfood nekochanfood marked this pull request as draft June 4, 2026 00:35
@anatawa12
Copy link
Copy Markdown
Member

https://datatracker.ietf.org/doc/html/rfc9110#name-401-unauthorized

The server generating a 401 response MUST send a WWW-Authenticate header field (Section 11.6.1) containing at least one challenge applicable to the target resource.

適切な WWW-Authenticate がないと思うので 401 は微妙かも

@nekochanfood nekochanfood marked this pull request as ready for review June 4, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages/backend Server side specific issue/PR packages/frontend Client side specific issue/PR size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Development

Successfully merging this pull request may close these issues.

TOTP の認証失敗で 500 Internal Server Error が返ってくる

2 participants