Skip to content

feat(#332): アクセス元IP制限オプションの追加#348

Merged
Kewton merged 3 commits intodevelopfrom
feature/332-worktree
Feb 22, 2026
Merged

feat(#332): アクセス元IP制限オプションの追加#348
Kewton merged 3 commits intodevelopfrom
feature/332-worktree

Conversation

@Kewton
Copy link
Owner

@Kewton Kewton commented Feb 22, 2026

Summary

Changes

New files

  • src/lib/ip-restriction.ts - Edge Runtime互換CIDRマッチングコアモジュール(parseAllowedIps/getAllowedRanges/isIpAllowed/normalizeIp/isIpRestrictionEnabled/getClientIp)
  • tests/unit/ip-restriction.test.ts - 47テストケース

Modified files

  • server.ts - X-Real-IPヘッダー注入(CM_TRUST_PROXY対応)
  • src/middleware.ts - IP制限チェック(Step 1、認証・WebSocket処理前)
  • src/lib/ws-server.ts - WebSocket upgradeハンドラーIP制限 + console.log削除
  • src/lib/env.ts - Envインターフェース拡張
  • src/cli/utils/daemon.ts - authEnvKeys拡張 + REVERSE_PROXY_WARNING条件追加
  • src/cli/types/index.ts - StartOptions拡張
  • src/cli/index.ts - --allowed-ips/--trust-proxyオプション追加
  • src/cli/commands/start.ts - 環境変数転送・警告抑制
  • src/cli/commands/init.ts - IP制限ヒント追加
  • src/cli/commands/status.ts - IP制限状態表示
  • src/cli/config/security-messages.ts - --allowed-ips案内追加
  • tests/integration/auth-middleware.test.ts - IP制限統合テスト6件追加
  • tsconfig.server.json - ip-restriction.ts追加

Security

  • DoS防止: MAX_ALLOWED_IP_ENTRIES=256、MAX_CIDR_ENTRY_LENGTH=18
  • ログインジェクション防止: normalizeIp() + substring(0,45)
  • fail-fast: 不正CIDR設定時はサーバー起動エラー
  • CM_TRUST_PROXY非準拠値のconsole.warn

Test plan

  • TypeScript型チェック: 0 errors
  • ESLint: 0 errors/warnings
  • 単体テスト: 3796 passed (185 files)
  • ip-restriction.ts専用テスト: 47 passed
  • 結合テスト: 17 passed
  • npm run build:server: success
  • 手動確認: CM_ALLOWED_IPS設定時のHTTPアクセス制限動作
  • 手動確認: WebSocket接続のIP制限動作
  • 手動確認: CLIオプション(--allowed-ips、--trust-proxy)動作

Closes #332

🤖 Generated with Claude Code

Kewton and others added 3 commits February 22, 2026 22:12
…cess

- Add src/lib/ip-restriction.ts with Edge Runtime compatible CIDR matching
- Inject X-Real-IP header in server.ts for trusted IP identification
- Add IP restriction check in middleware.ts (Step 1, before auth)
- Add IP restriction check in ws-server.ts (defense-in-depth)
- Extend CLI with --allowed-ips and --trust-proxy options
- Add daemon.ts authEnvKeys for CM_ALLOWED_IPS/CM_TRUST_PROXY
- Add 45 unit tests and 6 integration tests for IP restriction
- All static analysis checks passed (tsc, ESLint)

Resolves #332

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…le.log

Reorganize ip-restriction.ts module-scope initialization before dependent
functions for better readability. Enhance JSDoc with S4-001 future extension
notes and S4-002/S4-005 rationale. Remove console.log statements from
ws-server.ts per CLAUDE.md production rules. Fix daemon.ts REVERSE_PROXY_WARNING
to account for CM_ALLOWED_IPS (consistent with start.ts).

Improvements:
- ip-restriction.ts: module-scope vars moved before getClientIp() that references them
- ip-restriction.ts: enhanced JSDoc for S1-004, S4-001, S4-002, S4-005, S4-006
- ws-server.ts: removed 8 console.log calls, kept console.warn/error for security/errors
- daemon.ts: added CM_ALLOWED_IPS check to suppress REVERSE_PROXY_WARNING

Quality Metrics:
- TypeScript errors: 0
- ESLint errors: 0
- Unit tests: 3796 passed (185 files)
- Integration auth-middleware tests: 17 passed

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…orts

- Add ip-restriction.ts entry to CLAUDE.md module list
- Add Issue #332 to docs/implementation-history.md
- Add design policy, issue review, design review, and TDD reports

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Kewton Kewton merged commit 4160187 into develop Feb 22, 2026
5 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.

1 participant