musubix 3.3.8 → 3.3.10

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 (92) hide show
  1. package/README.md +50 -305
  2. package/bin/musubix.js +1 -9
  3. package/dist/index.d.ts +25 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +74 -0
  6. package/dist/index.js.map +1 -0
  7. package/package.json +49 -55
  8. package/.github/AGENTS.md +0 -949
  9. package/.github/prompts/sdd-change-apply.prompt.md +0 -283
  10. package/.github/prompts/sdd-change-archive.prompt.md +0 -241
  11. package/.github/prompts/sdd-change-init.prompt.md +0 -269
  12. package/.github/prompts/sdd-design.prompt.md +0 -250
  13. package/.github/prompts/sdd-implement.prompt.md +0 -387
  14. package/.github/prompts/sdd-requirements.prompt.md +0 -193
  15. package/.github/prompts/sdd-review.prompt.md +0 -155
  16. package/.github/prompts/sdd-security.prompt.md +0 -228
  17. package/.github/prompts/sdd-steering.prompt.md +0 -269
  18. package/.github/prompts/sdd-tasks.prompt.md +0 -255
  19. package/.github/prompts/sdd-test.prompt.md +0 -230
  20. package/.github/prompts/sdd-validate.prompt.md +0 -304
  21. package/.github/skills/musubix-adr-generation/SKILL.md +0 -209
  22. package/.github/skills/musubix-best-practices/SKILL.md +0 -315
  23. package/.github/skills/musubix-c4-design/SKILL.md +0 -162
  24. package/.github/skills/musubix-code-generation/SKILL.md +0 -237
  25. package/.github/skills/musubix-domain-inference/SKILL.md +0 -196
  26. package/.github/skills/musubix-ears-validation/SKILL.md +0 -161
  27. package/.github/skills/musubix-sdd-workflow/SKILL.md +0 -217
  28. package/.github/skills/musubix-technical-writing/SKILL.md +0 -444
  29. package/.github/skills/musubix-test-generation/SKILL.md +0 -212
  30. package/.github/skills/musubix-traceability/SKILL.md +0 -141
  31. package/AGENTS.md +0 -1065
  32. package/LICENSE +0 -21
  33. package/README.ja.md +0 -296
  34. package/bin/musubix-mcp.js +0 -15
  35. package/docs/API-REFERENCE.md +0 -1425
  36. package/docs/GITHUB-ACTIONS-NPM-SETUP.md +0 -132
  37. package/docs/INSTALL-GUIDE.ja.md +0 -459
  38. package/docs/INSTALL-GUIDE.md +0 -459
  39. package/docs/MIGRATION-v3.0.md +0 -324
  40. package/docs/MUSUBI-enhancement_roadmap_20260105.md +0 -651
  41. package/docs/MUSUBIX-v3.0-User-Guide.md +0 -1357
  42. package/docs/MUSUBIXv2.2.0-Manual-outline.md +0 -136
  43. package/docs/MUSUBIXv2.2.0-Manual.md +0 -3123
  44. package/docs/MUSUBIXv2.3.5-Refactering.md +0 -1310
  45. package/docs/MUSUBIv1.6.1-enhancement_roadmap_20260105.md +0 -291
  46. package/docs/MUSUBIv2.2.0-USERGUIDE.md +0 -2079
  47. package/docs/ROADMAP-v1.5.md +0 -116
  48. package/docs/SwarmCoding.md +0 -1284
  49. package/docs/Test-prompt.md +0 -105
  50. package/docs/USER-GUIDE-v1.8.0.md +0 -2371
  51. package/docs/USER-GUIDE.ja.md +0 -2147
  52. package/docs/USER-GUIDE.md +0 -3022
  53. package/docs/YATA-GLOBAL-GUIDE.ja.md +0 -750
  54. package/docs/YATA-GLOBAL-GUIDE.md +0 -595
  55. package/docs/YATA-LOCAL-GUIDE.ja.md +0 -989
  56. package/docs/YATA-LOCAL-GUIDE.md +0 -730
  57. package/docs/adr/0001-real-time-pattern-learning-architecture-for-v1-5-0.md +0 -75
  58. package/docs/adr/0002-pattern-sharing-protocol-for-cross-team-collaborat.md +0 -79
  59. package/docs/adr/0003-owl-2-rl-implementation-strategy-for-advanced-infe.md +0 -90
  60. package/docs/enterprise-knowledge-management.md +0 -1737
  61. package/docs/evolution-from-musubi-to-musubix.md +0 -2170
  62. package/docs/getting-started-with-sdd.md +0 -1602
  63. package/docs/moodle-refactering-codegraph-musubix.md +0 -391
  64. package/docs/moodle-refactering-codegraph.md +0 -278
  65. package/docs/overview/MUSUBIX-CodeGraph.md +0 -322
  66. package/docs/overview/MUSUBIX-Core.md +0 -671
  67. package/docs/overview/MUSUBIX-Decisions.md +0 -494
  68. package/docs/overview/MUSUBIX-FormalVerify.md +0 -566
  69. package/docs/overview/MUSUBIX-Knowledge.md +0 -1231
  70. package/docs/overview/MUSUBIX-Learning.md +0 -837
  71. package/docs/overview/MUSUBIX-MCP-Server.md +0 -535
  72. package/docs/overview/MUSUBIX-Overview.md +0 -264
  73. package/docs/overview/MUSUBIX-Phase1-Complete.md +0 -271
  74. package/docs/overview/MUSUBIX-Phase2-Complete.md +0 -310
  75. package/docs/overview/MUSUBIX-Policy.md +0 -477
  76. package/docs/overview/MUSUBIX-Roadmap-v2.md +0 -399
  77. package/docs/overview/MUSUBIX-Security-Plan.md +0 -939
  78. package/docs/overview/MUSUBIX-Security-v2.1.md +0 -668
  79. package/docs/overview/MUSUBIX-Security.md +0 -891
  80. package/docs/overview/MUSUBIX-YATA.md +0 -666
  81. package/docs/overview/MUSUBIX-v2.2.0-Advanced-Learning.md +0 -513
  82. package/docs/overview/Neuro-SymbolicAI.md +0 -159
  83. package/docs/packages/knowledge.md +0 -594
  84. package/docs/qiita-linux-kernel-knowledge-graph.md +0 -596
  85. package/scripts/generate-quality-gate-report.ts +0 -106
  86. package/scripts/postinstall.js +0 -94
  87. package/steering/.musubi-version +0 -1
  88. package/steering/product.ja.md +0 -572
  89. package/steering/project.yml +0 -66
  90. package/steering/rules/constitution.md +0 -491
  91. package/steering/structure.ja.md +0 -503
  92. package/steering/tech.ja.md +0 -208
