@sunchao116/mcp-audit 1.0.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/package.json +36 -0
- package/src/audit/currentAudit.js +50 -0
- package/src/audit/getDepChain.js +47 -0
- package/src/audit/index.js +28 -0
- package/src/audit/normalizeAuditResult.js +47 -0
- package/src/audit/npmAudit.js +10 -0
- package/src/audit/remoteAudit.js +24 -0
- package/src/audit/test/test-currentAudit.js +15 -0
- package/src/audit/test/test-getDepChain.js +13 -0
- package/src/audit/test/test-index.js +17 -0
- package/src/audit/test/test-normalizeAuditResult.js +18 -0
- package/src/audit/test/test-npmAudit.js +15 -0
- package/src/audit/test/test-remoteAudit.js +15 -0
- package/src/audit/test/workdir/audit.json +2130 -0
- package/src/audit/test/workdir/current.json +10 -0
- package/src/audit/test/workdir/index.json +2398 -0
- package/src/audit/test/workdir/normalized.json +2581 -0
- package/src/audit/test/workdir/package-lock.json +16137 -0
- package/src/audit/test/workdir/package.json +1 -0
- package/src/audit/test/workdir/remote.json +75 -0
- package/src/common/utils.js +35 -0
- package/src/entry/index.js +28 -0
- package/src/entry/test/result/result-local.md +1177 -0
- package/src/entry/test/result/result-remote.md +151 -0
- package/src/entry/test/test-index.js +15 -0
- package/src/generateLock/generateLock.js +27 -0
- package/src/generateLock/index.js +1 -0
- package/src/generateLock/test/1.json +1 -0
- package/src/generateLock/test/test.js +15 -0
- package/src/generateLock/test/workdir/package-lock.json +16137 -0
- package/src/generateLock/test/workdir/package.json +1 -0
- package/src/main/index.js +23 -0
- package/src/mcpServer.js +43 -0
- package/src/parseProject/index.js +18 -0
- package/src/parseProject/parseLocalProject.js +8 -0
- package/src/parseProject/parseRemoteProject.js +65 -0
- package/src/parseProject/test/test.js +26 -0
- package/src/render/index.js +24 -0
- package/src/render/markdown.js +17 -0
- package/src/render/template/audit.ejs +30 -0
- package/src/render/template/detail-item.ejs +32 -0
- package/src/render/template/detail.ejs +7 -0
- package/src/render/template/index.ejs +8 -0
- package/src/render/test/test-index.js +27 -0
- package/src/render/test/workdir/auditResult.json +2101 -0
- package/src/render/test/workdir/index.md +1221 -0
- package/src/render/test/workdir/package.json +38 -0
- package/src/workDir/index.js +21 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"my-site","version":"0.1.0","private":true,"scripts":{"serve":"vue-cli-service serve","build":"vue-cli-service build --modern","test:Pager":"vue serve ./src/components/Pager/test.vue","test:Avatar":"vue serve ./src/components/Avatar/test.vue","test:Icon":"vue serve ./src/components/Icon/test.vue","test:Empty":"vue serve ./src/components/Empty/test.vue","test:ImageLoader":"vue serve ./src/components/ImageLoader/test.vue","test:Contact":"vue serve ./src/components/SiteAside/Contact/test.vue","test:Menu":"vue serve ./src/components/SiteAside/Menu/test.vue","test:SiteAside":"vue serve ./src/components/SiteAside/test.vue","test:Layout":"vue serve ./src/components/Layout/test.vue","test:RightList":"vue serve ./src/views/Blog/components/RightList-test.vue"},"dependencies":{"axios":"^0.21.0","core-js":"^3.6.5","highlight.js":"^10.5.0","mockjs":"^1.1.0","nprogress":"^0.2.0","querystring":"^0.2.0","vue":"^2.6.11","vue-router":"^3.4.9","vuex":"^3.6.2"},"devDependencies":{"@vue/cli-plugin-babel":"~4.5.0","@vue/cli-service":"~4.5.0","less":"^3.0.4","less-loader":"^5.0.0","vue-template-compiler":"^2.6.11","webpack-bundle-analyzer":"^4.4.0"}}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"actions": [
|
|
3
|
+
{
|
|
4
|
+
"isMajor": false,
|
|
5
|
+
"action": "install",
|
|
6
|
+
"resolves": [
|
|
7
|
+
{
|
|
8
|
+
"id": 1098366,
|
|
9
|
+
"path": "ejs",
|
|
10
|
+
"dev": false,
|
|
11
|
+
"optional": false,
|
|
12
|
+
"bundled": false
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"module": "ejs",
|
|
16
|
+
"target": "3.1.10"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"advisories": {
|
|
20
|
+
"1098366": {
|
|
21
|
+
"findings": [
|
|
22
|
+
{
|
|
23
|
+
"version": "3.1.9",
|
|
24
|
+
"paths": [
|
|
25
|
+
"ejs"
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"found_by": null,
|
|
30
|
+
"deleted": null,
|
|
31
|
+
"references": "- https://nvd.nist.gov/vuln/detail/CVE-2024-33883\n- https://github.com/mde/ejs/commit/e469741dca7df2eb400199e1cdb74621e3f89aa5\n- https://github.com/mde/ejs/compare/v3.1.9...v3.1.10\n- https://security.netapp.com/advisory/ntap-20240605-0003\n- https://github.com/advisories/GHSA-ghr5-ch3p-vcr6",
|
|
32
|
+
"created": "2024-04-28T18:30:31.000Z",
|
|
33
|
+
"id": 1098366,
|
|
34
|
+
"npm_advisory_id": null,
|
|
35
|
+
"overview": "The ejs (aka Embedded JavaScript templates) package before 3.1.10 for Node.js lacks certain pollution protection.",
|
|
36
|
+
"reported_by": null,
|
|
37
|
+
"title": "ejs lacks certain pollution protection",
|
|
38
|
+
"metadata": null,
|
|
39
|
+
"cves": [
|
|
40
|
+
"CVE-2024-33883"
|
|
41
|
+
],
|
|
42
|
+
"access": "public",
|
|
43
|
+
"severity": "moderate",
|
|
44
|
+
"module_name": "ejs",
|
|
45
|
+
"vulnerable_versions": "<3.1.10",
|
|
46
|
+
"github_advisory_id": "GHSA-ghr5-ch3p-vcr6",
|
|
47
|
+
"recommendation": "Upgrade to version 3.1.10 or later",
|
|
48
|
+
"patched_versions": ">=3.1.10",
|
|
49
|
+
"updated": "2024-08-02T15:45:54.000Z",
|
|
50
|
+
"cvss": {
|
|
51
|
+
"score": 4,
|
|
52
|
+
"vectorString": "CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L"
|
|
53
|
+
},
|
|
54
|
+
"cwe": [
|
|
55
|
+
"CWE-693",
|
|
56
|
+
"CWE-1321"
|
|
57
|
+
],
|
|
58
|
+
"url": "https://github.com/advisories/GHSA-ghr5-ch3p-vcr6"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"muted": [],
|
|
62
|
+
"metadata": {
|
|
63
|
+
"vulnerabilities": {
|
|
64
|
+
"info": 0,
|
|
65
|
+
"low": 0,
|
|
66
|
+
"moderate": 1,
|
|
67
|
+
"high": 0,
|
|
68
|
+
"critical": 0
|
|
69
|
+
},
|
|
70
|
+
"dependencies": 1,
|
|
71
|
+
"devDependencies": 0,
|
|
72
|
+
"optionalDependencies": 0,
|
|
73
|
+
"totalDependencies": 1
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
2
|
+
import { dirname } from 'path';
|
|
3
|
+
import { exec } from 'child_process';
|
|
4
|
+
import { promisify } from 'util';
|
|
5
|
+
|
|
6
|
+
const execAsync = promisify(exec); // 将 exec 转换为返回 Promise 的函数
|
|
7
|
+
|
|
8
|
+
export async function runCommand(cmd, cwd) {
|
|
9
|
+
try {
|
|
10
|
+
const stdout = await execAsync(cmd, {
|
|
11
|
+
cwd,
|
|
12
|
+
encoding: 'utf-8',
|
|
13
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
14
|
+
});
|
|
15
|
+
// 返回 audit 的 JSON 结果
|
|
16
|
+
return stdout.stdout.toString();
|
|
17
|
+
} catch (err) {
|
|
18
|
+
if (err.stdout) {
|
|
19
|
+
return err.stdout.toString();
|
|
20
|
+
}
|
|
21
|
+
throw err;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function uniqueId() {
|
|
26
|
+
return Math.random().toString(36).substring(2, 15) + Date.now().toString(36);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function getFilename(importMetaUrl) {
|
|
30
|
+
return fileURLToPath(importMetaUrl);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function getDirname(importMetaUrl) {
|
|
34
|
+
return dirname(getFilename(importMetaUrl));
|
|
35
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createWorkDir, deleteWorkDir } from '../workDir/index.js';
|
|
2
|
+
import { parseProject } from '../parseProject/index.js';
|
|
3
|
+
import { generateLock } from '../generateLock/index.js';
|
|
4
|
+
import { audit } from '../audit/index.js';
|
|
5
|
+
import { render } from '../render/index.js';
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 根据项目根目录,审计项目中所有的包(含项目本身)
|
|
10
|
+
* @param {string} projectRoot 项目根目录,可以是本地目录的绝对路径,也可以是远程仓库的URL
|
|
11
|
+
* @param {string} savePath 保存审计结果的文件名,审计结果是一个标准格式的markdown字符串
|
|
12
|
+
*/
|
|
13
|
+
export async function auditPackage(projectRoot, savePath) {
|
|
14
|
+
// 1. 创建工作目录
|
|
15
|
+
const workDir = await createWorkDir();
|
|
16
|
+
// 2. 解析项目,向工作目录添加pacakge.json
|
|
17
|
+
const packageJson = await parseProject(projectRoot);
|
|
18
|
+
// 3. 生成lock文件
|
|
19
|
+
await generateLock(workDir, packageJson);
|
|
20
|
+
// 4. 对工作目录进行审计
|
|
21
|
+
const auditResult = await audit(workDir, packageJson);
|
|
22
|
+
// 5. 渲染审计结果
|
|
23
|
+
const renderedResult = await render(auditResult, packageJson);
|
|
24
|
+
// 6. 删除工作目录
|
|
25
|
+
await deleteWorkDir(workDir);
|
|
26
|
+
// 7. 将结果保存到指定路径
|
|
27
|
+
await fs.promises.writeFile(savePath, renderedResult);
|
|
28
|
+
}
|