cve-lite-cli 1.25.0 → 1.26.0-beta.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.
Files changed (38) hide show
  1. package/README.md +38 -13
  2. package/assets/OWASP_Logo_Black_TM.png +0 -0
  3. package/assets/logo-with-title-removebg-preview.png +0 -0
  4. package/dist/advisory/local-db.js +7 -1
  5. package/dist/advisory/osv-advisory-source.js +2 -1
  6. package/dist/cli/args.js +4 -0
  7. package/dist/cli/help.js +2 -1
  8. package/dist/cli/overrides.js +1 -1
  9. package/dist/cli/validate.js +9 -1
  10. package/dist/index.js +47 -16
  11. package/dist/osv/cache.js +5 -1
  12. package/dist/output/formatters.js +0 -15
  13. package/dist/output/html-reporter.js +11 -12
  14. package/dist/output/logos.js +18 -0
  15. package/dist/output/multi-folder-html-reporter.js +3 -4
  16. package/dist/output/override-findings-html.js +10 -4
  17. package/dist/output/override-findings-terminal.js +90 -21
  18. package/dist/output/printers.js +42 -16
  19. package/dist/parsers/pnpm-lock.js +46 -3
  20. package/dist/remediation/npm-registry.js +55 -73
  21. package/dist/scan/multi-folder-scan.js +13 -3
  22. package/dist/scanner.js +79 -59
  23. package/dist/utils/fix-runner.js +6 -0
  24. package/dist/utils/package-json.js +21 -0
  25. package/dist/utils/severity.js +16 -0
  26. package/dist/utils/validate-url.js +223 -0
  27. package/dist/utils/version.js +20 -2
  28. package/package.json +6 -2
  29. package/dist/learn/keypress.js +0 -50
  30. package/dist/learn/runner.js +0 -96
  31. package/dist/learn/scenario.js +0 -47
  32. package/dist/learn/session.js +0 -36
  33. package/dist/learn/types.js +0 -1
  34. package/dist/llm/client.js +0 -40
  35. package/dist/llm/config.js +0 -48
  36. package/dist/llm/explainer.js +0 -31
  37. package/dist/output/logo-base64.js +0 -1
  38. package/dist/output/owasp-logo-base64.js +0 -1
