@greenarmor/ges-scanner-integration 1.0.1 → 1.1.1

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.
@@ -0,0 +1,18 @@
1
+ export interface DependencyFinding {
2
+ package: string;
3
+ version: string;
4
+ severity: "critical" | "high" | "medium" | "low";
5
+ type: "vulnerability" | "license" | "outdated" | "deprecated";
6
+ description: string;
7
+ recommendation: string;
8
+ }
9
+ export interface DependencyReport {
10
+ totalDeps: number;
11
+ findings: DependencyFinding[];
12
+ licenseSummary: Record<string, number>;
13
+ outdatedCount: number;
14
+ deprecatedCount: number;
15
+ vulnerabilityCount: number;
16
+ }
17
+ export declare function analyzeDependencies(projectPath?: string): DependencyReport;
18
+ export declare function formatDependencyReport(report: DependencyReport): string;
@@ -0,0 +1,342 @@
1
+ import { execSync } from "node:child_process";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ export function analyzeDependencies(projectPath = ".") {
5
+ const findings = [];
6
+ let totalDeps = 0;
7
+ const licenseSummary = {};
8
+ let outdatedCount = 0;
9
+ let deprecatedCount = 0;
10
+ let vulnerabilityCount = 0;
11
+ if (existsSync(join(projectPath, "package.json"))) {
12
+ const result = analyzeNodeProject(projectPath);
13
+ findings.push(...result.findings);
14
+ totalDeps += result.totalDeps;
15
+ Object.assign(licenseSummary, result.licenseSummary);
16
+ outdatedCount += result.outdatedCount;
17
+ deprecatedCount += result.deprecatedCount;
18
+ vulnerabilityCount += result.vulnerabilityCount;
19
+ }
20
+ if (existsSync(join(projectPath, "requirements.txt")) || existsSync(join(projectPath, "pyproject.toml"))) {
21
+ const result = analyzePythonProject(projectPath);
22
+ findings.push(...result.findings);
23
+ totalDeps += result.totalDeps;
24
+ Object.assign(licenseSummary, result.licenseSummary);
25
+ vulnerabilityCount += result.vulnerabilityCount;
26
+ }
27
+ if (existsSync(join(projectPath, "Cargo.toml"))) {
28
+ const result = analyzeRustProject(projectPath);
29
+ findings.push(...result.findings);
30
+ totalDeps += result.totalDeps;
31
+ vulnerabilityCount += result.vulnerabilityCount;
32
+ }
33
+ if (existsSync(join(projectPath, "go.mod"))) {
34
+ const result = analyzeGoProject(projectPath);
35
+ findings.push(...result.findings);
36
+ totalDeps += result.totalDeps;
37
+ vulnerabilityCount += result.vulnerabilityCount;
38
+ }
39
+ return { totalDeps, findings, licenseSummary, outdatedCount, deprecatedCount, vulnerabilityCount };
40
+ }
41
+ function analyzeNodeProject(projectPath) {
42
+ const findings = [];
43
+ const licenseSummary = {};
44
+ let totalDeps = 0;
45
+ let outdatedCount = 0;
46
+ let deprecatedCount = 0;
47
+ let vulnerabilityCount = 0;
48
+ try {
49
+ const pkgContent = readFileSync(join(projectPath, "package.json"), "utf-8");
50
+ const pkg = JSON.parse(pkgContent);
51
+ const deps = { ...(pkg.dependencies || {}), ...(pkg.devDependencies || {}) };
52
+ totalDeps = Object.keys(deps).length;
53
+ for (const [name, version] of Object.entries(deps)) {
54
+ if (isDeprecatedNodePackage(name)) {
55
+ deprecatedCount++;
56
+ findings.push({
57
+ package: name,
58
+ version: version,
59
+ severity: "medium",
60
+ type: "deprecated",
61
+ description: `Package "${name}" is deprecated or known to have maintenance issues.`,
62
+ recommendation: getDeprecatedRecommendation(name),
63
+ });
64
+ }
65
+ if (hasCopyleftLicense(name)) {
66
+ licenseSummary["copyleft"] = (licenseSummary["copyleft"] || 0) + 1;
67
+ findings.push({
68
+ package: name,
69
+ version: version,
70
+ severity: "medium",
71
+ type: "license",
72
+ description: `Package "${name}" may use a copyleft license (GPL, AGPL). Verify compatibility with your project license.`,
73
+ recommendation: "Review the package license. Consider an alternative with a permissive license (MIT, Apache-2.0, BSD).",
74
+ });
75
+ }
76
+ }
77
+ }
78
+ catch {
79
+ // not parseable
80
+ }
81
+ try {
82
+ const auditOutput = execSync("npm audit --json", {
83
+ cwd: projectPath,
84
+ encoding: "utf-8",
85
+ timeout: 30000,
86
+ stdio: ["pipe", "pipe", "pipe"],
87
+ });
88
+ const audit = JSON.parse(auditOutput);
89
+ const vulns = audit.vulnerabilities || audit.vulnerabilities || {};
90
+ for (const [name, info] of Object.entries(vulns)) {
91
+ const severity = info.severity || "medium";
92
+ vulnerabilityCount++;
93
+ findings.push({
94
+ package: name,
95
+ version: info.range || "unknown",
96
+ severity: severity,
97
+ type: "vulnerability",
98
+ description: `Vulnerability in "${name}": ${info.title || info.advisory || "Security vulnerability detected"}`,
99
+ recommendation: info.fixAvailable ? `Update to ${typeof info.fixAvailable === "object" ? info.fixAvailable.version : "latest"}` : "No fix available. Consider replacing this dependency.",
100
+ });
101
+ }
102
+ }
103
+ catch {
104
+ // npm audit not available or failed
105
+ }
106
+ try {
107
+ const outdatedOutput = execSync("npm outdated --json", {
108
+ cwd: projectPath,
109
+ encoding: "utf-8",
110
+ timeout: 30000,
111
+ stdio: ["pipe", "pipe", "pipe"],
112
+ });
113
+ if (outdatedOutput.trim()) {
114
+ const outdated = JSON.parse(outdatedOutput);
115
+ for (const [name, info] of Object.entries(outdated)) {
116
+ outdatedCount++;
117
+ findings.push({
118
+ package: name,
119
+ version: info.current || "unknown",
120
+ severity: "low",
121
+ type: "outdated",
122
+ description: `Package "${name}" is outdated: ${info.current} -> ${info.latest}`,
123
+ recommendation: `Update with: npm install ${name}@latest`,
124
+ });
125
+ }
126
+ }
127
+ }
128
+ catch {
129
+ // npm outdated not available or failed
130
+ }
131
+ if (!licenseSummary["permissive"])
132
+ licenseSummary["permissive"] = totalDeps - (licenseSummary["copyleft"] || 0);
133
+ return { totalDeps, findings, licenseSummary, outdatedCount, deprecatedCount, vulnerabilityCount };
134
+ }
135
+ function analyzePythonProject(projectPath) {
136
+ const findings = [];
137
+ let totalDeps = 0;
138
+ let vulnerabilityCount = 0;
139
+ try {
140
+ const reqFile = existsSync(join(projectPath, "requirements.txt"))
141
+ ? readFileSync(join(projectPath, "requirements.txt"), "utf-8")
142
+ : readFileSync(join(projectPath, "pyproject.toml"), "utf-8");
143
+ const deps = reqFile
144
+ .split("\n")
145
+ .map((l) => l.trim())
146
+ .filter((l) => l && !l.startsWith("#") && !l.startsWith("["));
147
+ totalDeps = deps.length;
148
+ }
149
+ catch {
150
+ // not readable
151
+ }
152
+ try {
153
+ const pipAudit = execSync("pip-audit --format json 2>/dev/null || pip install pip-audit && pip-audit --format json", {
154
+ cwd: projectPath,
155
+ encoding: "utf-8",
156
+ timeout: 60000,
157
+ stdio: ["pipe", "pipe", "pipe"],
158
+ });
159
+ if (pipAudit.trim()) {
160
+ const audit = JSON.parse(pipAudit);
161
+ for (const vuln of audit.dependencies || []) {
162
+ vulnerabilityCount++;
163
+ findings.push({
164
+ package: vuln.name,
165
+ version: vuln.version || "unknown",
166
+ severity: "high",
167
+ type: "vulnerability",
168
+ description: `Python vulnerability in "${vuln.name}": ${vuln.vulns?.[0]?.id || "Security issue"}`,
169
+ recommendation: `Upgrade ${vuln.name} to ${vuln.vulns?.[0]?.fix_versions?.[0] || "latest"}`,
170
+ });
171
+ }
172
+ }
173
+ }
174
+ catch {
175
+ // pip-audit not available
176
+ }
177
+ return { totalDeps, findings, licenseSummary: {}, outdatedCount: 0, deprecatedCount: 0, vulnerabilityCount };
178
+ }
179
+ function analyzeRustProject(projectPath) {
180
+ const findings = [];
181
+ let totalDeps = 0;
182
+ let vulnerabilityCount = 0;
183
+ try {
184
+ const cargoLock = readFileSync(join(projectPath, "Cargo.lock"), "utf-8");
185
+ totalDeps = (cargoLock.match(/^name = /gm) || []).length;
186
+ }
187
+ catch {
188
+ // no lock file
189
+ }
190
+ try {
191
+ const cargoAudit = execSync("cargo audit --json 2>/dev/null", {
192
+ cwd: projectPath,
193
+ encoding: "utf-8",
194
+ timeout: 30000,
195
+ stdio: ["pipe", "pipe", "pipe"],
196
+ });
197
+ if (cargoAudit.trim()) {
198
+ const audit = JSON.parse(cargoAudit);
199
+ for (const vuln of audit.vulnerabilities || []) {
200
+ vulnerabilityCount++;
201
+ findings.push({
202
+ package: vuln.name || "unknown",
203
+ version: vuln.version || "unknown",
204
+ severity: "high",
205
+ type: "vulnerability",
206
+ description: `Rust advisory: ${vuln.advisory?.title || "Security vulnerability"}`,
207
+ recommendation: `Update ${vuln.name} to latest version.`,
208
+ });
209
+ }
210
+ }
211
+ }
212
+ catch {
213
+ // cargo audit not installed
214
+ }
215
+ return { totalDeps, findings, licenseSummary: {}, outdatedCount: 0, deprecatedCount: 0, vulnerabilityCount };
216
+ }
217
+ function analyzeGoProject(projectPath) {
218
+ const findings = [];
219
+ let totalDeps = 0;
220
+ let vulnerabilityCount = 0;
221
+ try {
222
+ const goList = execSync("go list -m all 2>/dev/null", {
223
+ cwd: projectPath,
224
+ encoding: "utf-8",
225
+ timeout: 30000,
226
+ stdio: ["pipe", "pipe", "pipe"],
227
+ });
228
+ totalDeps = goList.trim().split("\n").length - 1; // minus the main module
229
+ }
230
+ catch {
231
+ // go not available
232
+ }
233
+ try {
234
+ const govuln = execSync("govulncheck ./... 2>/dev/null", {
235
+ cwd: projectPath,
236
+ encoding: "utf-8",
237
+ timeout: 30000,
238
+ stdio: ["pipe", "pipe", "pipe"],
239
+ });
240
+ const vulnLines = govuln.split("\n").filter((l) => l.includes("Vulnerability"));
241
+ vulnerabilityCount = vulnLines.length;
242
+ for (const line of vulnLines) {
243
+ findings.push({
244
+ package: "unknown",
245
+ version: "unknown",
246
+ severity: "high",
247
+ type: "vulnerability",
248
+ description: `Go vulnerability: ${line.trim()}`,
249
+ recommendation: "Update affected modules to latest versions.",
250
+ });
251
+ }
252
+ }
253
+ catch {
254
+ // govulncheck not installed
255
+ }
256
+ return { totalDeps, findings, licenseSummary: {}, outdatedCount: 0, deprecatedCount: 0, vulnerabilityCount };
257
+ }
258
+ const DEPRECATED_PACKAGES = new Set([
259
+ "request",
260
+ "node-uuid",
261
+ "bcrypt-nodejs",
262
+ "gulp-util",
263
+ "bower",
264
+ "phantomjs",
265
+ "gulp-babel",
266
+ "npmconf",
267
+ "rimraf",
268
+ "left-pad",
269
+ "core-js@2",
270
+ "moment",
271
+ "jquery",
272
+ "lodash",
273
+ ]);
274
+ function isDeprecatedNodePackage(name) {
275
+ return DEPRECATED_PACKAGES.has(name);
276
+ }
277
+ function getDeprecatedRecommendation(name) {
278
+ const alternatives = {
279
+ "request": "Use node-fetch, axios, or undici instead.",
280
+ "node-uuid": "Use the uuid package instead.",
281
+ "bcrypt-nodejs": "Use bcrypt or argon2 instead.",
282
+ "bower": "Use npm or yarn instead.",
283
+ "phantomjs": "Use puppeteer or playwright instead.",
284
+ "moment": "Use date-fns, dayjs, or luxon instead.",
285
+ "jquery": "Use modern DOM APIs or a framework (React, Vue, Svelte).",
286
+ "lodash": "Use native JavaScript methods or single-purpose packages.",
287
+ "left-pad": "Use String.prototype.padStart().",
288
+ "rimraf": "Use fs.rm() (Node.js 14+) instead.",
289
+ };
290
+ return alternatives[name] || "Find a maintained alternative on npm.";
291
+ }
292
+ const COPYLEFT_PACKAGES = new Set([
293
+ "ghost",
294
+ "ffmpeg-static",
295
+ ]);
296
+ function hasCopyleftLicense(name) {
297
+ return COPYLEFT_PACKAGES.has(name);
298
+ }
299
+ export function formatDependencyReport(report) {
300
+ const lines = [
301
+ "",
302
+ " Dependency Analysis",
303
+ " --------------------",
304
+ ` Total dependencies: ${report.totalDeps}`,
305
+ ` Vulnerabilities: ${report.vulnerabilityCount}`,
306
+ ` Outdated: ${report.outdatedCount}`,
307
+ ` Deprecated: ${report.deprecatedCount}`,
308
+ ];
309
+ if (Object.keys(report.licenseSummary).length > 0) {
310
+ lines.push(" Licenses:");
311
+ for (const [license, count] of Object.entries(report.licenseSummary)) {
312
+ lines.push(` ${license}: ${count}`);
313
+ }
314
+ }
315
+ if (report.findings.length > 0) {
316
+ const critical = report.findings.filter((f) => f.severity === "critical");
317
+ const high = report.findings.filter((f) => f.severity === "high");
318
+ const medium = report.findings.filter((f) => f.severity === "medium");
319
+ const low = report.findings.filter((f) => f.severity === "low");
320
+ lines.push("");
321
+ lines.push(` Findings: ${report.findings.length} total (${critical.length} critical, ${high.length} high, ${medium.length} medium, ${low.length} low)`);
322
+ lines.push("");
323
+ const shown = [...critical, ...high, ...medium].slice(0, 20);
324
+ for (const f of shown) {
325
+ const sev = f.severity.toUpperCase().padEnd(8);
326
+ const type = f.type.toUpperCase().padEnd(12);
327
+ lines.push(` [${sev}] [${type}] ${f.package}@${f.version}`);
328
+ lines.push(` ${f.description}`);
329
+ lines.push(` Fix: ${f.recommendation}`);
330
+ lines.push("");
331
+ }
332
+ const remaining = report.findings.length - shown.length;
333
+ if (remaining > 0) {
334
+ lines.push(` ... and ${remaining} more findings`);
335
+ }
336
+ }
337
+ else {
338
+ lines.push(" No dependency issues found.");
339
+ }
340
+ lines.push("");
341
+ return lines.join("\n");
342
+ }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export { analyzeDependencies, formatDependencyReport } from "./dependency-analysis.js";
2
+ export type { DependencyFinding, DependencyReport } from "./dependency-analysis.js";
1
3
  export interface ScanResult {
2
4
  scanner: string;
3
5
  status: "pass" | "fail" | "error" | "not-available";
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { execSync } from "node:child_process";
2
2
  import { existsSync } from "node:fs";
3
+ export { analyzeDependencies, formatDependencyReport } from "./dependency-analysis.js";
3
4
  const NODE_PM_MARKERS = [
4
5
  { file: "pnpm-lock.yaml", pm: "pnpm" },
5
6
  { file: "yarn.lock", pm: "yarn" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greenarmor/ges-scanner-integration",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
5
  "description": "GESF Scanner Integration - Trivy, Gitleaks, Semgrep, npm audit",
6
6
  "main": "./dist/index.js",
@@ -11,16 +11,17 @@
11
11
  "default": "./dist/index.js"
12
12
  }
13
13
  },
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "clean": "rm -rf dist tsconfig.tsbuildinfo",
17
+ "test": "vitest run"
18
+ },
14
19
  "dependencies": {
15
- "@greenarmor/ges-core": "1.0.1"
20
+ "@greenarmor/ges-core": "1.1.1"
16
21
  },
17
22
  "devDependencies": {
18
23
  "typescript": "^6.0.0",
19
- "@types/node": "^22.0.0"
20
- },
21
- "scripts": {
22
- "build": "tsc",
23
- "clean": "rm -rf dist tsconfig.tsbuildinfo",
24
- "test": "echo \"no tests yet\""
24
+ "@types/node": "^22.0.0",
25
+ "vitest": "^4.1.8"
25
26
  }
26
- }
27
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025–2026 greenarmor
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.