musubix 3.6.0 → 3.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/.github/AGENTS.md +949 -0
  2. package/.github/prompts/sdd-change-apply.prompt.md +283 -0
  3. package/.github/prompts/sdd-change-archive.prompt.md +241 -0
  4. package/.github/prompts/sdd-change-init.prompt.md +269 -0
  5. package/.github/prompts/sdd-design.prompt.md +250 -0
  6. package/.github/prompts/sdd-implement.prompt.md +387 -0
  7. package/.github/prompts/sdd-requirements.prompt.md +193 -0
  8. package/.github/prompts/sdd-review.prompt.md +155 -0
  9. package/.github/prompts/sdd-security.prompt.md +228 -0
  10. package/.github/prompts/sdd-steering.prompt.md +269 -0
  11. package/.github/prompts/sdd-tasks.prompt.md +255 -0
  12. package/.github/prompts/sdd-test.prompt.md +230 -0
  13. package/.github/prompts/sdd-validate.prompt.md +304 -0
  14. package/.github/skills/build-fix/SKILL.md +124 -0
  15. package/.github/skills/checkpoint/SKILL.md +131 -0
  16. package/.github/skills/codemap/SKILL.md +120 -0
  17. package/.github/skills/codemap/templates/codemap-index.md +142 -0
  18. package/.github/skills/codemap/templates/package-codemap.md +160 -0
  19. package/.github/skills/context-optimizer/SKILL.md +109 -0
  20. package/.github/skills/context-optimizer/contexts/dev.md +40 -0
  21. package/.github/skills/context-optimizer/contexts/research.md +55 -0
  22. package/.github/skills/context-optimizer/contexts/review.md +49 -0
  23. package/.github/skills/e2e-runner/SKILL.md +145 -0
  24. package/.github/skills/eval-harness/SKILL.md +111 -0
  25. package/.github/skills/eval-harness/examples/capability-eval.md +158 -0
  26. package/.github/skills/eval-harness/examples/human-grader-template.md +326 -0
  27. package/.github/skills/eval-harness/examples/regression-eval.md +228 -0
  28. package/.github/skills/learning-hooks/SKILL.md +101 -0
  29. package/.github/skills/learning-hooks/templates/learned-skill-template.md +79 -0
  30. package/.github/skills/musubix-adr-generation/SKILL.md +74 -0
  31. package/.github/skills/musubix-best-practices/SKILL.md +85 -0
  32. package/.github/skills/musubix-c4-design/SKILL.md +86 -0
  33. package/.github/skills/musubix-code-generation/SKILL.md +90 -0
  34. package/.github/skills/musubix-domain-inference/SKILL.md +82 -0
  35. package/.github/skills/musubix-ears-validation/SKILL.md +74 -0
  36. package/.github/skills/musubix-sdd-workflow/SKILL.md +95 -0
  37. package/.github/skills/musubix-technical-writing/SKILL.md +108 -0
  38. package/.github/skills/musubix-test-generation/SKILL.md +88 -0
  39. package/.github/skills/musubix-traceability/SKILL.md +94 -0
  40. package/.github/skills/refactor-cleaner/SKILL.md +105 -0
  41. package/.github/skills/session-manager/SKILL.md +119 -0
  42. package/.github/skills/session-manager/scripts/session-end.sh +175 -0
  43. package/.github/skills/session-manager/scripts/session-start.sh +87 -0
  44. package/.github/skills/verification-loop/SKILL.md +111 -0
  45. package/.github/skills/verification-loop/scripts/verify.sh +305 -0
  46. package/AGENTS.md +333 -0
  47. package/LICENSE +21 -0
  48. package/README.ja.md +313 -0
  49. package/README.md +315 -50
  50. package/bin/musubix-mcp.js +15 -0
  51. package/bin/musubix.js +9 -1
  52. package/docs/API-REFERENCE.md +1425 -0
  53. package/docs/CODEMAPS/CODEMAP.md +1 -0
  54. package/docs/GITHUB-ACTIONS-NPM-SETUP.md +132 -0
  55. package/docs/INSTALL-GUIDE.ja.md +459 -0
  56. package/docs/INSTALL-GUIDE.md +459 -0
  57. package/docs/MIGRATION-v3.0.md +324 -0
  58. package/docs/MUSUBI-enhancement_roadmap_20260105.md +651 -0
  59. package/docs/MUSUBIX-v3.0-User-Guide.md +1357 -0
  60. package/docs/MUSUBIXv2.2.0-Manual-outline.md +136 -0
  61. package/docs/MUSUBIXv2.2.0-Manual.md +3123 -0
  62. package/docs/MUSUBIXv2.3.5-Refactering.md +1310 -0
  63. package/docs/MUSUBIv1.6.1-enhancement_roadmap_20260105.md +291 -0
  64. package/docs/MUSUBIv2.2.0-USERGUIDE.md +2079 -0
  65. package/docs/ROADMAP-v1.5.md +116 -0
  66. package/docs/SwarmCoding.md +1284 -0
  67. package/docs/Test-prompt.md +105 -0
  68. package/docs/USER-GUIDE-v1.8.0.md +2371 -0
  69. package/docs/USER-GUIDE.ja.md +2147 -0
  70. package/docs/USER-GUIDE.md +3022 -0
  71. package/docs/YATA-GLOBAL-GUIDE.ja.md +750 -0
  72. package/docs/YATA-GLOBAL-GUIDE.md +595 -0
  73. package/docs/YATA-LOCAL-GUIDE.ja.md +989 -0
  74. package/docs/YATA-LOCAL-GUIDE.md +730 -0
  75. package/docs/adr/0001-real-time-pattern-learning-architecture-for-v1-5-0.md +75 -0
  76. package/docs/adr/0002-pattern-sharing-protocol-for-cross-team-collaborat.md +79 -0
  77. package/docs/adr/0003-owl-2-rl-implementation-strategy-for-advanced-infe.md +90 -0
  78. package/docs/adr/ADR-v3.4.0-001-deep-research-architecture.md +217 -0
  79. package/docs/adr/ADR-v3.4.0-002-search-provider-selection.md +308 -0
  80. package/docs/adr/ADR-v3.4.0-003-lm-api-integration.md +475 -0
  81. package/docs/adr/ADR-v3.7.0-001-everything-claude-code-integration.md +102 -0
  82. package/docs/enterprise-knowledge-management.md +1737 -0
  83. package/docs/evolution-from-musubi-to-musubix.md +2170 -0
  84. package/docs/experiments/EXPERIMENT-ASSISTANT-AXIS-DRIFT-DETECTION.md +155 -0
  85. package/docs/getting-started-with-sdd.md +1602 -0
  86. package/docs/moodle-refactering-codegraph-musubix.md +391 -0
  87. package/docs/moodle-refactering-codegraph.md +278 -0
  88. package/docs/overview/MUSUBIX-CodeGraph.md +322 -0
  89. package/docs/overview/MUSUBIX-Core.md +671 -0
  90. package/docs/overview/MUSUBIX-Decisions.md +494 -0
  91. package/docs/overview/MUSUBIX-FormalVerify.md +566 -0
  92. package/docs/overview/MUSUBIX-Knowledge.md +1231 -0
  93. package/docs/overview/MUSUBIX-Learning.md +837 -0
  94. package/docs/overview/MUSUBIX-MCP-Server.md +535 -0
  95. package/docs/overview/MUSUBIX-Overview.md +264 -0
  96. package/docs/overview/MUSUBIX-Phase1-Complete.md +271 -0
  97. package/docs/overview/MUSUBIX-Phase2-Complete.md +310 -0
  98. package/docs/overview/MUSUBIX-Policy.md +477 -0
  99. package/docs/overview/MUSUBIX-Roadmap-v2.md +399 -0
  100. package/docs/overview/MUSUBIX-Security-Plan.md +939 -0
  101. package/docs/overview/MUSUBIX-Security-v2.1.md +668 -0
  102. package/docs/overview/MUSUBIX-Security.md +891 -0
  103. package/docs/overview/MUSUBIX-YATA.md +666 -0
  104. package/docs/overview/MUSUBIX-v2.2.0-Advanced-Learning.md +513 -0
  105. package/docs/overview/Neuro-SymbolicAI.md +159 -0
  106. package/docs/packages/knowledge.md +594 -0
  107. package/docs/qiita/musubix-v3.6.0-fastrender-insights.md +625 -0
  108. package/docs/qiita-linux-kernel-knowledge-graph.md +596 -0
  109. package/docs/qiita-musubix-assistant-axis.md +380 -0
  110. package/package.json +58 -52
  111. package/scripts/generate-quality-gate-report.ts +106 -0
  112. package/scripts/postinstall.js +94 -0
  113. package/scripts/register-release-knowledge.ts +127 -0
  114. package/steering/.musubi-version +1 -0
  115. package/steering/product.ja.md +572 -0
  116. package/steering/project.yml +66 -0
  117. package/steering/rules/constitution.md +491 -0
  118. package/steering/structure.ja.md +503 -0
  119. package/steering/tech.ja.md +208 -0
  120. package/dist/index.d.ts +0 -25
  121. package/dist/index.d.ts.map +0 -1
  122. package/dist/index.js +0 -74
  123. package/dist/index.js.map +0 -1
