Exploit databaseDownload repository ZIP
GH-9a15c927d1634a2ada1e945e3ec9e01d
jvr2022/cve-2026-40345
Sources for CVE-2026-40345
1 sourcePreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.
Repository files7
jvr2022/cve-2026-40345Revision 0b7a228bcb3e
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
scanner.mjs
Text · 4,686 bytes#!/usr/bin/env node
import fs from "node:fs";
import path from "node:path";
const args = process.argv.slice(2);
const jsonOutput = args.includes("--json");
const input = args.find((arg) => !arg.startsWith("--")) ?? ".";
const root = path.resolve(input);
const ignored = new Set([".git", ".hg", ".svn", "node_modules", "build", "dist", "coverage"]);
const findings = [];
const seen = new Set();
function add(file, source, requested, resolved = null) {
const key = [file, source, requested, resolved].join("\0");
if (seen.has(key)) return;
seen.add(key);
const status = resolved ? versionStatus(resolved) : rangeStatus(requested);
if (status !== "safe") {
findings.push({
file: path.relative(process.cwd(), file) || path.basename(file),
source,
requested: requested ?? null,
resolved,
status
});
}
}
function versionParts(value) {
const match = String(value).match(/(?:^|[^0-9])v?(\d+)\.(\d+)\.(\d+)/);
return match ? match.slice(1).map(Number) : null;
}
function versionStatus(value) {
const parts = versionParts(value);
if (!parts) return "review";
return parts[0] < 8 ? "vulnerable" : "safe";
}
function rangeStatus(value) {
const text = String(value ?? "").trim();
if (!text || /^(latest|next|workspace:|file:|git\+|https?:)/i.test(text)) return "review";
const lowerBoundAtLeastEight = /(?:^|[\s|])(?:>=|>)\s*8(?:\.|$|\s)/.test(text);
if (/<\s*\d+/.test(text) && !lowerBoundAtLeastEight) return "vulnerable";
const majors = [...text.matchAll(/(?:^|[\s|<>=~^@])v?(\d+)(?=\.|$|[\s|])/g)]
.map((match) => Number(match[1]));
if (majors.some((major) => major < 8)) return "vulnerable";
if (majors.length > 0 && majors.every((major) => major >= 8)) return "safe";
return "review";
}
function readJson(file) {
try {
return JSON.parse(fs.readFileSync(file, "utf8"));
} catch {
return null;
}
}
function inspectPackageJson(file) {
const data = readJson(file);
if (!data || typeof data !== "object") return;
for (const section of [
"dependencies",
"devDependencies",
"optionalDependencies",
"peerDependencies"
]) {
const spec = data[section]?.["deepmerge-ts"];
if (spec !== undefined) add(file, section, String(spec));
}
}
function inspectNpmLock(file) {
const data = readJson(file);
if (!data || typeof data !== "object") return;
for (const [location, entry] of Object.entries(data.packages ?? {})) {
if (/node_modules[\\/]deepmerge-ts$/.test(location) && entry?.version) {
add(file, location, null, String(entry.version));
}
}
function visitDependencies(dependencies, parent = "dependencies") {
for (const [name, entry] of Object.entries(dependencies ?? {})) {
const location = `${parent}/${name}`;
if (name === "deepmerge-ts" && entry?.version) {
add(file, location, null, String(entry.version));
}
visitDependencies(entry?.dependencies, location);
}
}
visitDependencies(data.dependencies);
}
function inspectPnpmLock(file) {
let text;
try {
text = fs.readFileSync(file, "utf8");
} catch {
return;
}
const pattern = /(?:^|\n)\s*\/?deepmerge-ts@([^:\s(]+)/g;
for (const match of text.matchAll(pattern)) {
add(file, "pnpm lock", null, match[1]);
}
}
function inspectFile(file) {
const base = path.basename(file);
if (base === "package.json") inspectPackageJson(file);
if (base === "package-lock.json" || base === "npm-shrinkwrap.json") inspectNpmLock(file);
if (base === "pnpm-lock.yaml") inspectPnpmLock(file);
}
function collect(directory) {
let entries;
try {
entries = fs.readdirSync(directory, { withFileTypes: true });
} catch {
return;
}
for (const entry of entries) {
if (entry.isSymbolicLink() || ignored.has(entry.name)) continue;
const file = path.join(directory, entry.name);
if (entry.isDirectory()) collect(file);
else inspectFile(file);
}
}
try {
if (fs.statSync(root).isDirectory()) collect(root);
else inspectFile(root);
} catch {
console.error(`Path not found: ${root}`);
process.exitCode = 2;
}
if (jsonOutput) {
console.log(JSON.stringify({ target: root, findings }, null, 2));
} else if (findings.length === 0) {
console.log("No affected deepmerge-ts version found.");
} else {
console.log(`deepmerge-ts findings: ${findings.length}`);
for (const finding of findings) {
const version = finding.resolved ? `resolved=${finding.resolved}` : `requested=${finding.requested}`;
console.log(`${finding.status.toUpperCase()} ${finding.file} ${finding.source} ${version}`);
}
}
if (findings.some((finding) => finding.status === "vulnerable")) process.exitCode = 1;