@@ -1,391 +0,0 @@
1
- ---
2
- title: MUSUBIX CodeGraph による脆弱性自動検出・修正・検証の実験レポート 2
3
- tags: MUSUBIX CodeGraph セキュリティ監査 PHP 脆弱性検出
4
- private: false
5
- updated_at: '2025-01-10'
6
- id: null
7
- organization_url_name: null
8
- slide: false
9
- ignorePublish: false
10
- ---
11
-
12
- > **関連記事**:
13
- > - [MUSUBIX v2.3.5 リリース:CodeGraph によるリファクタリング手法](https://qiita.com/hisaho/items/5c7ef8b329ed244a4584)
14
- > - [MUSUBIX CodeGraph による脆弱性自動検出・修正・検証の実験レポート](https://qiita.com/hisaho/items/20beb1d125e7c5919e9a)
15
-
16
- # 概要
17
-
18
- 本実験では、**MUSUBIX の2つのセキュリティ機能**を組み合わせて、Moodle LMS の包括的なセキュリティ監査を実施しました。
19
-
20
- ## 使用ツール
21
-
22
- | ツール | 機能 | コマンド |
23
- |--------|------|---------|
24
- | **CodeGraph** | 構造解析・パターン検索 | `npx musubix cg index/search` |
25
- | **Security Scanner** | 脆弱性スキャン・CWE分類 | `npx musubix codegen security` |
26
-
27
- ## 監査ワークフロー
28
-
29
- ```mermaid
30
- flowchart TB
31
- subgraph Phase1["Phase 1: CodeGraph 構造解析"]
32
- A["プロジェクト<br/>インデックス化"] --> B["エンティティ<br/>抽出"]
33
- B --> C["関係性<br/>マッピング"]
34
- end
35
-
36
- subgraph Phase2["Phase 2: Security Scanner"]
37
- D["パターン<br/>マッチング"] --> E["脆弱性<br/>分類"]
38
- E --> F["CWE<br/>マッピング"]
39
- end
40
-
41
- subgraph Phase3["Phase 3: 統合分析"]
42
- G["結果<br/>統合"] --> H["優先度<br/>評価"]
43
- H --> I["修正<br/>推奨"]
44
- end
45
-
46
- Phase1 --> Phase2
47
- Phase2 --> Phase3
48
-
49
- style Phase1 fill:#e3f2fd
50
- style Phase2 fill:#fff3e0
51
- style Phase3 fill:#e8f5e9
52
- ```
53
-
54
- ---
55
-
56
- # 実験環境
57
-
58
- | 項目 | 内容 |
59
- |------|------|
60
- | 対象プロジェクト | Moodle LMS |
61
- | ファイル数 | 51,830 |
62
- | MUSUBIX バージョン | v2.3.5 |
63
- | スキャン対象 | PHP, JavaScript |
64
-
65
- ---
66
-
67
- # Phase 1: CodeGraph による構造解析
68
-
69
- ## インデックス作成
70
-
71
- ```bash
72
- $ npx musubix cg index /tmp/moodle/public
73
-
74
- {
75
- success: true,
76
- message: 'Indexing complete',
77
- stats: { totalEntities: 59046, totalRelations: 11114, files: 51830 }
78
- }
79
- ```
80
-
81
- ## 構造統計
82
-
83
- | 項目 | 数値 |
84
- |------|------|
85
- | 総エンティティ | 59,046 |
86
- | 総リレーション | 11,114 |
87
- | ファイル数 | 51,830 |
88
-
89
- ---
90
-
91
- # Phase 2: Security Scanner による脆弱性検出
92
-
93
- ## スキャン実行
94
-
95
- ```bash
96
- $ npx musubix codegen security /tmp/moodle/public --severity high
97
- ```
98
-
99
- ## 検出結果サマリー
100
-
101
- ### 重大度別集計
102
-
103
- | 重大度 | 件数 |
104
- |--------|------|
105
- | **High** | 100 |
106
- | **Medium** | 100+ |
107
- | **Low** | 多数 |
108
-
109
- ### 脆弱性タイプ別集計(High)
110
-
111
- | タイプ | 件数 | CWE |
112
- |--------|------|-----|
113
- | **XSS (Cross-Site Scripting)** | 85 | CWE-79 |
114
- | **Command Injection** | 15 | CWE-78 |
115
-
116
- ### 脆弱性タイプ別集計(Medium)
117
-
118
- | タイプ | 件数 | CWE |
119
- |--------|------|-----|
120
- | **Insecure Communication** | 83 | CWE-319 |
121
- | **Command Injection** | 9 | CWE-78 |
122
- | **XSS** | 8 | CWE-79 |
123
-
124
- ---
125
-
126
- # Phase 3: 詳細分析
127
-
128
- ## 3.1 XSS 脆弱性 (CWE-79)
129
-
130
- ### 検出パターン
131
-
132
- ```javascript
133
- // 危険: innerHTML への直接代入
134
- element.innerHTML = userInput;
135
- ```
136
-
137
- ### 検出箇所(代表例)
138
-
139
- | ファイル | 行 | 説明 |
140
- |----------|------|------|
141
- | `admin/tool/analytics/amd/src/log_info.js` | 42 | innerHTML 直接代入 |
142
- | `admin/tool/componentlibrary/amd/src/jsrunner.js` | 39 | innerHTML 直接代入 |
143
- | `admin/tool/componentlibrary/amd/src/mustache.js` | 92 | innerHTML 直接代入 |
144
- | `admin/tool/componentlibrary/amd/src/search.js` | 138 | innerHTML 直接代入 |
145
- | `lib/amd/src/datafilter.js` | 134, 312 | innerHTML 代入 |
146
- | `lib/amd/src/dropzone.js` | 187 | innerHTML テンプレート |
147
- | `lib/amd/src/togglesensitive.js` | 155 | innerHTML アイコン |
148
-
149
- ### 推奨修正
150
-
151
- ```javascript
152
- // ❌ 危険
153
- element.innerHTML = userInput;
154
-
155
- // ✅ 安全(テキストの場合)
156
- element.textContent = userInput;
157
-
158
- // ✅ 安全(HTML が必要な場合)
159
- element.innerHTML = DOMPurify.sanitize(userInput);
160
- ```
161
-
162
- ---
163
-
164
- ## 3.2 Command Injection 脆弱性 (CWE-78)
165
-
166
- ### 検出パターン
167
-
168
- ```php
169
- // 危険: シェルコマンド実行
170
- exec($command);
171
- shell_exec($command);
172
- system($command);
173
- passthru($command);
174
- ```
175
-
176
- ### 検出箇所(代表例)
177
-
178
- | ファイル | 行 | 関数 |
179
- |----------|------|------|
180
- | `admin/tool/behat/cli/init.php` | 168 | `exec()` |
181
- | `admin/tool/messageinbound/roundcube/rcube_utils.php` | 1464, 1472, 1481 | `shell_exec()` |
182
- | `admin/tool/phpunit/cli/init.php` | 98, 105 | `exec()` |
183
- | `mod/assign/feedback/editpdf/classes/pdf.php` | 551, 596, 741 | `exec()` |
184
- | `filter/tex/texdebug.php` | 288 | `exec()` |
185
- | `filter/tex/latex.php` | 68 | `exec()` |
186
- | `files/converter/unoconv/classes/converter.php` | 151, 285 | `exec()` |
187
- | `files/classes/redactor/services/exifremover_service.php` | 150 | `exec()` |
188
-
189
- ### 統計
190
-
191
- ```bash
192
- $ grep -rn "shell_exec\|passthru\|system(" --include="*.php" | wc -l
193
- 146
194
- ```
195
-
196
- ### 推奨修正
197
-
198
- ```php
199
- // ❌ 危険
200
- exec($userInput);
201
-
202
- // ✅ 安全
203
- exec(escapeshellcmd($command));
204
- // または
205
- $process = new Symfony\Component\Process\Process([$binary, $arg1, $arg2]);
206
- $process->run();
207
- ```
208
-
209
- ---
210
-
211
- ## 3.3 Insecure Communication (CWE-319)
212
-
213
- ### 検出パターン
214
-
215
- ```javascript
216
- // 危険: HTTP の使用
217
- fetch('http://example.com/api');
218
- ```
219
-
220
- ### 検出件数
221
-
222
- | タイプ | 件数 |
223
- |--------|------|
224
- | HTTP URL in JS | 83+ |
225
-
226
- ### 推奨修正
227
-
228
- ```javascript
229
- // ❌ 危険
230
- const url = 'http://api.example.com';
231
-
232
- // ✅ 安全
233
- const url = 'https://api.example.com';
234
- ```
235
-
236
- ---
237
-
238
- ## 3.4 eval() 使用 (CWE-95)
239
-
240
- ### 検出箇所
241
-
242
- | ファイル | 行 | 用途 |
243
- |----------|------|------|
244
- | `webservice/lib.php` | 1594, 1631 | 動的コード生成 |
245
- | `question/type/calculated/question.php` | 455, 456 | 数式評価 |
246
- | `question/type/calculated/questiontype.php` | 1107, 1244 | 数式評価 |
247
-
248
- ### リスク評価
249
-
250
- - **webservice/lib.php**: 動的クラス生成に使用。入力検証が必要。
251
- - **calculated question**: 数学的な式評価。ホワイトリスト検証が実装済み。
252
-
253
- ---
254
-
255
- ## 3.5 ユーザー入力の直接使用
256
-
257
- ### 検出パターン
258
-
259
- ```php
260
- // install.php での直接使用
261
- $lang = preg_replace('/[^A-Za-z0-9_-]/i', '', $_REQUEST['lang']);
262
- $config->dbtype = trim($_POST['dbtype']);
263
- ```
264
-
265
- ### 評価
266
-
267
- `install.php` ではインストール時のみ使用され、`preg_replace` でサニタイズされているため、リスクは限定的。ただし、本番環境では `install.php` を削除すべき。
268
-
269
- ---
270
-
271
- # 統合分析結果
272
-
273
- ## 脆弱性サマリー
274
-
275
- | カテゴリ | High | Medium | 対応優先度 |
276
- |----------|------|--------|-----------|
277
- | XSS (innerHTML) | 85 | 8 | 🔴 高 |
278
- | Command Injection | 15 | 9 | 🔴 高 |
279
- | Insecure Communication | 0 | 83 | 🟡 中 |
280
- | eval() 使用 | - | - | 🟡 要検証 |
281
- | Object Injection | 0 | 0 | ✅ 修正済み |
282
-
283
- ## 修正済み脆弱性
284
-
285
- 前回の実験で修正した `unserialize()` 脆弱性(6件)は、今回のスキャンで検出されませんでした。
286
-
287
- | 脆弱性 | 修正前 | 修正後 |
288
- |--------|--------|--------|
289
- | PHP Object Injection | 6件 | **0件** ✅ |
290
-
291
- ---
292
-
293
- # 推奨アクション
294
-
295
- ## 即時対応(High Priority)
296
-
297
- 1. **XSS 脆弱性の修正**
298
- - `innerHTML` → `textContent` への置換
299
- - または DOMPurify によるサニタイズ
300
-
301
- 2. **Command Injection の検証**
302
- - `exec()`/`shell_exec()` の入力検証確認
303
- - `escapeshellarg()` / `escapeshellcmd()` の使用
304
-
305
- ## 中期対応(Medium Priority)
306
-
307
- 3. **HTTPS への移行**
308
- - すべての HTTP URL を HTTPS に変更
309
- - Mixed Content の解消
310
-
311
- 4. **eval() の代替実装検討**
312
- - 数式評価には専用ライブラリを検討
313
-
314
- ## 継続的対応
315
-
316
- 5. **CI/CD へのセキュリティスキャン統合**
317
- - `npx musubix codegen security` を CI に組み込み
318
- - プルリクエスト時の自動スキャン
319
-
320
- ---
321
-
322
- # ツール比較
323
-
324
- | 機能 | CodeGraph | Security Scanner |
325
- |------|-----------|------------------|
326
- | 構造解析 | ✅ | - |
327
- | パターン検索 | ✅ | ✅ |
328
- | CWE 分類 | - | ✅ |
329
- | 修正推奨 | - | ✅ |
330
- | GraphRAG | ✅ | - |
331
- | 依存関係追跡 | ✅ | - |
332
-
333
- ## 統合活用のメリット
334
-
335
- CodeGraph と Security Scanner を組み合わせることで、単独のツールでは実現できない**深いセキュリティ分析**が可能になります。CodeGraph はコードベース全体の構造を理解し、関数間の呼び出し関係やデータの流れを可視化します。一方、Security Scanner は既知の脆弱性パターンを高速に検出し、CWE 分類に基づいた優先度付けを行います。
336
-
337
- この2つを統合することで、脆弱性が**どこから呼び出され、どこに影響を与えるか**を正確に把握でき、修正時の副作用リスクを最小限に抑えられます。
338
-
339
- ```mermaid
340
- flowchart LR
341
- A["CodeGraph<br/>構造理解"] --> C["統合分析"]
342
- B["Security Scanner<br/>脆弱性検出"] --> C
343
- C --> D["精度の高い<br/>セキュリティ評価"]
344
- C --> E["修正範囲の<br/>影響分析"]
345
-
346
- style C fill:#e8f5e9
347
- ```
348
-
349
- 1. **CodeGraph**: コードの構造と依存関係を理解
350
- 2. **Security Scanner**: 脆弱性パターンを検出・分類
351
- 3. **統合**: 脆弱性の影響範囲を正確に把握
352
-
353
- ---
354
-
355
- # まとめ
356
-
357
- 本実験では、MUSUBIX の **CodeGraph** と **Security Scanner** を組み合わせた統合セキュリティ監査の有効性を実証しました。5万ファイル以上の大規模 PHP/JavaScript プロジェクトに対して、わずか数分で構造解析と脆弱性検出を完了し、CWE 分類に基づいた優先度付きの修正ガイダンスを自動生成できました。
358
-
359
- 特に、前回修正した PHP Object Injection 脆弱性(6件)が今回のスキャンで検出されなかったことは、**修正の効果を客観的に検証できる**という点で重要な成果です。
360
-
361
- ## 実験結果
362
-
363
- | 項目 | 結果 |
364
- |------|------|
365
- | スキャンファイル数 | 51,830 |
366
- | 検出脆弱性(High) | 100 |
367
- | 検出脆弱性(Medium) | 100+ |
368
- | 主要脆弱性タイプ | XSS, Command Injection |
369
- | 修正済み脆弱性 | Object Injection (6件) |
370
-
371
- ## CodeGraph + Security Scanner の有効性
372
-
373
- - **広範なカバレッジ**: 5万以上のファイルを効率的にスキャン
374
- - **CWE マッピング**: 業界標準の脆弱性分類
375
- - **優先度付け**: 重大度による効率的なトリアージ
376
- - **修正ガイダンス**: 各脆弱性に対する推奨修正
377
-
378
- ---
379
-
380
- # 参考資料
381
-
382
- - [CWE-79: Cross-site Scripting (XSS)](https://cwe.mitre.org/data/definitions/79.html)
383
- - [CWE-78: OS Command Injection](https://cwe.mitre.org/data/definitions/78.html)
384
- - [CWE-319: Cleartext Transmission](https://cwe.mitre.org/data/definitions/319.html)
385
- - [OWASP Top 10](https://owasp.org/www-project-top-ten/)
386
-
387
- ---
388
-
389
- **作成日**: 2025-01-10
390
- **作成者**: MUSUBIX CodeGraph v2.3.5 + Security Scanner
391
- **ライセンス**: MIT
@@ -1,278 +0,0 @@
1
- ---
2
- title: MUSUBIX CodeGraph による脆弱性自動検出・修正・検証の実験レポート
3
- tags: MUSUBIX CodeGraph セキュリティ PHP Playwright
4
- private: false
5
- updated_at: '2025-01-10'
6
- id: null
7
- organization_url_name: null
8
- slide: false
9
- ignorePublish: false
10
- ---
11
-
12
- > **本記事の位置づけ**: この記事は [MUSUBIX v2.3.5 リリース:CodeGraph によるリファクタリング手法](https://qiita.com/hisaho/items/5c7ef8b329ed244a4584) の続編です。CodeGraph の基本概念、対応言語、CLI コマンドについては、そちらを参照してください。
13
-
14
- # 実験概要
15
-
16
- 本実験では、**MUSUBIX CodeGraph を活用したセキュリティ脆弱性のエンドツーエンド自動修正ワークフロー**を検証しました。
17
-
18
- ## 実験シナリオ
19
-
20
- ```mermaid
21
- flowchart LR
22
- A["🔍 CodeGraph<br/>脆弱性スキャン"] --> B["⚠️ 脆弱性<br/>6件検出"]
23
- B --> C["🔧 MUSUBIX<br/>自動修正"]
24
- C --> D["🧪 Playwright<br/>E2Eテスト"]
25
- D --> E["🔄 CodeGraph<br/>再インデックス"]
26
- E --> F["✅ 脆弱性<br/>0件確認"]
27
-
28
- style A fill:#e3f2fd
29
- style B fill:#ffebee
30
- style C fill:#fff3e0
31
- style D fill:#e8f5e9
32
- style E fill:#e3f2fd
33
- style F fill:#c8e6c9
34
- ```
35
-
36
- | フェーズ | 内容 | 結果 |
37
- |---------|------|------|
38
- | **Phase 1** | CodeGraph で Moodle をスキャン | 82,550 エンティティ、6件の脆弱性検出 |
39
- | **Phase 2** | MUSUBIX で自動修正 | 3ファイル、6箇所を修正 |
40
- | **Phase 3** | Playwright でテスト | 8テスト全合格 |
41
- | **Phase 4** | CodeGraph で再インデックス | 59,046 エンティティ |
42
- | **Phase 5** | 脆弱性再チェック | **0件** ✅ |
43
-
44
- ## 実験の意義
45
-
46
- この実験により、以下のワークフローが実現可能であることを実証しました:
47
-
48
- 1. **検出**: CodeGraph のパターン検索で危険なコードを自動検出
49
- 2. **修正**: 検出結果に基づき、セキュリティベストプラクティスに従った修正を適用
50
- 3. **検証**: Playwright E2E テストで修正の正確性を確認
51
- 4. **確認**: 再インデックス・再スキャンで脆弱性が完全に解消されたことを検証
52
-
53
- **このサイクルを CI/CD に組み込むことで、継続的なセキュリティ品質の維持が可能になります。**
54
-
55
- ---
56
-
57
- # 実験環境
58
-
59
- | 項目 | 内容 |
60
- |------|------|
61
- | 対象プロジェクト | Moodle LMS |
62
- | PHP ファイル数 | 49,816 |
63
- | MUSUBIX バージョン | v2.3.5 |
64
- | テストフレームワーク | Playwright |
65
- | 脆弱性タイプ | PHP Object Injection (unserialize) |
66
-
67
- ---
68
-
69
- # Phase 1: CodeGraph による脆弱性スキャン
70
-
71
- ## インデックス作成
72
-
73
- ```bash
74
- $ npx musubix cg index /tmp/moodle/public
75
-
76
- {
77
- success: true,
78
- message: 'Indexing complete',
79
- stats: { totalEntities: 82550, totalRelations: 15234, files: 49816 }
80
- }
81
- ```
82
-
83
- ## 危険パターンの検索
84
-
85
- ```bash
86
- # unserialize パターンを検索
87
- $ npx musubix cg search "unserialize"
88
- ```
89
-
90
- ## 検出された脆弱性
91
-
92
- | ID | ファイル | 行 | 脆弱なコード | 重大度 |
93
- |----|----------|------|--------------|--------|
94
- | VUL-001 | `repository/coursefiles/lib.php` | 154 | `unserialize(base64_decode($encoded))` | High |
95
- | VUL-002 | `repository/lib.php` | 2514 | `@unserialize($file->get_source())` | High |
96
- | VUL-002 | `repository/lib.php` | 2529 | `@unserialize($newfile->get_source())` | High |
97
- | VUL-002 | `repository/lib.php` | 2580 | `@unserialize($file->get_source())` | High |
98
- | VUL-002 | `repository/lib.php` | 2626 | `@unserialize($f->get_source())` | High |
99
- | VUL-003 | `admin/tool/xmldb/index.php` | 44 | `unserialize($SESSION->xmldb)` | Medium |
100
-
101
- **問題点**: `allowed_classes` パラメータなしの `unserialize()` は **PHP Object Injection** 脆弱性を引き起こす可能性があります。
102
-
103
- ---
104
-
105
- # Phase 2: MUSUBIX による自動修正
106
-
107
- ## 修正戦略
108
-
109
- PHP 7.0+ の `allowed_classes` オプションを使用:
110
-
111
- | 修正パターン | 用途 |
112
- |-------------|------|
113
- | `["allowed_classes" => false]` | 外部データ(すべてのクラスをブロック) |
114
- | `["allowed_classes" => [stdClass::class]]` | メタデータ(必要最小限のクラスのみ) |
115
- | `["allowed_classes" => true]` | 信頼できるセッションデータ |
116
-
117
- ## 適用した修正
118
-
119
- **VUL-001: coursefiles/lib.php (行 154)**
120
- ```diff
121
- - return unserialize(base64_decode($encoded));
122
- + return unserialize(base64_decode($encoded), ["allowed_classes" => false]);
123
- ```
124
-
125
- **VUL-002: repository/lib.php (4箇所)**
126
- ```diff
127
- - $source = @unserialize($file->get_source());
128
- + $source = @unserialize($file->get_source(), ["allowed_classes" => [stdClass::class]]);
129
- ```
130
-
131
- **VUL-003: xmldb/index.php (行 44)**
132
- ```diff
133
- - $XMLDB = unserialize($SESSION->xmldb);
134
- + $XMLDB = unserialize($SESSION->xmldb, ["allowed_classes" => true]);
135
- ```
136
-
137
- ## バックアップ作成
138
-
139
- ```bash
140
- cp public/repository/coursefiles/lib.php public/repository/coursefiles/lib.php.bak
141
- cp public/repository/lib.php public/repository/lib.php.bak
142
- cp public/admin/tool/xmldb/index.php public/admin/tool/xmldb/index.php.bak
143
- ```
144
-
145
- ---
146
-
147
- # Phase 3: Playwright による検証
148
-
149
- ## テスト実行結果
150
-
151
- ```bash
152
- $ npx playwright test
153
-
154
- Running 8 tests using 1 worker
155
-
156
- ✓ VUL-001: coursefiles/lib.php should use allowed_classes parameter (10ms)
157
- ✓ VUL-002: repository/lib.php should use allowed_classes for file sources (3ms)
158
- ✓ VUL-003: xmldb/index.php should use allowed_classes for session data (2ms)
159
- ✓ Modified files should have valid PHP syntax (9ms)
160
- ✓ Backup files should exist for all modified files (2ms)
161
- ✓ Backup files should contain original unsafe code (2ms)
162
- ✓ Modified files have proper allowed_classes protection (1ms)
163
- ✓ Summary of security fixes applied (1ms)
164
-
165
- 📊 Security Fix Summary:
166
- ========================
167
- ✅ VUL-001: coursefiles/lib.php - unserialize(base64_decode) protected
168
- ✅ VUL-002: repository/lib.php - 4 unserialize calls protected
169
- ✅ VUL-003: xmldb/index.php - session unserialize protected
170
-
171
- Total files modified: 3
172
- Total vulnerabilities fixed: 6
173
-
174
- 8 passed (588ms)
175
- ```
176
-
177
- ---
178
-
179
- # Phase 4: CodeGraph 再インデックス
180
-
181
- 修正後にプロジェクトを再インデックス化:
182
-
183
- ```bash
184
- $ npx musubix cg index /tmp/moodle/public
185
-
186
- {
187
- success: true,
188
- message: 'Indexing complete',
189
- stats: { totalEntities: 59046, totalRelations: 11114, files: 51830 }
190
- }
191
- ```
192
-
193
- ---
194
-
195
- # Phase 5: 脆弱性再チェック
196
-
197
- ## grep による確認
198
-
199
- ```bash
200
- $ grep -rn "unserialize" /tmp/moodle/public/repository/coursefiles/lib.php \
201
- /tmp/moodle/public/repository/lib.php \
202
- /tmp/moodle/public/admin/tool/xmldb/index.php
203
- ```
204
-
205
- ## 修正確認結果
206
-
207
- | ファイル | 行 | 修正後コード | 状態 |
208
- |----------|------|--------------|------|
209
- | `coursefiles/lib.php` | 154 | `unserialize(..., ["allowed_classes" => false])` | ✅ |
210
- | `repository/lib.php` | 2514 | `@unserialize(..., ["allowed_classes" => [stdClass::class]])` | ✅ |
211
- | `repository/lib.php` | 2529 | `@unserialize(..., ["allowed_classes" => [stdClass::class]])` | ✅ |
212
- | `repository/lib.php` | 2580 | `@unserialize(..., ["allowed_classes" => [stdClass::class]])` | ✅ |
213
- | `repository/lib.php` | 2626 | `@unserialize(..., ["allowed_classes" => [stdClass::class]])` | ✅ |
214
- | `xmldb/index.php` | 44 | `unserialize(..., ["allowed_classes" => true])` | ✅ |
215
-
216
- ## 最終チェックサマリー
217
-
218
- | チェック項目 | 結果 |
219
- |--------------|------|
220
- | `allowed_classes` 付き unserialize | **6件** ✅ |
221
- | `allowed_classes` なし unserialize(危険) | **0件** ✅ |
222
- | Playwright テスト | **8/8 合格** ✅ |
223
-
224
- **すべての脆弱性が修正され、危険なパターンは検出されませんでした。** 🎉
225
-
226
- ---
227
-
228
- # 実験結果まとめ
229
-
230
- ## 数値サマリー
231
-
232
- | 項目 | Phase 1 | Phase 5 |
233
- |------|---------|---------|
234
- | エンティティ数 | 82,550 | 59,046 |
235
- | 検出脆弱性 | 6 | 0 |
236
- | 危険パターン | 6 | 0 |
237
-
238
- ## 完全自動化ワークフロー
239
-
240
- ```mermaid
241
- flowchart TB
242
- subgraph CI["CI/CD Pipeline"]
243
- A["git push"] --> B["CodeGraph Index"]
244
- B --> C{"脆弱性検出?"}
245
- C -->|Yes| D["自動修正提案"]
246
- C -->|No| E["✅ Pass"]
247
- D --> F["PR 作成"]
248
- F --> G["Playwright Test"]
249
- G --> H["レビュー"]
250
- H --> I["マージ"]
251
- I --> B
252
- end
253
-
254
- style E fill:#c8e6c9
255
- style D fill:#ffecb3
256
- ```
257
-
258
- ## 今後の展望
259
-
260
- 1. **CI/CD 統合**: GitHub Actions で CodeGraph スキャンを自動実行
261
- 2. **自動修正 PR**: 検出された脆弱性に対する修正 PR を自動作成
262
- 3. **レポート生成**: セキュリティスキャン結果のダッシュボード化
263
- 4. **他の脆弱性パターン**: SQL Injection、XSS、Command Injection 等への拡張
264
-
265
- ---
266
-
267
- # 参考資料
268
-
269
- - [MUSUBIXv2.3.2-Refactering.md](./MUSUBIXv2.3.2-Refactering.md) - CodeGraph 基本機能の解説
270
- - [PHP unserialize マニュアル](https://www.php.net/manual/ja/function.unserialize.php)
271
- - [OWASP PHP Object Injection](https://owasp.org/www-community/vulnerabilities/PHP_Object_Injection)
272
-
273
- ---
274
-
275
- **作成日**: 2025-01-09
276
- **更新日**: 2025-01-10
277
- **作成者**: MUSUBIX CodeGraph v2.3.5
278
- **ライセンス**: MIT