@@ -0,0 +1,891 @@
1
+ # MUSUBIX セキュリティ分析パッケージ
2
+
3
+ **パッケージ名**: `@nahisaho/musubix-security`
4
+ **バージョン**: 1.8.0
5
+ **最終更新**: 2026-01-07
6
+
7
+ ---
8
+
9
+ ## 1. 概要
10
+
11
+ `@nahisaho/musubix-security` は、TypeScript/JavaScriptプロジェクトの包括的なセキュリティ分析を提供するパッケージです。OWASP Top 10およびCWE Top 25に基づく脆弱性検出、シークレット漏洩検出、テイント解析、依存関係監査を統合します。
12
+
13
+ ### 1.1 主要機能
14
+
15
+ | 機能 | 説明 |
16
+ |------|------|
17
+ | **脆弱性スキャン** | SQLインジェクション、XSS、コマンドインジェクション等の検出 |
18
+ | **シークレット検出** | API キー、認証情報、秘密鍵のハードコード検出 |
19
+ | **テイント解析** | ユーザー入力から危険な関数へのデータフロー追跡 |
20
+ | **依存関係監査** | npm audit統合による脆弱な依存関係の検出 |
21
+ | **自動修正生成** | 検出された脆弱性に対する修正コードの提案 |
22
+ | **レポート生成** | JSON/Markdown/HTML/SARIF形式のレポート出力 |
23
+ | **自動修正・修復** | AutoFixer、パッチ生成、修正検証(Phase 5) |
24
+ | **セキュリティインテリジェンス** | 脅威フィード統合、MITRE ATT&CK対応(Phase 6) |
25
+ | **リスク分析** | CVSS計算、予測分析、異常検出(Phase 6) |
26
+
27
+ ### 1.2 モジュール構成
28
+
29
+ ```
30
+ packages/security/src/
31
+ ├── analysis/ # 解析エンジン
32
+ │ ├── vulnerability-scanner.ts # 脆弱性スキャナ
33
+ │ ├── secret-detector.ts # シークレット検出
34
+ │ ├── taint-analyzer.ts # テイント解析
35
+ │ └── dependency-auditor.ts # 依存関係監査
36
+ ├── services/ # サービス層
37
+ │ ├── security-service.ts # 統合サービス
38
+ │ ├── fix-generator.ts # 修正生成
39
+ │ ├── fix-verifier.ts # 修正検証
40
+ │ └── report-generator.ts # レポート生成
41
+ ├── remediation/ # 自動修正(Phase 5)
42
+ │ ├── auto-fixer.ts # 自動修正エンジン
43
+ │ ├── fix-validator.ts # 修正検証
44
+ │ ├── patch-generator.ts # パッチ生成
45
+ │ ├── remediation-planner.ts # 修復計画
46
+ │ └── secure-code-transformer.ts # セキュアコード変換
47
+ ├── intelligence/ # セキュリティインテリジェンス(Phase 6)
48
+ │ ├── threat-intelligence.ts # 脅威インテリジェンス
49
+ │ ├── attack-pattern-matcher.ts # MITRE ATT&CK統合
50
+ │ ├── risk-scorer.ts # リスクスコアリング
51
+ │ ├── security-analytics.ts # セキュリティ分析
52
+ │ └── predictive-analyzer.ts # 予測分析
53
+ ├── infrastructure/ # インフラストラクチャ
54
+ │ ├── ast-parser.ts # AST解析
55
+ │ ├── file-scanner.ts # ファイルスキャン
56
+ │ ├── config-loader.ts # 設定読み込み
57
+ │ └── cache.ts # キャッシュ
58
+ ├── mcp/ # MCPツール統合
59
+ │ ├── server.ts # MCPサーバー
60
+ │ └── tools.ts # MCPツール定義
61
+ ├── cli/ # CLIインターフェース
62
+ │ └── commands.ts # CLIコマンド
63
+ ├── types/ # 型定義
64
+ │ ├── vulnerability.ts # 脆弱性型
65
+ │ ├── secret.ts # シークレット型
66
+ │ ├── taint.ts # テイント型
67
+ │ ├── fix.ts # 修正型
68
+ │ ├── dependency.ts # 依存関係型
69
+ │ └── config.ts # 設定型
70
+ └── index.ts # エントリポイント
71
+ ```
72
+
73
+ ---
74
+
75
+ ## 2. 脆弱性スキャン
76
+
77
+ ### 2.1 概要
78
+
79
+ ts-morphを使用したAST解析により、ソースコード内のセキュリティ脆弱性を静的に検出します。
80
+
81
+ ### 2.2 VulnerabilityScanner
82
+
83
+ ```typescript
84
+ import { VulnerabilityScanner } from '@nahisaho/musubix-security';
85
+
86
+ const scanner = new VulnerabilityScanner();
87
+
88
+ // 単一ファイルスキャン(Vulnerability[]を返す)
89
+ const vulnerabilities = scanner.scanFile('src/api.ts');
90
+
91
+ // ディレクトリスキャン(ScanResultを返す)
92
+ const result = await scanner.scanDirectory('./src');
93
+
94
+ console.log(result.vulnerabilities); // 検出された脆弱性
95
+ console.log(result.scannedFiles); // スキャンしたファイル数
96
+ console.log(result.summary); // 重要度別サマリー
97
+ ```
98
+
99
+ ### 2.3 検出可能な脆弱性
100
+
101
+ | カテゴリ | CWE | 検出パターン | 重要度 |
102
+ |---------|-----|-------------|--------|
103
+ | **SQLインジェクション** | CWE-89 | 文字列連結/テンプレートリテラルによるクエリ構築 | Critical |
104
+ | **コマンドインジェクション** | CWE-78 | exec, execSync, spawn への動的入力 | Critical |
105
+ | **XSS** | CWE-79 | innerHTML, document.write への未サニタイズ出力 | High |
106
+ | **パストラバーサル** | CWE-22 | ユーザー入力を含むファイルパス操作 | High |
107
+ | **コードインジェクション** | CWE-94 | eval, new Function の使用 | Critical |
108
+ | **NoSQLインジェクション** | CWE-943 | MongoDB等への動的クエリ | High |
109
+ | **オープンリダイレクト** | CWE-601 | 未検証のリダイレクトURL | Medium |
110
+ | **XXE** | CWE-611 | XML外部エンティティ参照 | High |
111
+
112
+ ### 2.4 Vulnerability型
113
+
114
+ ```typescript
115
+ interface Vulnerability {
116
+ id: string; // 一意のID (VULN-YYYYMMDD-NNN)
117
+ ruleId: string; // ルールID (sql-injection等)
118
+ name: string; // 脆弱性名
119
+ description: string; // 説明
120
+ severity: Severity; // critical/high/medium/low/info
121
+ location: SourceLocation; // ファイル/行/列
122
+ cweId?: string; // CWE ID
123
+ owaspCategory?: string; // OWASP カテゴリ
124
+ snippet?: string; // コードスニペット
125
+ remediation?: string; // 修正ガイダンス
126
+ }
127
+
128
+ type Severity = 'critical' | 'high' | 'medium' | 'low' | 'info';
129
+ ```
130
+
131
+ ---
132
+
133
+ ## 3. シークレット検出
134
+
135
+ ### 3.1 概要
136
+
137
+ ソースコードやコンフィグファイル内にハードコードされた機密情報を検出します。
138
+
139
+ ### 3.2 SecretDetector
140
+
141
+ ```typescript
142
+ import { SecretDetector } from '@nahisaho/musubix-security';
143
+
144
+ const detector = new SecretDetector();
145
+
146
+ // コンテンツスキャン(Secret[]を返す)
147
+ const secrets = detector.scanContent(content, 'config.ts');
148
+
149
+ // ディレクトリスキャン(SecretScanResultを返す)
150
+ const result = await detector.scan('./src');
151
+
152
+ console.log(result.summary.total); // 検出されたシークレット数
153
+ console.log(result.scannedFiles); // スキャンしたファイル数
154
+ ```
155
+
156
+ ### 3.3 検出可能なシークレット
157
+
158
+ | タイプ | パターン | 重要度 |
159
+ |--------|---------|--------|
160
+ | **AWS Access Key** | `AKIA[0-9A-Z]{16}` | Critical |
161
+ | **AWS Secret Key** | 40文字のbase64文字列 | Critical |
162
+ | **GitHub Token** | `ghp_*`, `gho_*`, `ghu_*`, `ghs_*`, `ghr_*` | Critical |
163
+ | **Private Key** | PEM形式の秘密鍵 | Critical |
164
+ | **Database URL** | `postgres://`, `mongodb://`, `mysql://` | High |
165
+ | **JWT Secret** | JWT署名シークレット | High |
166
+ | **Stripe Key** | `sk_live_*`, `sk_test_*` | Critical/Low |
167
+ | **Slack Webhook** | `https://hooks.slack.com/services/...` | Medium |
168
+ | **Azure Connection** | Azure接続文字列 | Critical |
169
+
170
+ ### 3.4 Secret型
171
+
172
+ ```typescript
173
+ interface Secret {
174
+ id: string; // 一意のID (SEC-YYYYMMDD-NNN)
175
+ type: SecretType; // シークレットタイプ
176
+ value: string; // 検出された値
177
+ masked: string; // マスクされた値
178
+ file: string; // ファイルパス
179
+ line: number; // 行番号
180
+ column: number; // 列番号
181
+ context: string; // コンテキスト情報
182
+ confidence: number; // 信頼度 (0-1)
183
+ isTestValue: boolean; // テスト用の値かどうか
184
+ }
185
+ ```
186
+
187
+ ### 3.5 カスタムパターン
188
+
189
+ ```typescript
190
+ const detector = new SecretDetector({
191
+ customPatterns: [
192
+ {
193
+ id: 'custom-api-key',
194
+ name: 'Custom API Key',
195
+ type: 'custom-key',
196
+ severity: 'high',
197
+ regex: /MYAPP_KEY_[A-Z0-9]{32}/g,
198
+ enabled: true,
199
+ },
200
+ ],
201
+ });
202
+ ```
203
+
204
+ ---
205
+
206
+ ## 4. テイント解析
207
+
208
+ ### 4.1 概要
209
+
210
+ ユーザー入力(ソース)から危険な関数呼び出し(シンク)へのデータフローを追跡し、未サニタイズのデータが脆弱性を引き起こす可能性を検出します。
211
+
212
+ ### 4.2 TaintAnalyzer
213
+
214
+ ```typescript
215
+ import { TaintAnalyzer } from '@nahisaho/musubix-security';
216
+
217
+ const analyzer = new TaintAnalyzer();
218
+ const result = analyzer.analyze('./src');
219
+
220
+ console.log(result.sources); // テイントソース(ユーザー入力)
221
+ console.log(result.sinks); // テイントシンク(危険な関数)
222
+ console.log(result.paths); // ソースからシンクへのパス
223
+ ```
224
+
225
+ ### 4.3 テイントソースカテゴリ
226
+
227
+ | カテゴリ | 説明 | 例 |
228
+ |---------|------|-----|
229
+ | `user-input` | ユーザー入力 | `req.body`, `req.query`, `req.params` |
230
+ | `database` | データベース出力 | `db.query()` の結果 |
231
+ | `file-system` | ファイル読み取り | `fs.readFileSync()` |
232
+ | `network` | ネットワーク応答 | `fetch()`, `axios` の結果 |
233
+ | `environment` | 環境変数 | `process.env.*` |
234
+ | `cli-args` | コマンドライン引数 | `process.argv` |
235
+
236
+ ### 4.4 テイントシンクカテゴリ
237
+
238
+ | カテゴリ | 危険性 | 例 |
239
+ |---------|--------|-----|
240
+ | `sql-query` | SQLインジェクション | `db.query()`, `knex.raw()` |
241
+ | `command-exec` | コマンドインジェクション | `exec()`, `spawn()` |
242
+ | `html-output` | XSS | `innerHTML`, `document.write()` |
243
+ | `file-read` | パストラバーサル | `fs.readFile()` |
244
+ | `file-write` | 任意ファイル書き込み | `fs.writeFile()` |
245
+ | `eval` | コードインジェクション | `eval()`, `new Function()` |
246
+ | `redirect` | オープンリダイレクト | `res.redirect()` |
247
+
248
+ ### 4.5 TaintResult型
249
+
250
+ ```typescript
251
+ interface TaintResult {
252
+ sources: TaintSource[]; // 検出されたソース
253
+ sinks: TaintSink[]; // 検出されたシンク
254
+ paths: TaintPath[]; // ソース→シンクのパス
255
+ sanitizers: string[]; // 検出されたサニタイザ
256
+ summary: {
257
+ totalSources: number;
258
+ totalSinks: number;
259
+ totalPaths: number;
260
+ bySeverity: Record<Severity, number>;
261
+ };
262
+ }
263
+ ```
264
+
265
+ ---
266
+
267
+ ## 5. 依存関係監査
268
+
269
+ ### 5.1 概要
270
+
271
+ npm auditを統合し、プロジェクトの依存関係に含まれる既知の脆弱性を検出します。
272
+
273
+ ### 5.2 DependencyAuditor
274
+
275
+ ```typescript
276
+ import { DependencyAuditor } from '@nahisaho/musubix-security';
277
+
278
+ const auditor = new DependencyAuditor();
279
+ const result = await auditor.audit('./project');
280
+
281
+ console.log(result.vulnerabilities); // 脆弱な依存関係
282
+ console.log(result.upgradeSuggestions); // アップグレード提案
283
+ ```
284
+
285
+ ### 5.3 AuditResult型
286
+
287
+ ```typescript
288
+ interface AuditResult {
289
+ vulnerabilities: VulnerableDependency[];
290
+ upgradeSuggestions: UpgradeSuggestion[];
291
+ summary: {
292
+ total: number;
293
+ critical: number;
294
+ high: number;
295
+ medium: number;
296
+ low: number;
297
+ };
298
+ timestamp: Date;
299
+ }
300
+
301
+ interface VulnerableDependency {
302
+ name: string; // パッケージ名
303
+ version: string; // 現在のバージョン
304
+ severity: Severity; // 重要度
305
+ vulnerability: {
306
+ id: string; // 脆弱性ID (GHSA-*, CVE-*)
307
+ title: string; // タイトル
308
+ description: string; // 説明
309
+ patchedVersions: string; // 修正バージョン
310
+ };
311
+ }
312
+ ```
313
+
314
+ ---
315
+
316
+ ## 6. 統合セキュリティサービス
317
+
318
+ ### 6.1 SecurityService
319
+
320
+ すべてのセキュリティ機能を統合したサービスクラス。
321
+
322
+ ```typescript
323
+ import { createSecurityService } from '@nahisaho/musubix-security';
324
+
325
+ const service = createSecurityService();
326
+
327
+ // フルスキャン
328
+ const result = await service.scan({
329
+ target: './src',
330
+ vulnerabilities: true,
331
+ taint: true,
332
+ secrets: true,
333
+ dependencies: true,
334
+ generateFixes: true,
335
+ });
336
+
337
+ // クイックスキャン(脆弱性のみ)
338
+ const quickResult = await service.quickScan('./src');
339
+
340
+ // 単一ファイルスキャン
341
+ const fileResult = await service.scanFile('src/api.ts');
342
+
343
+ // テイント解析のみ
344
+ const taintResult = await service.analyzeTaint('./src');
345
+
346
+ // シークレット検出のみ
347
+ const secretResult = await service.detectSecrets('./src');
348
+
349
+ // 依存関係監査のみ
350
+ const auditResult = await service.auditDependencies('./project');
351
+ ```
352
+
353
+ ### 6.2 FullScanResult型
354
+
355
+ ```typescript
356
+ interface FullScanResult {
357
+ metadata: {
358
+ target: string;
359
+ timestamp: Date;
360
+ duration: number;
361
+ filesScanned: number;
362
+ };
363
+ vulnerabilities: ScanResult;
364
+ taint?: TaintResult;
365
+ secrets?: SecretScanResult;
366
+ dependencies?: AuditResult;
367
+ fixes?: Fix[];
368
+ summary: {
369
+ totalVulnerabilities: number;
370
+ totalSecrets: number;
371
+ totalTaintPaths: number;
372
+ fixesGenerated: number;
373
+ bySeverity: Record<Severity, number>;
374
+ };
375
+ }
376
+ ```
377
+
378
+ ---
379
+
380
+ ## 7. レポート生成
381
+
382
+ ### 7.1 ReportGenerator
383
+
384
+ 複数のフォーマットでセキュリティレポートを生成します。
385
+
386
+ ```typescript
387
+ const report = await service.generateReport(scanResult, 'sarif');
388
+
389
+ // 対応フォーマット
390
+ type ReportFormat = 'json' | 'markdown' | 'html' | 'sarif';
391
+ ```
392
+
393
+ ### 7.2 SARIF形式
394
+
395
+ GitHub Code Scanningと互換性のあるSARIF 2.1.0形式を出力。
396
+
397
+ ```json
398
+ {
399
+ "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
400
+ "version": "2.1.0",
401
+ "runs": [{
402
+ "tool": {
403
+ "driver": {
404
+ "name": "MUSUBIX Security Scanner",
405
+ "version": "1.8.0"
406
+ }
407
+ },
408
+ "results": [...]
409
+ }]
410
+ }
411
+ ```
412
+
413
+ ### 7.3 Markdown形式
414
+
415
+ ```markdown
416
+ # Security Scan Report
417
+
418
+ ## Summary
419
+
420
+ | Severity | Count |
421
+ |----------|-------|
422
+ | Critical | 2 |
423
+ | High | 5 |
424
+ | Medium | 10 |
425
+
426
+ ## Vulnerabilities
427
+
428
+ ### SQL Injection (CWE-89)
429
+ - **File**: src/db.ts:42
430
+ - **Severity**: Critical
431
+ - **Description**: ...
432
+ ```
433
+
434
+ ### 7.4 HTML形式
435
+
436
+ 視覚的なダッシュボード形式のHTMLレポートを生成。
437
+
438
+ ---
439
+
440
+ ## 8. 修正生成
441
+
442
+ ### 8.1 FixGenerator
443
+
444
+ 検出された脆弱性に対する修正コードを自動生成します。
445
+
446
+ ```typescript
447
+ import { createSecurityService } from '@nahisaho/musubix-security';
448
+
449
+ const service = createSecurityService();
450
+ const scanResult = await service.scan({
451
+ target: './src',
452
+ generateFixes: true,
453
+ });
454
+
455
+ for (const fix of scanResult.fixes) {
456
+ console.log(`Fix for ${fix.vulnerabilityId}:`);
457
+ console.log(`Strategy: ${fix.strategy}`);
458
+ console.log(`Confidence: ${fix.confidence}`);
459
+ for (const edit of fix.edits) {
460
+ console.log(`${edit.file}:${edit.startLine}`);
461
+ console.log(`- ${edit.originalCode}`);
462
+ console.log(`+ ${edit.newCode}`);
463
+ }
464
+ }
465
+ ```
466
+
467
+ ### 8.2 修正戦略
468
+
469
+ | 戦略 | 対象脆弱性 | 説明 |
470
+ |------|-----------|------|
471
+ | `parameterized-query` | SQLインジェクション | プリペアドステートメントに変換 |
472
+ | `escape-html` | XSS | HTMLエスケープを追加 |
473
+ | `shell-escape` | コマンドインジェクション | シェルエスケープを追加 |
474
+ | `path-sanitize` | パストラバーサル | パス正規化を追加 |
475
+ | `remove-eval` | コードインジェクション | eval を安全な代替に置換 |
476
+
477
+ ### 8.3 Fix型
478
+
479
+ ```typescript
480
+ interface Fix {
481
+ id: string; // 修正ID
482
+ vulnerabilityId: string; // 対象脆弱性ID
483
+ description: string; // 修正説明
484
+ strategy: FixStrategy; // 修正戦略
485
+ confidence: number; // 信頼度 (0-1)
486
+ edits: CodeEdit[]; // コード編集
487
+ }
488
+
489
+ interface CodeEdit {
490
+ file: string;
491
+ startLine: number;
492
+ endLine: number;
493
+ originalCode: string;
494
+ newCode: string;
495
+ }
496
+ ```
497
+
498
+ ---
499
+
500
+ ## 9. 自動修正・修復システム(Phase 5)
501
+
502
+ ### 9.1 AutoFixer
503
+
504
+ 検出された脆弱性に対する自動修正を生成します。
505
+
506
+ ```typescript
507
+ import { AutoFixer, createAutoFixer } from '@nahisaho/musubix-security';
508
+
509
+ const fixer = createAutoFixer();
510
+
511
+ // 脆弱性に対する修正を生成
512
+ const fixes = fixer.generateFixes(vulnerability, {
513
+ maxFixes: 3,
514
+ minConfidence: 0.7,
515
+ includeBreakingChanges: false,
516
+ preferredStrategies: ['sanitization', 'parameterization'],
517
+ });
518
+
519
+ // 修正を適用
520
+ const result = fixer.applyFix(fixes[0], fileContent);
521
+ ```
522
+
523
+ ### 9.2 FixValidator
524
+
525
+ 修正の適用前に検証を行います。
526
+
527
+ ```typescript
528
+ import { FixValidator, createFixValidator } from '@nahisaho/musubix-security';
529
+
530
+ const validator = createFixValidator();
531
+
532
+ // 修正の検証
533
+ const result = await validator.validate(fix, originalCode, fixedCode);
534
+
535
+ console.log(result.valid); // 検証結果
536
+ console.log(result.checks); // 検証チェック一覧
537
+ console.log(result.score); // スコア (0-100)
538
+ console.log(result.recommendations); // 推奨事項
539
+ ```
540
+
541
+ ### 9.3 PatchGenerator
542
+
543
+ 修正をパッチ形式で出力します。
544
+
545
+ ```typescript
546
+ import { PatchGenerator, createPatchGenerator } from '@nahisaho/musubix-security';
547
+
548
+ const generator = createPatchGenerator();
549
+
550
+ // パッチ生成
551
+ const patch = generator.generatePatch(fix, originalContent, {
552
+ format: 'unified', // unified | git | json | context
553
+ contextLines: 3,
554
+ });
555
+
556
+ // パッチの適用
557
+ const applied = generator.applyPatch(patch, targetContent);
558
+
559
+ // リバースパッチ
560
+ const reversePatch = generator.generateReversePatch(patch);
561
+ ```
562
+
563
+ ### 9.4 RemediationPlanner
564
+
565
+ 複数の脆弱性に対する修復計画を策定します。
566
+
567
+ ```typescript
568
+ import { RemediationPlanner, createRemediationPlanner } from '@nahisaho/musubix-security';
569
+
570
+ const planner = createRemediationPlanner();
571
+
572
+ // 修復計画の作成
573
+ const plan = planner.createPlan(vulnerabilities, {
574
+ strategy: 'risk-based', // severity-first | effort-first | risk-based | dependency-aware | balanced
575
+ maxParallelFixes: 3,
576
+ });
577
+
578
+ console.log(plan.phases); // フェーズ分けされた修復順序
579
+ console.log(plan.estimatedEffort); // 推定作業量
580
+ console.log(plan.riskReduction); // リスク削減効果
581
+ ```
582
+
583
+ ### 9.5 SecureCodeTransformer
584
+
585
+ セキュアなコードパターンへの変換を行います。
586
+
587
+ ```typescript
588
+ import { SecureCodeTransformer, createSecureCodeTransformer } from '@nahisaho/musubix-security';
589
+
590
+ const transformer = createSecureCodeTransformer();
591
+
592
+ // 変換の適用
593
+ const result = transformer.transform(code, {
594
+ categories: ['output-encoding', 'cryptography', 'error-handling'],
595
+ });
596
+
597
+ console.log(result.transformed); // 変換後のコード
598
+ console.log(result.changes); // 変更一覧
599
+ console.log(result.riskLevel); // リスクレベル
600
+ ```
601
+
602
+ ---
603
+
604
+ ## 10. セキュリティインテリジェンス(Phase 6)
605
+
606
+ ### 10.1 ThreatIntelligence
607
+
608
+ 外部脅威フィードとの統合とIOCマッチングを提供します。
609
+
610
+ ```typescript
611
+ import { ThreatIntelligence, createThreatIntelligence } from '@nahisaho/musubix-security';
612
+
613
+ const intel = createThreatIntelligence();
614
+
615
+ // フィードの追加
616
+ await intel.addFeed({
617
+ id: 'custom-feed',
618
+ name: 'Custom Threat Feed',
619
+ url: 'https://threat-feed.example.com/iocs',
620
+ type: 'stix',
621
+ refreshInterval: 3600000, // 1時間
622
+ });
623
+
624
+ // コードに対するIOCマッチング
625
+ const matches = intel.matchCode(sourceCode);
626
+
627
+ // IOC検索
628
+ const iocs = intel.searchIOCs({ type: 'ip', severity: 'high' });
629
+ ```
630
+
631
+ ### 10.2 AttackPatternMatcher
632
+
633
+ MITRE ATT&CKフレームワークとの統合を提供します。
634
+
635
+ ```typescript
636
+ import { AttackPatternMatcher, createAttackPatternMatcher } from '@nahisaho/musubix-security';
637
+
638
+ const matcher = createAttackPatternMatcher();
639
+
640
+ // コードに対するパターンマッチング
641
+ const matches = matcher.matchCode(sourceCode);
642
+
643
+ // 特定のテクニックの取得
644
+ const technique = matcher.getTechnique('T1059');
645
+
646
+ // タクティクス別のテクニック一覧
647
+ const techniques = matcher.getTechniquesByTactic('execution');
648
+
649
+ // カスタムパターンの追加
650
+ matcher.addPattern({
651
+ id: 'CUSTOM-001',
652
+ name: 'Custom Attack Pattern',
653
+ technique: 'T1059',
654
+ patterns: [/eval\s*\(/g],
655
+ severity: 'high',
656
+ });
657
+ ```
658
+
659
+ ### 10.3 RiskScorer
660
+
661
+ CVSS計算とビジネスインパクト評価を行います。
662
+
663
+ ```typescript
664
+ import { RiskScorer, createRiskScorer } from '@nahisaho/musubix-security';
665
+
666
+ const scorer = createRiskScorer();
667
+
668
+ // CVSS計算
669
+ const cvss = scorer.calculateCVSS(vulnerability);
670
+ console.log(cvss.baseScore); // 基本スコア
671
+ console.log(cvss.temporalScore); // 時間的スコア
672
+ console.log(cvss.environmentalScore); // 環境的スコア
673
+ console.log(cvss.severity); // 重要度ラベル
674
+
675
+ // ビジネスインパクト評価
676
+ const impact = scorer.assessBusinessImpact(vulnerability, {
677
+ assetCriticality: 'high',
678
+ dataClassification: 'confidential',
679
+ serviceAvailability: 'critical',
680
+ });
681
+
682
+ console.log(impact.score); // インパクトスコア
683
+ console.log(impact.factors); // 評価要素
684
+ console.log(impact.recommendations); // 推奨事項
685
+ ```
686
+
687
+ ### 10.4 SecurityAnalytics
688
+
689
+ セキュリティメトリクスの収集とダッシュボード生成を行います。
690
+
691
+ ```typescript
692
+ import { SecurityAnalytics, createSecurityAnalytics } from '@nahisaho/musubix-security';
693
+
694
+ const analytics = createSecurityAnalytics();
695
+
696
+ // イベントの記録
697
+ analytics.recordVulnerability(vulnerability);
698
+ analytics.recordFix(fix);
699
+ analytics.recordScan(scanResult);
700
+
701
+ // メトリクス計算
702
+ const mttr = analytics.calculateMetric('mean-time-to-remediation');
703
+ const vulnTrend = analytics.calculateMetric('vulnerability-trend');
704
+
705
+ // ダッシュボード生成
706
+ const dashboard = analytics.generateDashboard();
707
+ console.log(dashboard.summary); // サマリー
708
+ console.log(dashboard.kpis); // KPI一覧
709
+ console.log(dashboard.trends); // トレンドデータ
710
+ ```
711
+
712
+ ### 10.5 PredictiveAnalyzer
713
+
714
+ セキュリティトレンドの予測と異常検出を行います。
715
+
716
+ ```typescript
717
+ import { PredictiveAnalyzer, createPredictiveAnalyzer } from '@nahisaho/musubix-security';
718
+
719
+ const analyzer = createPredictiveAnalyzer();
720
+
721
+ // データポイントの追加
722
+ analyzer.addDataPoints([
723
+ { timestamp: new Date('2026-01-01'), value: 10, metric: 'vulnerabilities' },
724
+ { timestamp: new Date('2026-01-02'), value: 12, metric: 'vulnerabilities' },
725
+ // ...
726
+ ]);
727
+
728
+ // リスク予測(30日先)
729
+ const projection = analyzer.projectRisk(30);
730
+ console.log(projection.projectedRisk); // 予測リスク値
731
+ console.log(projection.confidence); // 信頼度
732
+ console.log(projection.trend); // トレンド方向
733
+
734
+ // 異常検出
735
+ const anomalies = analyzer.detectAnomalies();
736
+ console.log(anomalies); // 検出された異常一覧
737
+
738
+ // アラート取得
739
+ const alerts = analyzer.getAlerts();
740
+ ```
741
+
742
+ ---
743
+
744
+ ## 11. CLI使用方法
745
+
746
+ ### 11.1 基本コマンド
747
+
748
+ ```bash
749
+ # フルスキャン
750
+ npx musubix-security scan ./src
751
+
752
+ # 脆弱性スキャンのみ
753
+ npx musubix-security scan ./src --vulnerabilities-only
754
+
755
+ # シークレット検出のみ
756
+ npx musubix-security secrets ./src
757
+
758
+ # テイント解析のみ
759
+ npx musubix-security taint ./src
760
+
761
+ # 依存関係監査
762
+ npx musubix-security audit ./project
763
+ ```
764
+
765
+ ### 11.2 オプション
766
+
767
+ ```bash
768
+ # 重要度フィルタ
769
+ npx musubix-security scan ./src --severity critical,high
770
+
771
+ # 出力フォーマット
772
+ npx musubix-security scan ./src --format sarif --output report.sarif
773
+
774
+ # 修正生成
775
+ npx musubix-security scan ./src --generate-fixes
776
+
777
+ # 詳細出力
778
+ npx musubix-security scan ./src --verbose
779
+ ```
780
+
781
+ ---
782
+
783
+ ## 12. MCP統合
784
+
785
+ ### 12.1 MCPツール
786
+
787
+ MCP(Model Context Protocol)サーバーとして以下のツールを提供。
788
+
789
+ | ツール名 | 説明 |
790
+ |---------|------|
791
+ | `security_scan` | 包括的セキュリティスキャン |
792
+ | `security_scan_file` | 単一ファイルスキャン |
793
+ | `security_detect_secrets` | シークレット検出 |
794
+ | `security_analyze_taint` | テイント解析 |
795
+ | `security_audit_deps` | 依存関係監査 |
796
+ | `security_generate_fix` | 修正コード生成 |
797
+ | `security_generate_report` | レポート生成 |
798
+
799
+ ### 12.2 MCPサーバー起動
800
+
801
+ ```bash
802
+ npx musubix-security-mcp
803
+ ```
804
+
805
+ ---
806
+
807
+ ## 13. 設定
808
+
809
+ ### 13.1 設定ファイル
810
+
811
+ プロジェクトルートに `.musubix-securityrc.json` を配置:
812
+
813
+ ```json
814
+ {
815
+ "version": "1.0",
816
+ "scan": {
817
+ "severityFilter": ["critical", "high", "medium"],
818
+ "rulesets": ["owasp-top-10", "cwe-top-25"]
819
+ },
820
+ "taint": {
821
+ "interprocedural": true,
822
+ "trackAsync": true,
823
+ "maxPathDepth": 10
824
+ },
825
+ "secret": {
826
+ "ignoreTestValues": true
827
+ },
828
+ "report": {
829
+ "format": "sarif",
830
+ "includeCodeSnippets": true,
831
+ "includeFixes": true
832
+ }
833
+ }
834
+ ```
835
+
836
+ ### 13.2 DEFAULT_CONFIG
837
+
838
+ ```typescript
839
+ import { DEFAULT_CONFIG } from '@nahisaho/musubix-security';
840
+
841
+ // デフォルト設定を確認
842
+ console.log(DEFAULT_CONFIG.scan.severityFilter);
843
+ // ['critical', 'high', 'medium']
844
+ ```
845
+
846
+ ---
847
+
848
+ ## 14. テスト統計
849
+
850
+ | フェーズ | テストファイル数 | テスト数 | 状態 |
851
+ |---------|-----------------|---------|------|
852
+ | Core | 7 | 125 | ✅ 合格 |
853
+ | Phase 2 (Advanced Detection) | 5 | 91 | ✅ 合格 |
854
+ | Phase 3 (Enterprise) | 5 | 120 | ✅ 合格 |
855
+ | Phase 4 (Integration) | 5 | 141 | ✅ 合格 |
856
+ | Phase 5 (Auto-Fix) | 5 | 176 | ✅ 合格 |
857
+ | Phase 6 (Intelligence) | 5 | 70 | ✅ 合格 |
858
+ | **合計** | **32** | **723** | **✅ 全合格** |
859
+
860
+ ※ 2件のスキップテストあり(Container/Image Scanner の外部依存)
861
+
862
+ ---
863
+
864
+ ## 15. 依存関係
865
+
866
+ | パッケージ | バージョン | 用途 |
867
+ |-----------|-----------|------|
868
+ | `ts-morph` | ^24.0.0 | TypeScript AST解析 |
869
+ | `minimatch` | ^10.0.1 | ファイルパターンマッチング |
870
+ | `cosmiconfig` | ^9.0.0 | 設定ファイル読み込み |
871
+ | `yaml` | ^2.7.1 | YAML設定サポート |
872
+ | `zod` | ^3.24.1 | スキーマバリデーション |
873
+ | `commander` | ^13.1.0 | CLI構築 |
874
+ | `@modelcontextprotocol/sdk` | ^1.11.0 | MCP統合 |
875
+
876
+ ---
877
+
878
+ ## 16. 関連ドキュメント
879
+
880
+ - [MUSUBIX Overview](./MUSUBIX-Overview.md) - システム全体概要
881
+ - [MUSUBIX Core](./MUSUBIX-Core.md) - コアライブラリ
882
+ - [MUSUBIX Formal Verify](./MUSUBIX-FormalVerify.md) - 形式検証
883
+ - [API Reference](../API-REFERENCE.md) - 詳細APIリファレンス
884
+
885
+ ---
886
+
887
+ ## 17. ライセンス
888
+
889
+ MIT License
890
+
891
+ Copyright (c) 2026 nahisaho