Skip to content

fix(security): 認証オフ時の削除PINにも総当たり制限を適用する - #58

Merged
HR0101 merged 3 commits into
mainfrom
fix/destructive-pin-lockout
Nov 3, 2026
Merged

HR0101 merged 3 commits into
mainfrom
fix/destructive-pin-lockout

Conversation

@HR0101

@HR0101 HR0101 commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Closes #19

概要

通常の認証をオフ(authEnabled=false)にし、削除系操作のPIN保護(requirePINForDeletion=true)のみを有効にした場合、削除系エンドポイントへの誤ったPIN入力が総当たり制限(ロックアウト)の対象にならない問題(Issue #19)を修正しました。

原因と解決策

  • 原因:
    • ServerViewModel.protectedDestructive が authEnabled=false かつ requirePINForDeletion=true の場合に PINSecurity.constantTimeEquals を直接呼び出しており、通常の認証経路(isAuthorized / recordAuthResult)を通らないため、IPごとの失敗回数記録と指数バックオフによるロックアウトが適用されていなかった。
  • 解決策:
    1. MediaServerKit にスレッドセーフな PINLockoutTracker を追加し、IPごとの連続失敗回数の記録・指数バックオフによるロックアウト判定・定数時間PIN比較・成功時のカウンターリセットを一本化。
    2. ServerViewModel の通常認証(isAuthorized)と削除系操作のPIN保護(protectedDestructive)の双方が共通の checkPIN(_:)(PINLockoutTracker.verify)を経由するように変更。
    3. PINLockoutTrackerTests を追加し、連続失敗によるロックアウト・ロックアウト中の正しいPIN拒否・遅延経過後の解除・指数バックオフ・成功時の失敗カウンターリセット・IP単位の独立性を検証。

機能・変更内容別コミット一覧

  1. 2a4190d - feat(security): IPごとの連続失敗回数と指数バックオフを管理するPINLockoutTrackerを追加
    • Packages/MediaServerKit/Sources/MediaServerKit/PINSecurity.swift
  2. 3ef9682 - fix(server): 認証オフ時の削除PIN検証にもPINLockoutTracker経由で総当たり制限を適用
    • ArkServer/Features/Server/ViewModels/ServerViewModel.swift
  3. 9ec77f2 - test(security): PINLockoutTrackerのロックアウト・指数バックオフ・リセットの単体テストを追加
    • Packages/MediaServerKit/Tests/MediaServerKitTests/PINSecurityTests.swift

検証

  • swift test --package-path Packages/MediaServerKit: 全33件のテスト(新規追加の PINLockoutTrackerTests 8件を含む)がパスすることを確認。

@coderabbitai

coderabbitai Bot commented Nov 3, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 41b29ef6-bb24-43dc-ab3f-ac732fd6942f
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@HR0101
HR0101 merged commit 56dcec5 into main Nov 3, 2026
2 checks passed
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.

[Security] 認証オフ時の削除PINにも総当たり制限を適用する

1 participant