osv-scanner-mcp 0.1.0
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.
- package/LICENSE +202 -0
- package/README.md +228 -0
- package/dist/errors.js +16 -0
- package/dist/index.js +62 -0
- package/dist/osv/binaryDownloader.js +127 -0
- package/dist/osv/binaryManager.js +79 -0
- package/dist/osv/osvApi.js +74 -0
- package/dist/osv/runner.js +103 -0
- package/dist/osv/scanReport.js +186 -0
- package/dist/osv/suggestFix.js +120 -0
- package/dist/osv/vulnerabilityExplanation.js +118 -0
- package/dist/test/osv/binaryDownloader.test.js +117 -0
- package/dist/test/osv/explainVulnerability.test.js +173 -0
- package/dist/test/osv/runner.test.js +170 -0
- package/dist/test/osv/scanReport.test.js +342 -0
- package/dist/test/osv/suggestFix.test.js +104 -0
- package/dist/test/tools/explainVulnerability.test.js +39 -0
- package/dist/test/tools/scanJavaProject.test.js +87 -0
- package/dist/test/tools/suggestFix.test.js +79 -0
- package/dist/test/utils/mavenVersion.test.js +185 -0
- package/dist/test/utils/projectDetector.test.js +154 -0
- package/dist/tools/explainVulnerability.js +18 -0
- package/dist/tools/scanJavaProject.js +23 -0
- package/dist/tools/suggestFix.js +29 -0
- package/dist/tools/toolResult.js +29 -0
- package/dist/utils/mavenVersion.js +211 -0
- package/dist/utils/projectDetector.js +122 -0
- package/dist/utils/unknownJson.js +18 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# OSV-Scanner-MCP
|
|
2
|
+
|
|
3
|
+
Google製 [OSV-Scanner](https://github.com/google/osv-scanner) をラップするMCPサーバーです。Claude等のMCPクライアントから「このJavaプロジェクトの脆弱性をチェックして」と自然言語で依頼するだけで、依存ライブラリの既知の脆弱性(CVE / GHSA)を深刻度順のレポートで取得できます。
|
|
4
|
+
|
|
5
|
+
> **ステータス**: MVP完成。Maven(pom.xml)と Gradle(gradle.lockfile / lockfile方式)に対応しています。
|
|
6
|
+
|
|
7
|
+
## 特徴
|
|
8
|
+
|
|
9
|
+
- **ワンショットスキャン**: `scan_java_project` ツールにプロジェクトパスを渡すだけで、検出→スキャン→整形済みレポートまで一気に返します
|
|
10
|
+
- **深刻度順のレポート**: パッケージごとに脆弱性をCVSSスコア順に整理し、5段階の深刻度ラベル(critical / high / medium / low / unknown)とサマリ集計付きで返します
|
|
11
|
+
- **修正版の提示**: 各脆弱性の `fixed_versions` をMavenバージョン優先順位規則で正しくソートして含めます(`2.17.1-RELEASE` のようなsemver非対応の表記にも対応)
|
|
12
|
+
- **セキュリティ第一の設計**: シェル非経由の実行・引数ホワイトリスト・パス正規化と境界チェック・タイムアウト/出力サイズ上限を実装段階から組み込んでいます
|
|
13
|
+
|
|
14
|
+
## 動作要件
|
|
15
|
+
|
|
16
|
+
- Node.js >= 20.19
|
|
17
|
+
- [OSV-Scanner](https://google.github.io/osv-scanner/) バイナリ — **手動インストールは不要です**。見つからない場合、公式GitHub Releasesからピン留めバージョンを自動ダウンロードし、パッケージに埋め込まれたSHA256チェックサムで検証してから使用します(`~/.cache/osv-scanner-mcp/` にキャッシュ)
|
|
18
|
+
- 手動インストール済みのバイナリ(PATH上または `OSV_SCANNER_PATH` 指定)があればそちらを優先します
|
|
19
|
+
- 自動ダウンロードを無効化する場合は `OSV_MCP_AUTO_DOWNLOAD=0`
|
|
20
|
+
- スキャン時(OSV-Scanner経由)および `explain_vulnerability` 実行時に `api.osv.dev` へのネットワークアクセスが発生します(照会先はOSVデータベースのみ)
|
|
21
|
+
|
|
22
|
+
## セットアップ
|
|
23
|
+
|
|
24
|
+
### Claude Code への登録
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
claude mcp add osv-scanner -- npx -y osv-scanner-mcp
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Claude Desktop への登録
|
|
31
|
+
|
|
32
|
+
`claude_desktop_config.json` に追加:
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"mcpServers": {
|
|
37
|
+
"osv-scanner": {
|
|
38
|
+
"command": "npx",
|
|
39
|
+
"args": ["-y", "osv-scanner-mcp"]
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### ソースから使う場合
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
git clone https://github.com/tedorigawa001/OSV-Scanner-MCP.git
|
|
49
|
+
cd OSV-Scanner-MCP
|
|
50
|
+
npm install
|
|
51
|
+
npm run build
|
|
52
|
+
# 登録時は `npx -y osv-scanner-mcp` の代わりに `node /path/to/OSV-Scanner-MCP/dist/index.js` を指定
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 環境変数
|
|
56
|
+
|
|
57
|
+
| 変数 | 説明 |
|
|
58
|
+
|---|---|
|
|
59
|
+
| `OSV_SCANNER_PATH` | 使用するosv-scannerバイナリの明示指定。省略時はPATH→自動ダウンロードの順で解決。**指定が無効な場合はフォールバックせずエラーになります**(意図しないバイナリの実行防止) |
|
|
60
|
+
| `OSV_MCP_ALLOWED_ROOT` | 指定時、このディレクトリ配下以外のスキャンを拒否します(パストラバーサル対策の境界) |
|
|
61
|
+
| `OSV_MCP_AUTO_DOWNLOAD` | `0` または `false` でバイナリの自動ダウンロードを無効化(デフォルト有効) |
|
|
62
|
+
|
|
63
|
+
## 提供ツール
|
|
64
|
+
|
|
65
|
+
### `scan_java_project`
|
|
66
|
+
|
|
67
|
+
Java(Maven)プロジェクトをスキャンし、既知の脆弱性レポートを返します。
|
|
68
|
+
|
|
69
|
+
**入力**
|
|
70
|
+
|
|
71
|
+
| パラメータ | 型 | 説明 |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| `project_path` | string | スキャン対象のプロジェクトディレクトリ、または pom.xml / gradle.lockfile の絶対パス |
|
|
74
|
+
|
|
75
|
+
> **Gradleプロジェクトについて**: 本ツールは**lockfile方式**のみ対応です(ビルド実行方式は build.gradle の任意コード実行を伴うため、セキュリティ上の理由から採用していません)。`gradle.lockfile` が無い場合は `./gradlew dependencies --write-locks` で生成してください(依存ロック未設定の場合は `build.gradle` に `dependencyLocking { lockAllConfigurations() }` の追加が必要です)。
|
|
76
|
+
|
|
77
|
+
**出力(成功時)**
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"project_dir": "/path/to/project",
|
|
82
|
+
"manifests": ["pom.xml"],
|
|
83
|
+
"source_files": ["/path/to/project/pom.xml"],
|
|
84
|
+
"vulnerable_package_count": 4,
|
|
85
|
+
"vulnerability_count": 14,
|
|
86
|
+
"severity_breakdown": { "critical": 3, "high": 3, "medium": 7, "low": 0, "unknown": 1 },
|
|
87
|
+
"packages": [
|
|
88
|
+
{
|
|
89
|
+
"name": "org.apache.logging.log4j:log4j-core",
|
|
90
|
+
"version": "2.14.1",
|
|
91
|
+
"ecosystem": "Maven",
|
|
92
|
+
"vulnerabilities": [
|
|
93
|
+
{
|
|
94
|
+
"id": "GHSA-jfh8-c2jp-5v3q",
|
|
95
|
+
"cve": "CVE-2021-44228",
|
|
96
|
+
"aliases": ["CVE-2021-44228"],
|
|
97
|
+
"severity_score": 10,
|
|
98
|
+
"severity": "critical",
|
|
99
|
+
"summary": "Remote code injection in Log4j",
|
|
100
|
+
"fixed_versions": ["2.3.1", "2.12.2", "2.15.0"]
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
- `packages` は最も深刻な脆弱性を持つ順、各 `vulnerabilities` は深刻度順(unknownは末尾)
|
|
109
|
+
- `fixed_versions` はMaven優先順位で昇順。複数のリリース系統(例: 2.12系バックポートと2.15系)が混在することがあります。空配列は「修正版が存在しない」ことを意味します
|
|
110
|
+
- `severity_score` が取得できない脆弱性は `null` / `"unknown"` として扱います
|
|
111
|
+
|
|
112
|
+
### `suggest_fix`
|
|
113
|
+
|
|
114
|
+
スキャンを実行し、脆弱なパッケージごとに**推奨アップグレードバージョン**を提案します。単純な最大バージョンではなく、現在のバージョンに最も近いリリース系統の修正版を3段階フォールバックで選定します:
|
|
115
|
+
|
|
116
|
+
| Tier | 意味 |
|
|
117
|
+
|---|---|
|
|
118
|
+
| `same_minor` | 現在と同じ major.minor 系統内の修正版(最小の変更で済む) |
|
|
119
|
+
| `major_internal` | 同一メジャー内の修正版(マイナーバージョンアップが必要) |
|
|
120
|
+
| `cross_major` | メジャーアップグレードが必要(破壊的変更の可能性あり) |
|
|
121
|
+
|
|
122
|
+
**入力**: `scan_java_project` と同じ(`project_path`)
|
|
123
|
+
|
|
124
|
+
**出力(成功時)**
|
|
125
|
+
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"project_dir": "/path/to/project",
|
|
129
|
+
"manifests": ["pom.xml"],
|
|
130
|
+
"vulnerable_package_count": 4,
|
|
131
|
+
"unfixed_vulnerability_count": 1,
|
|
132
|
+
"suggestions": [
|
|
133
|
+
{
|
|
134
|
+
"package": "org.apache.logging.log4j:log4j-core",
|
|
135
|
+
"current_version": "2.14.1",
|
|
136
|
+
"ecosystem": "Maven",
|
|
137
|
+
"recommended_upgrade": "2.25.4",
|
|
138
|
+
"upgrade_tier": "major_internal",
|
|
139
|
+
"upgrade_note": "2.14系統向けの修正版は存在しない。同一メジャー(2.x)内では2.25.4が7件のCVEを解消する最小版",
|
|
140
|
+
"per_cve_detail": [
|
|
141
|
+
{ "id": "GHSA-jfh8-c2jp-5v3q", "cve": "CVE-2021-44228", "severity": "critical", "fixed_in": "2.15.0", "tier": "major_internal" }
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
- `recommended_upgrade` は「修正可能な全CVEを解消できる最小バージョン」(CVEごとのTier結果の最大値)
|
|
149
|
+
- 修正版が存在しない(または現在より新しい修正版がない)CVEは `tier: "unfixed"` として明示し、推奨計算から除外します。全CVEがunfixedの場合 `recommended_upgrade` は `null`
|
|
150
|
+
|
|
151
|
+
### `explain_vulnerability`
|
|
152
|
+
|
|
153
|
+
指定したGHSA-ID / CVE-IDの脆弱性の詳細を**OSVデータベースAPI(api.osv.dev)から直接取得**して返します(スキャンは実行しません)。スキャン結果の `id` をそのまま渡せます。クライアントLLMの知識カットオフ以降に公開された脆弱性の説明に特に有効です。
|
|
154
|
+
|
|
155
|
+
**入力**
|
|
156
|
+
|
|
157
|
+
| パラメータ | 型 | 説明 |
|
|
158
|
+
|---|---|---|
|
|
159
|
+
| `vulnerability_id` | string | 脆弱性のID(例: `GHSA-jfh8-c2jp-5v3q`、`CVE-2021-44228`) |
|
|
160
|
+
|
|
161
|
+
**出力(成功時)**: `id` / `aliases` / `summary` / `details`(説明markdown、4,000字上限)/ `severity`(CVSSベクトル)/ `published` / `modified` / `affected`(影響パッケージとバージョン範囲)/ `references`(アドバイザリ・修正コミット等のURL、http/httpsのみ・20件上限)
|
|
162
|
+
|
|
163
|
+
> **注意**: OSVの正規IDはGHSA等のため、CVE-IDでは見つからない場合があります(その場合はエラーメッセージでGHSA-IDでの照会を案内します)。
|
|
164
|
+
|
|
165
|
+
**出力(エラー時)** — 全ツール共通
|
|
166
|
+
|
|
167
|
+
`isError: true` とともに、機械判読可能な `kind` を含むJSONを返します:
|
|
168
|
+
|
|
169
|
+
```json
|
|
170
|
+
{
|
|
171
|
+
"error": {
|
|
172
|
+
"kind": "no_manifest_found",
|
|
173
|
+
"message": "対応マニフェスト(pom.xml / gradle.lockfile)が見つかりません(深さ3まで探索): /path/to/project"
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
| kind | 意味 |
|
|
179
|
+
|---|---|
|
|
180
|
+
| `binary_not_found` | OSV-Scannerが見つからない(インストール案内をmessageに含む) |
|
|
181
|
+
| `project_not_found` | 指定パスが存在しない・ディレクトリ/pom.xmlでない |
|
|
182
|
+
| `no_manifest_found` | 対応マニフェスト(pom.xml / gradle.lockfile)が見つからない |
|
|
183
|
+
| `binary_download_failed` | バイナリのダウンロード失敗(未対応プラットフォーム含む) |
|
|
184
|
+
| `binary_checksum_mismatch` | ダウンロードしたバイナリのチェックサム不一致(改ざん/破損の可能性) |
|
|
185
|
+
| `gradle_lockfile_missing` | Gradleプロジェクトだがgradle.lockfileが無い(生成手順をmessageで案内) |
|
|
186
|
+
| `path_outside_allowed_root` | `OSV_MCP_ALLOWED_ROOT` の外を指している |
|
|
187
|
+
| `no_packages_found` | スキャン対象パッケージなし(依存関係が未定義のpom.xml等) |
|
|
188
|
+
| `scan_failed` | OSV-Scannerが異常終了(stderr抜粋を`detail`に含む) |
|
|
189
|
+
| `scan_timeout` | タイムアウト(デフォルト120秒) |
|
|
190
|
+
| `output_too_large` | 出力がサイズ上限(デフォルト32MB)を超過 |
|
|
191
|
+
| `invalid_output` | 出力がJSONとして解釈できない |
|
|
192
|
+
| `invalid_vulnerability_id` | 脆弱性IDの形式が不正 |
|
|
193
|
+
| `vulnerability_not_found` | 指定IDの脆弱性がOSVデータベースに存在しない |
|
|
194
|
+
| `api_request_failed` | OSV APIへのリクエスト失敗(ネットワーク・タイムアウト・非2xx) |
|
|
195
|
+
| `internal_error` | 想定外のエラー(内部情報は返しません) |
|
|
196
|
+
|
|
197
|
+
## セキュリティ設計
|
|
198
|
+
|
|
199
|
+
脆弱性診断ツール自体が攻撃経路にならないよう、以下を実装しています。
|
|
200
|
+
|
|
201
|
+
- **サプライチェーン対策**: バイナリの自動ダウンロードは公式GitHub Releasesに限定し、バージョンをピン留め。**パッケージに埋め込まれたSHA256チェックサム**で検証します(配布元のSHA256SUMSファイルは信用しないため、リリース側が改ざんされても検出可能)。検証合格まで実行権限を与えず、キャッシュ済みバイナリも使用のたびに再検証します
|
|
202
|
+
- **コマンドインジェクション対策**: シェルを経由しない `spawn` + 引数配列で実行。OSV-Scannerへの引数は固定リストのみで、可変部は検証済み絶対パス1つだけ
|
|
203
|
+
- **パストラバーサル対策**: 入力パスは `realpath` でシンボリックリンク解決後に境界チェック。pom.xml探索ではシンボリックリンクを辿りません
|
|
204
|
+
- **DoS対策**: タイムアウト・stdout上限・stderr抜粋上限を設定。スキャン結果は防御的にパースし、形式不正でも例外を投げません
|
|
205
|
+
- **情報漏えい対策**: 想定外の例外はスタックトレース等を含めず `internal_error` に丸めます。外部由来のテキスト(脆弱性summary等)は長さ上限付きの「データ」として構造化して返します
|
|
206
|
+
|
|
207
|
+
## 開発
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
npm test # テスト実行(vitest)
|
|
211
|
+
npx vitest run --coverage # カバレッジ計測
|
|
212
|
+
npm run typecheck # 型チェック
|
|
213
|
+
npm run build # dist/ へビルド
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
設計メモ・残課題は [docs/DESIGN_TODO.md](docs/DESIGN_TODO.md) を参照してください。
|
|
217
|
+
|
|
218
|
+
## ロードマップ
|
|
219
|
+
|
|
220
|
+
- [x] `suggest_fix` ツール: 現在のバージョンに最も近い系統の修正版を提案(3段階Tierフォールバック)
|
|
221
|
+
- [x] `explain_vulnerability` ツール: 脆弱性の詳細説明(OSV API経由)
|
|
222
|
+
- [x] npmパッケージ化(`npx osv-scanner-mcp`)
|
|
223
|
+
- [x] OSV-Scannerバイナリの自動ダウンロード(チェックサム検証付き)
|
|
224
|
+
- [x] Gradle対応(lockfile方式)
|
|
225
|
+
|
|
226
|
+
## ライセンス
|
|
227
|
+
|
|
228
|
+
[Apache License 2.0](LICENSE)
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* スキャン処理全体で使う型付きエラー。
|
|
3
|
+
* MCPツール層はこの`kind`を見てエラーレスポンスの形式に変換する想定。
|
|
4
|
+
*/
|
|
5
|
+
export class ScanToolError extends Error {
|
|
6
|
+
kind;
|
|
7
|
+
detail;
|
|
8
|
+
constructor(kind, message,
|
|
9
|
+
/** stderr抜粋などの補足情報(外部由来テキストのため上限付きで格納すること) */
|
|
10
|
+
detail) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.kind = kind;
|
|
13
|
+
this.detail = detail;
|
|
14
|
+
this.name = "ScanToolError";
|
|
15
|
+
}
|
|
16
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* OSV-Scanner-MCP: Google OSV-ScannerをラップするMCPサーバー(stdioトランスポート)。
|
|
4
|
+
*
|
|
5
|
+
* 環境変数:
|
|
6
|
+
* - OSV_SCANNER_PATH: 使用するosv-scannerバイナリの明示指定(省略時はPATHから探索)
|
|
7
|
+
* - OSV_MCP_ALLOWED_ROOT: 指定時、このディレクトリ配下以外のスキャンを拒否する
|
|
8
|
+
*/
|
|
9
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
10
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { handleExplainVulnerability } from "./tools/explainVulnerability.js";
|
|
13
|
+
import { handleScanJavaProject } from "./tools/scanJavaProject.js";
|
|
14
|
+
import { handleSuggestFix } from "./tools/suggestFix.js";
|
|
15
|
+
export const ALLOWED_ROOT_ENV = "OSV_MCP_ALLOWED_ROOT";
|
|
16
|
+
const server = new McpServer({
|
|
17
|
+
name: "osv-scanner-mcp",
|
|
18
|
+
version: "0.1.0",
|
|
19
|
+
});
|
|
20
|
+
server.registerTool("scan_java_project", {
|
|
21
|
+
title: "Javaプロジェクトの脆弱性スキャン",
|
|
22
|
+
description: "Java(Maven)プロジェクトをGoogle OSV-Scannerでスキャンし、依存ライブラリの既知の脆弱性(CVE/GHSA)を深刻度順のJSONレポートで返す。" +
|
|
23
|
+
"レポートにはパッケージごとの脆弱性一覧(CVSSスコア・5段階深刻度・修正版バージョン)とサマリ集計が含まれる。" +
|
|
24
|
+
"Maven(pom.xml)とGradle(gradle.lockfile)に対応。",
|
|
25
|
+
inputSchema: {
|
|
26
|
+
project_path: z
|
|
27
|
+
.string()
|
|
28
|
+
.min(1)
|
|
29
|
+
.describe("スキャン対象のプロジェクトディレクトリ、またはpom.xml/gradle.lockfileの絶対パス"),
|
|
30
|
+
},
|
|
31
|
+
}, async ({ project_path }) => handleScanJavaProject({ project_path }, { allowedRoot: process.env[ALLOWED_ROOT_ENV] }));
|
|
32
|
+
server.registerTool("suggest_fix", {
|
|
33
|
+
title: "脆弱性を解消する推奨アップグレードの提案",
|
|
34
|
+
description: "Java(Maven)プロジェクトをスキャンし、脆弱な依存パッケージごとに推奨アップグレードバージョンを提案する。" +
|
|
35
|
+
"現在のバージョンに最も近いリリース系統の修正版を優先する3段階フォールバック" +
|
|
36
|
+
"(same_minor: 同一major.minor系統内 → major_internal: 同一メジャー内 → cross_major: メジャーアップグレード)で選定し、" +
|
|
37
|
+
"推奨バージョン・アップグレード距離(upgrade_tier)・CVEごとの修正版を返す。" +
|
|
38
|
+
"修正版が存在しないCVEはunfixedとして明示する。Maven(pom.xml)とGradle(gradle.lockfile)に対応。",
|
|
39
|
+
inputSchema: {
|
|
40
|
+
project_path: z
|
|
41
|
+
.string()
|
|
42
|
+
.min(1)
|
|
43
|
+
.describe("スキャン対象のプロジェクトディレクトリ、またはpom.xml/gradle.lockfileの絶対パス"),
|
|
44
|
+
},
|
|
45
|
+
}, async ({ project_path }) => handleSuggestFix({ project_path }, { allowedRoot: process.env[ALLOWED_ROOT_ENV] }));
|
|
46
|
+
server.registerTool("explain_vulnerability", {
|
|
47
|
+
title: "脆弱性の詳細説明の取得",
|
|
48
|
+
description: "指定したGHSA-IDまたはCVE-IDの脆弱性の詳細をOSVデータベース(api.osv.dev)から取得して返す。" +
|
|
49
|
+
"説明(details)・CVSSベクトル・影響を受けるパッケージとバージョン範囲・参照リンク(アドバイザリや修正コミット)が含まれる。" +
|
|
50
|
+
"scan_java_projectやsuggest_fixの結果に含まれるIDをそのまま渡せる。スキャンは実行しない。",
|
|
51
|
+
inputSchema: {
|
|
52
|
+
vulnerability_id: z
|
|
53
|
+
.string()
|
|
54
|
+
.min(3)
|
|
55
|
+
.max(100)
|
|
56
|
+
.describe("脆弱性のID(例: GHSA-jfh8-c2jp-5v3q、CVE-2021-44228)"),
|
|
57
|
+
},
|
|
58
|
+
}, async ({ vulnerability_id }) => handleExplainVulnerability({ vulnerability_id }));
|
|
59
|
+
const transport = new StdioServerTransport();
|
|
60
|
+
await server.connect(transport);
|
|
61
|
+
// stdoutはMCPプロトコル専用のため、起動ログはstderrへ
|
|
62
|
+
console.error("osv-scanner-mcp: MCP server running on stdio");
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OSV-Scannerバイナリの自動ダウンロード(docs/DESIGN_TODO.md 方式B)。
|
|
3
|
+
*
|
|
4
|
+
* サプライチェーン対策:
|
|
5
|
+
* - 取得元は公式GitHub Releases(github.com/google/osv-scanner)に限定
|
|
6
|
+
* - バージョンをピン留めし、各プラットフォームのSHA256を**このソースに埋め込む**。
|
|
7
|
+
* リリース側のSHA256SUMSファイルは参照しない(配布元が改ざんされた場合でも、
|
|
8
|
+
* リポジトリにコミットされた値との照合で検出できる)
|
|
9
|
+
* - チェックサム検証に合格するまでファイルに実行権限を与えない
|
|
10
|
+
* (一時ファイルに書き込み→検証→chmod→アトミックにリネーム)
|
|
11
|
+
* - キャッシュ済みバイナリも使用のたびに再検証する(キャッシュ改ざん対策)
|
|
12
|
+
*/
|
|
13
|
+
import { createHash } from "node:crypto";
|
|
14
|
+
import { chmod, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
15
|
+
import os from "node:os";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
import { ScanToolError } from "../errors.js";
|
|
18
|
+
/** ピン留めするOSV-Scannerのバージョン。更新時は下のチェックサムも必ず更新すること */
|
|
19
|
+
export const PINNED_OSV_SCANNER_VERSION = "2.4.0";
|
|
20
|
+
/**
|
|
21
|
+
* v2.4.0公式リリースのSHA256(osv-scanner_SHA256SUMSより転記、2026-07-04取得)。
|
|
22
|
+
* https://github.com/google/osv-scanner/releases/tag/v2.4.0
|
|
23
|
+
*/
|
|
24
|
+
const ASSET_CHECKSUMS = {
|
|
25
|
+
"osv-scanner_darwin_amd64": "088119325156321c34c456ac3703d6013538fd71cbac82b891ab34db491e4d66",
|
|
26
|
+
"osv-scanner_darwin_arm64": "9ca3185ad63e9ab54f7cb90f46a7362be02d80e37f0123d095a54355ea202f5d",
|
|
27
|
+
"osv-scanner_linux_amd64": "15314940c10d26af9c6649f150b8a47c1262e8fc7e17b1d1029b0e479e8ed8a0",
|
|
28
|
+
"osv-scanner_linux_arm64": "44e580752910f0ff36ec99aff59af20f65df1e859aa31e5605a8f0d055b496e9",
|
|
29
|
+
"osv-scanner_windows_amd64.exe": "0cdd113610126d5dfd5e12ad0e0b4f3e879291ff19bb43b0c52ed2f2c2df1a37",
|
|
30
|
+
"osv-scanner_windows_arm64.exe": "1ce89d7d8ef083634648ef0f193fe1254f36f46f4bdc93d61178adacc2e60da0",
|
|
31
|
+
};
|
|
32
|
+
const DOWNLOAD_TIMEOUT_MS = 300_000;
|
|
33
|
+
/** バイナリは実測50〜55MB。余裕を持たせつつ暴走は防ぐ */
|
|
34
|
+
const MAX_BINARY_BYTES = 200 * 1024 * 1024;
|
|
35
|
+
/** GitHub Releasesの資産名(例: osv-scanner_darwin_arm64)。未対応プラットフォームはnull */
|
|
36
|
+
export function assetNameForPlatform(platform = process.platform, arch = process.arch) {
|
|
37
|
+
const osName = { darwin: "darwin", linux: "linux", win32: "windows" }[platform];
|
|
38
|
+
const cpuName = { x64: "amd64", arm64: "arm64" }[arch];
|
|
39
|
+
if (osName === undefined || cpuName === undefined)
|
|
40
|
+
return null;
|
|
41
|
+
return `osv-scanner_${osName}_${cpuName}${osName === "windows" ? ".exe" : ""}`;
|
|
42
|
+
}
|
|
43
|
+
function defaultCacheDir() {
|
|
44
|
+
const xdg = process.env.XDG_CACHE_HOME;
|
|
45
|
+
const base = xdg !== undefined && xdg.trim() !== "" ? xdg : path.join(os.homedir(), ".cache");
|
|
46
|
+
return path.join(base, "osv-scanner-mcp");
|
|
47
|
+
}
|
|
48
|
+
function sha256Hex(data) {
|
|
49
|
+
return createHash("sha256").update(data).digest("hex");
|
|
50
|
+
}
|
|
51
|
+
async function verifyFile(filePath, expectedSha256) {
|
|
52
|
+
try {
|
|
53
|
+
return sha256Hex(await readFile(filePath)) === expectedSha256;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function downloadAsset(url, fetchFn, timeoutMs) {
|
|
60
|
+
let response;
|
|
61
|
+
try {
|
|
62
|
+
response = await fetchFn(url, { signal: AbortSignal.timeout(timeoutMs) });
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
const isTimeout = error instanceof Error && error.name === "TimeoutError";
|
|
66
|
+
throw new ScanToolError("binary_download_failed", isTimeout
|
|
67
|
+
? `OSV-Scannerのダウンロードが${Math.round(timeoutMs / 1000)}秒以内に完了しませんでした`
|
|
68
|
+
: "OSV-Scannerのダウンロードに失敗しました(ネットワークを確認してください)");
|
|
69
|
+
}
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
throw new ScanToolError("binary_download_failed", `OSV-Scannerのダウンロードに失敗しました(HTTP ${response.status}): ${url}`);
|
|
72
|
+
}
|
|
73
|
+
const contentLength = Number(response.headers.get("content-length") ?? "0");
|
|
74
|
+
if (contentLength > MAX_BINARY_BYTES) {
|
|
75
|
+
throw new ScanToolError("binary_download_failed", `ダウンロードサイズが上限(${MAX_BINARY_BYTES}バイト)を超えています`);
|
|
76
|
+
}
|
|
77
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
78
|
+
if (buffer.byteLength > MAX_BINARY_BYTES) {
|
|
79
|
+
throw new ScanToolError("binary_download_failed", `ダウンロードサイズが上限(${MAX_BINARY_BYTES}バイト)を超えています`);
|
|
80
|
+
}
|
|
81
|
+
return buffer;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* ピン留めバージョンのOSV-Scannerをキャッシュから返す。
|
|
85
|
+
* 無ければ公式GitHub Releasesからダウンロードし、チェックサム検証後に配置する。
|
|
86
|
+
*
|
|
87
|
+
* @returns 検証済みバイナリの絶対パス
|
|
88
|
+
*/
|
|
89
|
+
export async function ensureOsvScannerDownloaded(options = {}) {
|
|
90
|
+
const assetName = assetNameForPlatform(options.platform, options.arch);
|
|
91
|
+
if (assetName === null) {
|
|
92
|
+
throw new ScanToolError("binary_download_failed", `このプラットフォーム(${options.platform ?? process.platform}/${options.arch ?? process.arch})向けのOSV-Scanner公式バイナリが存在しません。手動でインストールし、環境変数OSV_SCANNER_PATHで指定してください`);
|
|
93
|
+
}
|
|
94
|
+
const checksums = options.checksums ?? ASSET_CHECKSUMS;
|
|
95
|
+
const expected = checksums[assetName];
|
|
96
|
+
if (expected === undefined) {
|
|
97
|
+
throw new ScanToolError("binary_download_failed", `${assetName}の埋め込みチェックサムがありません(パッケージの更新が必要です)`);
|
|
98
|
+
}
|
|
99
|
+
const cacheDir = options.cacheDir ?? defaultCacheDir();
|
|
100
|
+
const versionDir = path.join(cacheDir, `v${PINNED_OSV_SCANNER_VERSION}`);
|
|
101
|
+
const targetPath = path.join(versionDir, assetName);
|
|
102
|
+
// キャッシュ済みでも毎回検証する(改ざん・破損したキャッシュは再ダウンロード)
|
|
103
|
+
if (await verifyFile(targetPath, expected)) {
|
|
104
|
+
return targetPath;
|
|
105
|
+
}
|
|
106
|
+
const url = `https://github.com/google/osv-scanner/releases/download/v${PINNED_OSV_SCANNER_VERSION}/${assetName}`;
|
|
107
|
+
console.error(`osv-scanner-mcp: OSV-Scanner v${PINNED_OSV_SCANNER_VERSION} をダウンロード中... (${url})`);
|
|
108
|
+
const buffer = await downloadAsset(url, options.fetchFn ?? fetch, options.timeoutMs ?? DOWNLOAD_TIMEOUT_MS);
|
|
109
|
+
const actual = sha256Hex(buffer);
|
|
110
|
+
if (actual !== expected) {
|
|
111
|
+
throw new ScanToolError("binary_checksum_mismatch", `ダウンロードしたOSV-Scannerのチェックサムが一致しません(改ざんまたは破損の可能性)。expected=${expected} actual=${actual}`);
|
|
112
|
+
}
|
|
113
|
+
// 検証合格後に初めて実行権限を付与し、アトミックに配置する
|
|
114
|
+
await mkdir(versionDir, { recursive: true });
|
|
115
|
+
const tempPath = `${targetPath}.download-${process.pid}`;
|
|
116
|
+
try {
|
|
117
|
+
await writeFile(tempPath, buffer, { mode: 0o600 });
|
|
118
|
+
await chmod(tempPath, 0o755);
|
|
119
|
+
await rename(tempPath, targetPath);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
await rm(tempPath, { force: true });
|
|
123
|
+
throw new ScanToolError("binary_download_failed", `OSV-Scannerの配置に失敗しました: ${error instanceof Error ? error.message : String(error)}`);
|
|
124
|
+
}
|
|
125
|
+
console.error(`osv-scanner-mcp: 検証済みバイナリを配置しました: ${targetPath}`);
|
|
126
|
+
return targetPath;
|
|
127
|
+
}
|