@@ -1,96 +0,0 @@
1
- import os from "node:os";
2
- import fs from "node:fs";
3
- import path from "node:path";
4
- import { fetchScenarioIndex, fetchScenario } from "./scenario.js";
5
- import { runSession } from "./session.js";
6
- import { loadPackages } from "../parsers/index.js";
7
- import { scanPackages } from "../scanner.js";
8
- import { chalk } from "../utils/chalk.js";
9
- import { waitForKeypress } from "./keypress.js";
10
- import { countBySeverity } from "../utils/severity.js";
11
- function formatFindings(findings) {
12
- const counts = countBySeverity(findings);
13
- const total = findings.length;
14
- const label = total === 1 ? "finding" : "findings";
15
- const parts = [];
16
- if (counts.critical > 0)
17
- parts.push(`${counts.critical} critical`);
18
- if (counts.high > 0)
19
- parts.push(`${counts.high} high`);
20
- if (counts.medium > 0)
21
- parts.push(`${counts.medium} medium`);
22
- if (counts.low > 0)
23
- parts.push(`${counts.low} low`);
24
- return parts.length > 0 ? `${total} ${label} (${parts.join(" · ")})` : `${total} ${label}`;
25
- }
26
- export async function runLearnCommand() {
27
- let index;
28
- try {
29
- index = await fetchScenarioIndex();
30
- }
31
- catch {
32
- console.error("Could not fetch scenario. Check your connection and try again.");
33
- process.exit(1);
34
- return;
35
- }
36
- console.log("\nCVE Lite CLI - Learn Mode\n");
37
- console.log("Available scenarios:");
38
- index.scenarios.forEach((s, i) => {
39
- console.log(` ${i + 1}. ${s.title.padEnd(40)} (${s.difficulty})`);
40
- });
41
- const validKeys = index.scenarios.map((_, i) => String(i + 1));
42
- process.stdout.write(`\nPick a scenario [1-${index.scenarios.length}]: `);
43
- const choice = await waitForKeypress(validKeys);
44
- console.log(choice);
45
- const selected = index.scenarios[Number(choice) - 1];
46
- let scenarioData;
47
- try {
48
- scenarioData = await fetchScenario(selected.id);
49
- }
50
- catch {
51
- console.error("Could not fetch scenario. Check your connection and try again.");
52
- process.exit(1);
53
- return;
54
- }
55
- const { scenario, lockfileContent, fixedLockfileContent } = scenarioData;
56
- const tempDir = path.join(os.tmpdir(), `cve-lite-learn-${selected.id}`);
57
- fs.mkdirSync(tempDir, { recursive: true });
58
- try {
59
- console.log(`\nScenario: ${chalk.bold(scenario.title)}`);
60
- console.log("-".repeat(42));
61
- console.log(scenario.concept);
62
- console.log("\nScanning...");
63
- fs.writeFileSync(path.join(tempDir, "package-lock.json"), lockfileContent, "utf8");
64
- const initialInput = loadPackages(tempDir, false, 4);
65
- const initialFindings = await scanPackages(initialInput.packages, 100, { failOn: "critical", batchSize: "100", json: true });
66
- if (initialFindings.length === 0) {
67
- console.error("Unexpected: no findings. The scenario may be outdated - please update CVE Lite CLI.");
68
- process.exit(1);
69
- return;
70
- }
71
- await runSession(scenario);
72
- console.log("\nIn a real project, you would run:\n");
73
- console.log(` ${chalk.cyan(scenario.fixCommand)}`);
74
- console.log("\nApplying the fix for this scenario...\n");
75
- console.log("Rescanning...\n");
76
- fs.writeFileSync(path.join(tempDir, "package-lock.json"), fixedLockfileContent, "utf8");
77
- const fixedInput = loadPackages(tempDir, false, 4);
78
- const fixedFindings = await scanPackages(fixedInput.packages, 100, { failOn: "critical", batchSize: "100", json: true });
79
- console.log(`Before: ${formatFindings(initialFindings)}`);
80
- console.log(`After: ${formatFindings(fixedFindings)}`);
81
- const beforeCounts = countBySeverity(initialFindings);
82
- const afterCounts = countBySeverity(fixedFindings);
83
- const improved = fixedFindings.length < initialFindings.length ||
84
- (beforeCounts.critical > 0 && afterCounts.critical === 0) ||
85
- (beforeCounts.high > 0 && afterCounts.high === 0);
86
- if (improved || fixedFindings.length === 0) {
87
- console.log(chalk.green(`\n✓ ${scenario.successMessage}`));
88
- }
89
- else {
90
- console.log(chalk.yellow("\nSome findings remain - the fix may be partially applied or the lockfile was not updated."));
91
- }
92
- }
93
- finally {
94
- fs.rmSync(tempDir, { recursive: true, force: true });
95
- }
96
- }
@@ -1,47 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import os from "node:os";
4
- const BASE_URL = process.env["CVE_LITE_LEARN_BASE_URL"] ??
5
- "https://raw.githubusercontent.com/OWASP/cve-lite-cli/main/examples/learn";
6
- const CACHE_TTL_MS = 24 * 60 * 60 * 1000;
7
- function getCacheDir(key) {
8
- return path.join(os.homedir(), ".cache", "cve-lite", "learn", key);
9
- }
10
- async function fetchWithCache(url, cachePath) {
11
- const cacheDir = path.dirname(cachePath);
12
- if (fs.existsSync(cachePath)) {
13
- const { mtimeMs } = fs.statSync(cachePath);
14
- if (Date.now() - mtimeMs < CACHE_TTL_MS) {
15
- return fs.readFileSync(cachePath, "utf8");
16
- }
17
- }
18
- const res = await fetch(url);
19
- if (!res.ok)
20
- throw new Error(`Fetch failed: ${url} (${res.status})`);
21
- const text = await res.text();
22
- fs.mkdirSync(cacheDir, { recursive: true });
23
- fs.writeFileSync(cachePath, text, "utf8");
24
- return text;
25
- }
26
- export async function fetchScenarioIndex() {
27
- const cachePath = path.join(getCacheDir("_index"), "index.json");
28
- const text = await fetchWithCache(`${BASE_URL}/index.json`, cachePath);
29
- const data = JSON.parse(text);
30
- if (!Array.isArray(data?.scenarios)) {
31
- throw new Error("Invalid index.json: missing scenarios array");
32
- }
33
- return data;
34
- }
35
- export async function fetchScenario(id) {
36
- const cacheDir = getCacheDir(id);
37
- const [scenarioText, lockfileContent, fixedLockfileContent] = await Promise.all([
38
- fetchWithCache(`${BASE_URL}/${id}/scenario.json`, path.join(cacheDir, "scenario.json")),
39
- fetchWithCache(`${BASE_URL}/${id}/package-lock.json`, path.join(cacheDir, "package-lock.json")),
40
- fetchWithCache(`${BASE_URL}/${id}/package-lock-fixed.json`, path.join(cacheDir, "package-lock-fixed.json")),
41
- ]);
42
- const scenario = JSON.parse(scenarioText);
43
- if (!scenario.title || !Array.isArray(scenario.steps)) {
44
- throw new Error(`Invalid scenario.json for ${id}`);
45
- }
46
- return { scenario, lockfileContent, fixedLockfileContent };
47
- }
@@ -1,36 +0,0 @@
1
- import { chalk } from "../utils/chalk.js";
2
- import { waitForKeypress, waitForAnyKey } from "./keypress.js";
3
- async function runStep(step, stepNumber, total) {
4
- console.log(`\nFinding ${stepNumber} of ${total}`);
5
- console.log(`Package: ${chalk.bold(step.finding)}`);
6
- console.log(`Severity: ${chalk.red(step.severity.toUpperCase())}`);
7
- if (step.type) {
8
- console.log(`Type: ${step.type} dependency`);
9
- }
10
- console.log(`\n${step.question}`);
11
- step.options.forEach(opt => console.log(` ${opt}`));
12
- const validKeys = step.options.map((_, i) => String.fromCharCode(97 + i));
13
- process.stdout.write(`\nYour answer [a-${String.fromCharCode(96 + step.options.length)}]: `);
14
- const answer = await waitForKeypress(validKeys);
15
- console.log(answer);
16
- const correct = answer === step.correct.toLowerCase();
17
- if (correct) {
18
- console.log(chalk.green(`\n✓ ${step.correct_explanation}`));
19
- }
20
- else {
21
- console.log(chalk.red(`\n✗ ${step.wrong_explanation}`));
22
- }
23
- process.stdout.write("\nPress any key to continue...");
24
- await waitForAnyKey();
25
- console.log();
26
- return correct;
27
- }
28
- export async function runSession(scenario) {
29
- let correct = 0;
30
- for (let i = 0; i < scenario.steps.length; i++) {
31
- if (await runStep(scenario.steps[i], i + 1, scenario.steps.length)) {
32
- correct++;
33
- }
34
- }
35
- return correct;
36
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,40 +0,0 @@
1
- const PROVIDERS = {
2
- claude: {
3
- endpoint: "https://api.anthropic.com/v1/messages",
4
- model: "claude-haiku-4-5-20251001",
5
- },
6
- };
7
- async function doFetch(endpoint, apiKey, body) {
8
- return fetch(endpoint, {
9
- method: "POST",
10
- headers: {
11
- "x-api-key": apiKey,
12
- "anthropic-version": "2023-06-01",
13
- "content-type": "application/json",
14
- },
15
- body,
16
- signal: AbortSignal.timeout(15000),
17
- });
18
- }
19
- export async function callLlm(config, prompt) {
20
- const provider = PROVIDERS[config.provider];
21
- if (!provider) {
22
- throw new Error(`Unsupported LLM provider: "${config.provider}". Supported: ${Object.keys(PROVIDERS).join(", ")}`);
23
- }
24
- const body = JSON.stringify({
25
- model: provider.model,
26
- max_tokens: 200,
27
- messages: [{ role: "user", content: prompt }],
28
- });
29
- let response = await doFetch(provider.endpoint, config.apiKey, body);
30
- if (response.status === 429) {
31
- await new Promise(r => setTimeout(r, 2000));
32
- response = await doFetch(provider.endpoint, config.apiKey, body);
33
- }
34
- if (!response.ok) {
35
- const errText = await response.text();
36
- throw new Error(`LLM API error (${response.status}): ${errText}`);
37
- }
38
- const data = await response.json();
39
- return data.content.find(c => c.type === "text")?.text ?? "";
40
- }
@@ -1,48 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import os from "node:os";
4
- function readConfigFile(filePath) {
5
- try {
6
- return JSON.parse(fs.readFileSync(filePath, "utf8"));
7
- }
8
- catch {
9
- return {};
10
- }
11
- }
12
- export function loadLlmConfig(projectRoot) {
13
- const globalPath = path.join(os.homedir(), ".cve-lite", "config.json");
14
- const projectPath = path.join(projectRoot ?? process.cwd(), ".cve-lite.json");
15
- const globalLlm = readConfigFile(globalPath).llm ?? {};
16
- const projectLlm = readConfigFile(projectPath).llm ?? {};
17
- const merged = {
18
- provider: projectLlm.provider ?? globalLlm.provider ?? "",
19
- providers: { ...(globalLlm.providers ?? {}), ...(projectLlm.providers ?? {}) },
20
- };
21
- if (!merged.provider)
22
- return null;
23
- return merged;
24
- }
25
- export function resolveLlmConfig(projectRoot) {
26
- const config = loadLlmConfig(projectRoot);
27
- if (!config?.provider) {
28
- throw new Error('No LLM provider configured. Create ~/.cve-lite/config.json or .cve-lite.json with an "llm" block.');
29
- }
30
- const providerConfig = config.providers[config.provider];
31
- if (!providerConfig?.apiKey) {
32
- throw new Error(`No API key configured for provider "${config.provider}". Add it under llm.providers.${config.provider}.apiKey.`);
33
- }
34
- return { provider: config.provider, apiKey: providerConfig.apiKey };
35
- }
36
- export function checkGitignore(projectRoot) {
37
- const projectPath = path.join(projectRoot ?? process.cwd(), ".cve-lite.json");
38
- if (!fs.existsSync(projectPath))
39
- return true;
40
- const gitignorePath = path.join(projectRoot ?? process.cwd(), ".gitignore");
41
- try {
42
- const lines = fs.readFileSync(gitignorePath, "utf8").split("\n");
43
- return lines.some((l) => l.trim() === ".cve-lite.json");
44
- }
45
- catch {
46
- return false;
47
- }
48
- }
@@ -1,31 +0,0 @@
1
- import { callLlm } from "./client.js";
2
- import { runWithConcurrency } from "../utils/array.js";
3
- export function buildPrompt(finding) {
4
- const cve = finding.cveAliases[0] ?? finding.vulnerabilities[0]?.id ?? "unknown";
5
- const summary = finding.vulnerabilities[0]?.summary ?? "No summary available";
6
- const fixLine = finding.firstFixedVersion
7
- ? `Fix available: upgrade to ${finding.firstFixedVersion}`
8
- : "No fix is currently available.";
9
- return [
10
- "You are a security advisor helping a developer understand a vulnerability.",
11
- "",
12
- `Package: ${finding.pkg.name}@${finding.pkg.version}`,
13
- `Severity: ${finding.severity}`,
14
- `CVE: ${cve}`,
15
- `Summary: ${summary}`,
16
- fixLine,
17
- "",
18
- "In one short paragraph, explain what this vulnerability does and whether a typical Node.js application using this package is at risk. Be direct and practical.",
19
- ].join("\n");
20
- }
21
- export async function explainFinding(finding, config) {
22
- try {
23
- return await callLlm(config, buildPrompt(finding));
24
- }
25
- catch {
26
- return null;
27
- }
28
- }
29
- export async function explainFindings(findings, config) {
30
- return runWithConcurrency(findings, 3, finding => explainFinding(finding, config));
31
- }