@hardkeel/quantum-scan 0.0.0-stage → 0.3.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/CHANGELOG.md +18 -0
- package/LICENSE +202 -0
- package/README.md +161 -2
- package/action.yml +44 -0
- package/dist/badge.js +60 -0
- package/dist/cbom.js +59 -0
- package/dist/cli.js +305 -0
- package/dist/community-rules.js +30 -0
- package/dist/community.js +28 -0
- package/dist/ignore.js +75 -0
- package/dist/infra.js +557 -0
- package/dist/map-activity.js +22 -0
- package/dist/map-areas.js +50 -0
- package/dist/map-cloud-keys.js +108 -0
- package/dist/map-host.js +333 -0
- package/dist/map-network.js +518 -0
- package/dist/map-people.js +77 -0
- package/dist/map-rank.js +48 -0
- package/dist/map-report.js +178 -0
- package/dist/map-run.js +271 -0
- package/dist/map-types.js +16 -0
- package/dist/map-web.js +640 -0
- package/dist/pqc.js +32 -0
- package/dist/report.js +179 -0
- package/dist/rules.js +135 -0
- package/dist/sarif.js +43 -0
- package/dist/scan.js +220 -0
- package/dist/score.js +122 -0
- package/dist/secrets.js +108 -0
- package/dist/share-config.js +111 -0
- package/dist/share.js +114 -0
- package/dist/types.js +2 -0
- package/dist/walk.js +63 -0
- package/package.json +51 -4
package/dist/cli.js
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Hard Keel Quantum Scan, command line.
|
|
3
|
+
// Finds encryption quantum computers will break, weak encryption, exposed infrastructure settings
|
|
4
|
+
// and leaked keys in a folder,
|
|
5
|
+
// and writes an encryption inventory (CycloneDX CBOM) and a migration report.
|
|
6
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { walkFolder } from "./walk.js";
|
|
9
|
+
import { buildCbom } from "./cbom.js";
|
|
10
|
+
import { migrationReportMarkdown, prSummaryLine, shortLabel, sortFindings } from "./report.js";
|
|
11
|
+
import { buildSarif } from "./sarif.js";
|
|
12
|
+
import { scanFiles } from "./scan.js";
|
|
13
|
+
import { badgeSvg } from "./badge.js";
|
|
14
|
+
import { gradeSentence, readinessScore } from "./score.js";
|
|
15
|
+
import { applyIgnore, IGNORE_FILE, parseIgnore } from "./ignore.js";
|
|
16
|
+
import { ActivityLog } from "./map-activity.js";
|
|
17
|
+
import { parseScope, runMap, SCOPE_FILE } from "./map-run.js";
|
|
18
|
+
import { checkProof, parseTarget, proofRecord, publicLookup } from "./map-web.js";
|
|
19
|
+
import { buildPayload, diffRuns, sendPayload } from "./share.js";
|
|
20
|
+
import { folderKey, INDUSTRIES, loadSettings, saveSettings, settingsPath, sharingState, showNoticeIfNeeded, SIZES } from "./share-config.js";
|
|
21
|
+
export const VERSION = "0.3.0";
|
|
22
|
+
const APP_URL = "https://github.com/apps/hard-keel-quantum-scan";
|
|
23
|
+
const HELP = `Hard Keel Quantum Scan ${VERSION}
|
|
24
|
+
|
|
25
|
+
Finds encryption quantum computers will break, weak encryption, exposed settings and
|
|
26
|
+
leaked keys or passwords in your code and infrastructure config (Terraform, CloudFormation,
|
|
27
|
+
Kubernetes, Dockerfiles, nginx and Apache). Writes an encryption inventory and a
|
|
28
|
+
migration report.
|
|
29
|
+
|
|
30
|
+
Usage:
|
|
31
|
+
quantum-scan [folder] [options] Scan code and infrastructure config
|
|
32
|
+
quantum-scan map [options] Security map: code, websites, your network and
|
|
33
|
+
equipment, and this machine, asking before each area
|
|
34
|
+
quantum-scan prove <domain> Show the DNS record that proves a domain is yours
|
|
35
|
+
quantum-scan config <setting> Sharing, offline mode, industry and size
|
|
36
|
+
|
|
37
|
+
Options:
|
|
38
|
+
--format <text|json|sarif> What to print (default: text)
|
|
39
|
+
--output <file> Write the --format output to a file instead
|
|
40
|
+
--cbom <file> Write the encryption inventory (CycloneDX 1.6 CBOM)
|
|
41
|
+
--report <file> Write the migration report (Markdown)
|
|
42
|
+
--badge <file> Write a quantum readiness badge (SVG) for your README
|
|
43
|
+
--name <name> Repository name to use in the inventory and report
|
|
44
|
+
--fail-on <list> Exit with 1 on these: secret, weak-now, exposed,
|
|
45
|
+
quantum-vulnerable, or none (default: secret,weak-now,exposed)
|
|
46
|
+
--quiet Leave out the closing line about installing on GitHub
|
|
47
|
+
--offline Send nothing to Hard Keel
|
|
48
|
+
--version Print the version
|
|
49
|
+
--help Print this help
|
|
50
|
+
|
|
51
|
+
Map options:
|
|
52
|
+
--scope <file> Use saved answers (quantum-scan.scope.json) instead of asking
|
|
53
|
+
--out <folder> Where to write the map (default: quantum-scan-map)
|
|
54
|
+
--fail-on broken Exit with 1 when anything is broken now
|
|
55
|
+
|
|
56
|
+
Config:
|
|
57
|
+
quantum-scan config show Current settings
|
|
58
|
+
quantum-scan config show-shared Exactly what the last run sent, or would have sent
|
|
59
|
+
quantum-scan config sharing on|off Anonymized sharing (on by default)
|
|
60
|
+
quantum-scan config offline on|off Send nothing at all, ever
|
|
61
|
+
quantum-scan config industry <name> Optional. ${INDUSTRIES.join(", ")}, or none
|
|
62
|
+
quantum-scan config size <band> Optional. ${SIZES.join(", ")}, or none
|
|
63
|
+
|
|
64
|
+
Sharing: unless you turn it off, each run sends an anonymized summary: rounded counts of
|
|
65
|
+
which checks fired and which encryption types were found. Never code, keys, server
|
|
66
|
+
names, IP addresses or company name. Details: https://hardkeel.com/privacy/
|
|
67
|
+
`;
|
|
68
|
+
function parseArgs(argv) {
|
|
69
|
+
const flags = new Set(["quiet", "help", "version", "offline"]);
|
|
70
|
+
const opts = {};
|
|
71
|
+
const rest = [];
|
|
72
|
+
for (let i = 0; i < argv.length; i++) {
|
|
73
|
+
const a = argv[i];
|
|
74
|
+
if (!a.startsWith("--")) {
|
|
75
|
+
rest.push(a);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const [k, v] = a.slice(2).split("=", 2);
|
|
79
|
+
if (flags.has(k))
|
|
80
|
+
opts[k] = true;
|
|
81
|
+
else if (v !== undefined)
|
|
82
|
+
opts[k] = v;
|
|
83
|
+
else
|
|
84
|
+
opts[k] = argv[++i] ?? "";
|
|
85
|
+
}
|
|
86
|
+
return { opts, dir: rest[0] ?? "." };
|
|
87
|
+
}
|
|
88
|
+
function textReport(findings, filesScanned, quiet, score) {
|
|
89
|
+
const out = [`Hard Keel Quantum Scan · ${filesScanned} file${filesScanned === 1 ? "" : "s"} scanned`, "", gradeSentence(score), ""];
|
|
90
|
+
if (!findings.length) {
|
|
91
|
+
out.push("Nothing found. No leaked keys, weak or quantum-breakable encryption, or exposed settings.");
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
out.push(prSummaryLine(findings).replace("This change adds", "Found"));
|
|
95
|
+
const sorted = sortFindings(findings);
|
|
96
|
+
const section = (title, list, note) => {
|
|
97
|
+
if (!list.length)
|
|
98
|
+
return;
|
|
99
|
+
out.push("", title);
|
|
100
|
+
if (note)
|
|
101
|
+
out.push(` ${note}`);
|
|
102
|
+
for (const f of list)
|
|
103
|
+
out.push(` ${f.file}:${f.line} ${shortLabel(f)}`, ` ${f.fix}`);
|
|
104
|
+
};
|
|
105
|
+
section("Fix now", sorted.filter((f) => f.risk !== "quantum-vulnerable"));
|
|
106
|
+
section("Plan for later", sorted.filter((f) => f.risk === "quantum-vulnerable"), "Safe today, but quantum computers will be able to break these. NIST plans to phase them out between 2030 and 2035.");
|
|
107
|
+
}
|
|
108
|
+
if (!quiet)
|
|
109
|
+
out.push("", `Check every pull request automatically: ${APP_URL}`);
|
|
110
|
+
return out.join("\n");
|
|
111
|
+
}
|
|
112
|
+
export function main(argv) {
|
|
113
|
+
return scanCommand(argv).code;
|
|
114
|
+
}
|
|
115
|
+
/** The folder scan. Returns its exit code and the counts the anonymized summary may use. */
|
|
116
|
+
export function scanCommand(argv) {
|
|
117
|
+
const { opts, dir } = parseArgs(argv);
|
|
118
|
+
if (opts.help) {
|
|
119
|
+
process.stdout.write(HELP);
|
|
120
|
+
return { code: 0 };
|
|
121
|
+
}
|
|
122
|
+
if (opts.version) {
|
|
123
|
+
console.log(VERSION);
|
|
124
|
+
return { code: 0 };
|
|
125
|
+
}
|
|
126
|
+
const str = (k) => (typeof opts[k] === "string" ? opts[k] : undefined);
|
|
127
|
+
let walked;
|
|
128
|
+
try {
|
|
129
|
+
walked = walkFolder(dir);
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
console.error(e instanceof Error ? e.message : String(e));
|
|
133
|
+
return { code: 2 };
|
|
134
|
+
}
|
|
135
|
+
if (walked.unreadable.length) {
|
|
136
|
+
const list = walked.unreadable.slice(0, 5).map((u) => `${u.path} (${u.reason})`).join(", ");
|
|
137
|
+
console.error(`Skipped ${walked.unreadable.length} path${walked.unreadable.length === 1 ? "" : "s"} that couldn't be read: ${list}${walked.unreadable.length > 5 ? ", ..." : ""}`);
|
|
138
|
+
}
|
|
139
|
+
const scanned = scanFiles(walked.files);
|
|
140
|
+
const { filesScanned, pqc } = scanned;
|
|
141
|
+
const ignorePath = join(dir, IGNORE_FILE);
|
|
142
|
+
const { kept: findings, ignored } = applyIgnore(scanned.findings, existsSync(ignorePath) ? parseIgnore(readFileSync(ignorePath, "utf8")) : []);
|
|
143
|
+
const score = readinessScore(findings, pqc);
|
|
144
|
+
const repo = str("name") ?? dir;
|
|
145
|
+
const badgePath = str("badge");
|
|
146
|
+
if (badgePath)
|
|
147
|
+
writeFileSync(badgePath, badgeSvg(score) + "\n");
|
|
148
|
+
const cbomPath = str("cbom");
|
|
149
|
+
if (cbomPath)
|
|
150
|
+
writeFileSync(cbomPath, JSON.stringify(buildCbom(findings, { repo, toolVersion: VERSION }), null, 2) + "\n");
|
|
151
|
+
const reportPath = str("report");
|
|
152
|
+
if (reportPath)
|
|
153
|
+
writeFileSync(reportPath, migrationReportMarkdown(repo, findings, new Date().toISOString().slice(0, 10), score) + "\n");
|
|
154
|
+
const format = str("format") ?? "text";
|
|
155
|
+
let body;
|
|
156
|
+
if (format === "json")
|
|
157
|
+
body = JSON.stringify({ tool: "hard-keel-quantum-scan", version: VERSION, filesScanned, score, findings }, null, 2);
|
|
158
|
+
else if (format === "sarif")
|
|
159
|
+
body = JSON.stringify(buildSarif(findings, VERSION), null, 2);
|
|
160
|
+
else if (format === "text")
|
|
161
|
+
body = textReport(findings, filesScanned, opts.quiet === true, score);
|
|
162
|
+
else {
|
|
163
|
+
console.error(`Unknown --format "${format}". Use text, json or sarif.`);
|
|
164
|
+
return { code: 2 };
|
|
165
|
+
}
|
|
166
|
+
const outPath = str("output");
|
|
167
|
+
if (outPath) {
|
|
168
|
+
writeFileSync(outPath, body + "\n");
|
|
169
|
+
console.log(`${filesScanned} files scanned, ${findings.length} finding${findings.length === 1 ? "" : "s"}. Wrote ${outPath}.`);
|
|
170
|
+
}
|
|
171
|
+
else
|
|
172
|
+
console.log(body);
|
|
173
|
+
const failOn = (str("fail-on") ?? "secret,weak-now,exposed").split(",").map((s) => s.trim());
|
|
174
|
+
const code = findings.some((f) => failOn.includes(f.risk)) ? 1 : 0;
|
|
175
|
+
const rules = {};
|
|
176
|
+
const algorithms = {};
|
|
177
|
+
for (const f of findings) {
|
|
178
|
+
rules[f.ruleId] = (rules[f.ruleId] ?? 0) + 1;
|
|
179
|
+
if (f.kind === "secret")
|
|
180
|
+
continue; // what kind of secret is a rule id already; no algorithm entry
|
|
181
|
+
const a = (algorithms[f.algorithm] ??= { count: 0, quantumVulnerable: 0 });
|
|
182
|
+
a.count++;
|
|
183
|
+
if (f.risk === "quantum-vulnerable")
|
|
184
|
+
a.quantumVulnerable++;
|
|
185
|
+
}
|
|
186
|
+
const pqcCounts = {};
|
|
187
|
+
for (const p of pqc)
|
|
188
|
+
pqcCounts[p.algorithm] = (pqcCounts[p.algorithm] ?? 0) + 1;
|
|
189
|
+
const facts = { command: "scan", areas: ["code"], rules, algorithms, quantumSafe: pqcCounts, fixed: {}, ignored, replacements: {}, errors: walked.unreadable.some((u) => u.reason === "permission denied") ? ["permission"] : walked.unreadable.length ? ["read"] : [] };
|
|
190
|
+
return { code, facts, stateKey: folderKey(dir), state: { rules, pqc: pqcCounts } };
|
|
191
|
+
}
|
|
192
|
+
/** Records this run, works out what was fixed since the last one, and sends the summary unless sharing is off. */
|
|
193
|
+
async function finishRun(facts, stateKey, state, s, sharing, send) {
|
|
194
|
+
if (!facts || !stateKey || !state)
|
|
195
|
+
return;
|
|
196
|
+
const key = stateKey.startsWith("map:") ? folderKey(stateKey) : stateKey;
|
|
197
|
+
const diff = diffRuns(s.state[key], state);
|
|
198
|
+
facts.fixed = diff.fixed;
|
|
199
|
+
facts.replacements = diff.replacements;
|
|
200
|
+
s.state[key] = state;
|
|
201
|
+
const payload = buildPayload(facts, s, VERSION);
|
|
202
|
+
s.lastShared = sharing === "on" ? payload : { notSent: sharing, wouldHaveSent: payload };
|
|
203
|
+
// The notice comes before the first summary is sent, and only on runs that send one.
|
|
204
|
+
showNoticeIfNeeded(s, sharing);
|
|
205
|
+
saveSettings(s);
|
|
206
|
+
if (sharing === "on")
|
|
207
|
+
await send(payload);
|
|
208
|
+
}
|
|
209
|
+
function configCommand(args, s) {
|
|
210
|
+
const [what, value] = args;
|
|
211
|
+
const onOff = (v) => (v === "on" || v === "off" ? v : null);
|
|
212
|
+
if (!what || what === "show") {
|
|
213
|
+
console.log([
|
|
214
|
+
`Settings file: ${settingsPath()}`,
|
|
215
|
+
`Sharing: ${s.sharing}${sharingState(s, {}) !== s.sharing ? ` (overridden here: ${sharingState(s, {})})` : ""}`,
|
|
216
|
+
`Offline mode: ${s.offline ? "on" : "off"}`,
|
|
217
|
+
`Industry: ${s.industry ?? "not set"}`,
|
|
218
|
+
`Size: ${s.size ?? "not set"}`,
|
|
219
|
+
`Random ID: ${s.id} (linked to nothing; quote it to ask us to delete your data)`,
|
|
220
|
+
].join("\n"));
|
|
221
|
+
return 0;
|
|
222
|
+
}
|
|
223
|
+
if (what === "show-shared") {
|
|
224
|
+
console.log(s.lastShared ? JSON.stringify(s.lastShared, null, 2) : "Nothing yet. Run a scan first.");
|
|
225
|
+
return 0;
|
|
226
|
+
}
|
|
227
|
+
if (what === "sharing" && onOff(value))
|
|
228
|
+
s.sharing = onOff(value);
|
|
229
|
+
else if (what === "offline" && onOff(value))
|
|
230
|
+
s.offline = value === "on";
|
|
231
|
+
else if (what === "industry" && value && (value === "none" || INDUSTRIES.includes(value)))
|
|
232
|
+
s.industry = value === "none" ? undefined : value;
|
|
233
|
+
else if (what === "size" && value && (value === "none" || SIZES.includes(value)))
|
|
234
|
+
s.size = value === "none" ? undefined : value;
|
|
235
|
+
else {
|
|
236
|
+
console.error("Unknown setting. Run quantum-scan --help for the list.");
|
|
237
|
+
return 2;
|
|
238
|
+
}
|
|
239
|
+
s.profileAsked = true;
|
|
240
|
+
saveSettings(s);
|
|
241
|
+
console.log(`Saved: ${what} ${value}.`);
|
|
242
|
+
return 0;
|
|
243
|
+
}
|
|
244
|
+
async function proveCommand(domain, s) {
|
|
245
|
+
const p = domain ? parseTarget(domain) : { error: "missing domain" };
|
|
246
|
+
if ("error" in p) {
|
|
247
|
+
console.error("Usage: quantum-scan prove <domain>, for example quantum-scan prove example.com");
|
|
248
|
+
return 2;
|
|
249
|
+
}
|
|
250
|
+
const scope = existsSync(SCOPE_FILE) ? parseScope(readFileSync(SCOPE_FILE, "utf8")) : null;
|
|
251
|
+
const token = scope && !("error" in scope) && scope.ownershipToken ? scope.ownershipToken : s.ownershipToken;
|
|
252
|
+
const r = proofRecord(p.host, token);
|
|
253
|
+
console.log(`To prove you own ${p.host}, add this DNS record:\n\n Name: ${r.name}\n Type: TXT\n Value: ${r.value}\n\nIt covers ${p.host} and everything under it. It only allows look-only checks from this machine${scope && !("error" in scope) && scope.ownershipToken ? " and anyone using this scope file" : ""}.`);
|
|
254
|
+
const r2 = await checkProof(p.host, token, new ActivityLog(), undefined, publicLookup());
|
|
255
|
+
if (r2.status === "found")
|
|
256
|
+
console.log(`\nFound it. ${p.host} is proved.`);
|
|
257
|
+
else if (r2.status === "missing")
|
|
258
|
+
console.log("\nNot found yet. DNS changes can take a few minutes; run this again to check.");
|
|
259
|
+
else
|
|
260
|
+
console.log(`\nCouldn't check: ${r2.detail}. Check this machine's DNS settings, then run this again.`);
|
|
261
|
+
return r2.status === "found" ? 0 : 1;
|
|
262
|
+
}
|
|
263
|
+
/** Entry point: subcommands, the first-run notice and the anonymized summary. */
|
|
264
|
+
export async function run(argv, deps = {}) {
|
|
265
|
+
const send = deps.send ?? ((p) => sendPayload(p));
|
|
266
|
+
const s = loadSettings();
|
|
267
|
+
const [cmd, ...rest] = argv;
|
|
268
|
+
if (cmd === "config")
|
|
269
|
+
return configCommand(rest, s);
|
|
270
|
+
if (cmd === "prove")
|
|
271
|
+
return proveCommand(rest[0], s);
|
|
272
|
+
const offline = argv.includes("--offline");
|
|
273
|
+
const sharing = sharingState(s, { offline });
|
|
274
|
+
if (cmd === "map") {
|
|
275
|
+
const { opts } = parseArgs(rest);
|
|
276
|
+
const str = (k) => (typeof opts[k] === "string" ? opts[k] : undefined);
|
|
277
|
+
if (opts.help) {
|
|
278
|
+
process.stdout.write(HELP);
|
|
279
|
+
return 0;
|
|
280
|
+
}
|
|
281
|
+
const out = await runMap({
|
|
282
|
+
scopePath: str("scope"),
|
|
283
|
+
outDir: str("out") ?? "quantum-scan-map",
|
|
284
|
+
cwd: process.cwd(),
|
|
285
|
+
version: VERSION,
|
|
286
|
+
settings: s,
|
|
287
|
+
sharingOn: sharing === "on",
|
|
288
|
+
interactive: deps.interactive ?? Boolean(process.stdin.isTTY),
|
|
289
|
+
});
|
|
290
|
+
await finishRun(out.facts, out.stateKey, out.state, s, sharing, send);
|
|
291
|
+
if (str("fail-on") === "broken" && out.report && out.report.counts[1] > 0)
|
|
292
|
+
return 1;
|
|
293
|
+
return out.code;
|
|
294
|
+
}
|
|
295
|
+
const r = scanCommand(argv);
|
|
296
|
+
await finishRun(r.facts, r.stateKey, r.state, s, sharing, send);
|
|
297
|
+
return r.code;
|
|
298
|
+
}
|
|
299
|
+
const invoked = process.argv[1] ?? "";
|
|
300
|
+
if (/cli\.(ts|js)$/.test(invoked) || invoked.endsWith("quantum-scan")) {
|
|
301
|
+
run(process.argv.slice(2)).then((code) => (process.exitCode = code), (e) => {
|
|
302
|
+
console.error(e instanceof Error ? e.message : e);
|
|
303
|
+
process.exitCode = 2;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Generated by scripts/build-rules.mjs from rules/community/*.json. Do not edit by hand.
|
|
2
|
+
export const COMMUNITY_RULES = [
|
|
3
|
+
{ "id": "c-openssl-3des", "title": "3DES with OpenSSL in C or C++", "extensions": [".c", ".cc", ".cpp", ".cxx", ".h", ".hpp"], "pattern": "\\bEVP_des_ede3?_\\w+\\s*\\(", "algorithm": "3DES" },
|
|
4
|
+
{ "id": "c-openssl-ec", "title": "Elliptic-curve keys with OpenSSL in C or C++", "extensions": [".c", ".cc", ".cpp", ".cxx", ".h", ".hpp"], "pattern": "\\bEC_KEY_new_by_curve_name\\s*\\(|\\bEVP_PKEY_EC\\b|\\bEVP_EC_gen\\s*\\(", "algorithm": "EC" },
|
|
5
|
+
{ "id": "c-openssl-ecb", "title": "AES in ECB mode with OpenSSL in C or C++", "extensions": [".c", ".cc", ".cpp", ".cxx", ".h", ".hpp"], "pattern": "\\bEVP_aes_\\d+_ecb\\s*\\(", "algorithm": "ECB mode" },
|
|
6
|
+
{ "id": "c-openssl-rsa", "title": "RSA with OpenSSL in C or C++", "extensions": [".c", ".cc", ".cpp", ".cxx", ".h", ".hpp"], "pattern": "\\bRSA_generate_key(?:_ex)?\\s*\\(|\\bEVP_PKEY_RSA\\b|\\bEVP_RSA_gen\\s*\\(", "algorithm": "RSA", "keySize": "(?:RSA_generate_key(?:_ex)?\\s*\\([^,]+,|EVP_RSA_gen\\s*\\()\\s*(\\d{3,5})" },
|
|
7
|
+
{ "id": "c-openssl-weak-hash", "title": "MD5 or SHA-1 with OpenSSL in C or C++", "extensions": [".c", ".cc", ".cpp", ".cxx", ".h", ".hpp"], "pattern": "\\bEVP_(md5|sha1)\\s*\\(\\s*\\)|\\b(MD5|SHA1)_Init\\s*\\(", "algorithm": { "groups": [1, 2], "map": { "md5": "MD5", "sha1": "SHA-1" } } },
|
|
8
|
+
{ "id": "cs-ecb", "title": "ECB mode in .NET", "extensions": [".cs"], "pattern": "\\bCipherMode\\.ECB\\b", "algorithm": "ECB mode" },
|
|
9
|
+
{ "id": "cs-ecdh", "title": "ECDH key exchange in .NET", "extensions": [".cs"], "pattern": "\\bECDiffieHellman\\.Create\\s*\\(|\\bnew\\s+ECDiffieHellmanCng\\s*\\(", "algorithm": "ECDH" },
|
|
10
|
+
{ "id": "cs-ecdsa", "title": "ECDSA in .NET", "extensions": [".cs"], "pattern": "\\bECDsa\\.Create\\s*\\(|\\bnew\\s+ECDsaCng\\s*\\(", "algorithm": "ECDSA" },
|
|
11
|
+
{ "id": "cs-rsa", "title": "RSA keys in .NET", "extensions": [".cs"], "pattern": "\\bRSA\\.Create\\s*\\(|\\bnew\\s+RSACryptoServiceProvider\\s*\\(", "algorithm": "RSA", "keySize": "(?:RSA\\.Create|RSACryptoServiceProvider)\\s*\\(\\s*(\\d{3,5})" },
|
|
12
|
+
{ "id": "cs-weak-cipher", "title": "DES or 3DES in .NET", "extensions": [".cs"], "pattern": "\\b(DES|TripleDES)\\.Create\\s*\\(", "algorithm": { "groups": [1], "map": { "des": "DES", "tripledes": "3DES" } } },
|
|
13
|
+
{ "id": "cs-weak-hash", "title": "MD5 or SHA-1 in .NET", "extensions": [".cs"], "pattern": "\\b(MD5|SHA1)\\.(?:Create|HashData)\\s*\\(|\\bnew\\s+(MD5|SHA1)(?:CryptoServiceProvider|Managed)\\s*\\(", "algorithm": { "groups": [1, 2], "map": { "md5": "MD5", "sha1": "SHA-1" } } },
|
|
14
|
+
{ "id": "php-openssl-ec", "title": "Elliptic-curve keys with PHP's OpenSSL extension", "extensions": [".php"], "pattern": "\\bOPENSSL_KEYTYPE_EC\\b", "algorithm": "ECDSA" },
|
|
15
|
+
{ "id": "php-openssl-rsa", "title": "RSA keys with PHP's OpenSSL extension", "extensions": [".php"], "pattern": "\\bOPENSSL_KEYTYPE_RSA\\b", "algorithm": "RSA", "keySize": "private_key_bits['\\\"]?\\s*=>\\s*(\\d{3,5})" },
|
|
16
|
+
{ "id": "php-weak-hash", "title": "MD5 or SHA-1 of a variable in PHP", "extensions": [".php"], "pattern": "\\b(md5|sha1)\\s*\\(\\s*\\$|\\bhash\\s*\\(\\s*['\\\"](md5|sha1)['\\\"]", "algorithm": { "groups": [1, 2], "map": { "md5": "MD5", "sha1": "SHA-1" } } },
|
|
17
|
+
{ "id": "rb-openssl-ec", "title": "Elliptic-curve keys with Ruby's OpenSSL", "extensions": [".rb"], "pattern": "\\bOpenSSL::PKey::EC\\.(?:new|generate)\\b", "algorithm": "ECDSA" },
|
|
18
|
+
{ "id": "rb-openssl-rsa", "title": "RSA keys with Ruby's OpenSSL", "extensions": [".rb"], "pattern": "\\bOpenSSL::PKey::RSA\\.(?:new|generate)\\b", "algorithm": "RSA", "keySize": "RSA\\.(?:new|generate)\\s*\\(\\s*(\\d{3,5})" },
|
|
19
|
+
{ "id": "rb-weak-hash", "title": "MD5 or SHA-1 in Ruby", "extensions": [".rb"], "pattern": "\\bDigest::(MD5|SHA1)\\b", "algorithm": { "groups": [1], "map": { "md5": "MD5", "sha1": "SHA-1" } } },
|
|
20
|
+
{ "id": "rust-ed25519-dalek", "title": "Ed25519 signatures with ed25519-dalek", "extensions": [".rs"], "pattern": "\\bed25519_dalek::", "algorithm": "Ed25519" },
|
|
21
|
+
{ "id": "rust-ring-ecdsa", "title": "ECDSA signing keys with ring", "extensions": [".rs"], "pattern": "\\bEcdsaKeyPair::(?:generate_pkcs8|from_pkcs8)\\s*\\(", "algorithm": "ECDSA" },
|
|
22
|
+
{ "id": "rust-ring-ed25519", "title": "Ed25519 signing keys with ring", "extensions": [".rs"], "pattern": "\\bEd25519KeyPair::(?:generate_pkcs8|from_pkcs8)\\s*\\(", "algorithm": "Ed25519" },
|
|
23
|
+
{ "id": "rust-rsa-crate", "title": "RSA key generation with the rsa crate", "extensions": [".rs"], "pattern": "\\bRsaPrivateKey::new\\s*\\(", "algorithm": "RSA", "keySize": "RsaPrivateKey::new\\s*\\([^,]+,\\s*(\\d{3,5})" },
|
|
24
|
+
{ "id": "rust-weak-hash", "title": "MD5 or SHA-1 hashing in Rust", "extensions": [".rs"], "pattern": "\\b(Md5|Sha1)::(?:new|digest)\\s*\\(|\\b(md5)::compute\\s*\\(", "algorithm": { "groups": [1, 2], "map": { "md5": "MD5", "sha1": "SHA-1" } } },
|
|
25
|
+
{ "id": "rust-x25519-dalek", "title": "X25519 key exchange with x25519-dalek", "extensions": [".rs"], "pattern": "\\bx25519_dalek::", "algorithm": "X25519" },
|
|
26
|
+
{ "id": "swift-cryptokit-25519", "title": "Curve25519 with CryptoKit", "extensions": [".swift"], "pattern": "\\bCurve25519\\.(Signing|KeyAgreement)\\b", "algorithm": { "groups": [1], "map": { "signing": "Ed25519", "keyagreement": "X25519" } } },
|
|
27
|
+
{ "id": "swift-cryptokit-nist", "title": "P-256, P-384 or P-521 with CryptoKit", "extensions": [".swift"], "pattern": "\\bP(?:256|384|521)\\.(Signing|KeyAgreement)\\b", "algorithm": { "groups": [1], "map": { "signing": "ECDSA", "keyagreement": "ECDH" } } },
|
|
28
|
+
{ "id": "swift-insecure-hash", "title": "MD5 or SHA-1 with CryptoKit", "extensions": [".swift"], "pattern": "\\bInsecure\\.(MD5|SHA1)\\b", "algorithm": { "groups": [1], "map": { "md5": "MD5", "sha1": "SHA-1" } } },
|
|
29
|
+
{ "id": "swift-seckey-rsa", "title": "RSA keys with Apple's Security framework", "extensions": [".swift"], "pattern": "\\bkSecAttrKeyTypeRSA\\b", "algorithm": "RSA", "keySize": "kSecAttrKeySizeInBits[^:]*:\\s*(\\d{3,5})" },
|
|
30
|
+
];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Community detection rules: plain JSON files in rules/community/, checked and bundled into
|
|
2
|
+
// src/community-rules.ts by scripts/build-rules.mjs. Contributors never touch TypeScript.
|
|
3
|
+
import { COMMUNITY_RULES } from "./community-rules.js";
|
|
4
|
+
export function compileRule(spec) {
|
|
5
|
+
const a = spec.algorithm;
|
|
6
|
+
return {
|
|
7
|
+
id: spec.id,
|
|
8
|
+
langs: ["any"],
|
|
9
|
+
extensions: spec.extensions.map((e) => e.toLowerCase()),
|
|
10
|
+
pattern: new RegExp(spec.pattern, spec.flags ?? ""),
|
|
11
|
+
keySize: spec.keySize ? new RegExp(spec.keySize) : undefined,
|
|
12
|
+
algorithm: typeof a === "string"
|
|
13
|
+
? a
|
|
14
|
+
: (m) => {
|
|
15
|
+
for (const g of a.groups)
|
|
16
|
+
if (m[g] !== undefined)
|
|
17
|
+
return a.map[m[g].toLowerCase()] ?? null;
|
|
18
|
+
return null;
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const COMPILED = COMMUNITY_RULES.map(compileRule);
|
|
23
|
+
/** Community rules that apply to this file, by extension. */
|
|
24
|
+
export function communityRulesFor(path) {
|
|
25
|
+
const p = path.toLowerCase();
|
|
26
|
+
return COMPILED.filter((r) => r.extensions.some((e) => p.endsWith(e)));
|
|
27
|
+
}
|
|
28
|
+
export const COMMUNITY_RULE_COUNT = COMPILED.length;
|
package/dist/ignore.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// .quantum-scan-ignore: findings a team has looked at and marked not an issue.
|
|
2
|
+
//
|
|
3
|
+
// # comments start with #
|
|
4
|
+
// rule:py-weak-hash a rule, everywhere
|
|
5
|
+
// legacy/ every finding under a folder
|
|
6
|
+
// src/old.py every finding in one file
|
|
7
|
+
// src/old.py:py-weak-hash one rule in one file
|
|
8
|
+
// example.com:443:web-tls-static-rsa a known leftover on a website (quantum-scan map)
|
|
9
|
+
// example.com every finding on a website, any port (quantum-scan map)
|
|
10
|
+
//
|
|
11
|
+
// Windows-style paths (legacy\old.py) work too.
|
|
12
|
+
// Leaked keys and passwords can't be ignored by rule, only by file, so one line can't hide every secret.
|
|
13
|
+
export const IGNORE_FILE = ".quantum-scan-ignore";
|
|
14
|
+
export function parseIgnore(text) {
|
|
15
|
+
const out = [];
|
|
16
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
17
|
+
const line = raw.replace(/\s+#.*$/, "").trim();
|
|
18
|
+
if (!line || line.startsWith("#"))
|
|
19
|
+
continue;
|
|
20
|
+
if (line.startsWith("rule:")) {
|
|
21
|
+
const rule = line.slice(5).trim();
|
|
22
|
+
if (rule)
|
|
23
|
+
out.push({ rule });
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const norm = (p) => p.split("\\").join("/").replace(/^\.\//, "");
|
|
27
|
+
// A rule id always has a letter, so "example.com:443" stays a place, not a rule called 443.
|
|
28
|
+
const m = line.match(/^(.+?):([a-z0-9-]*[a-z][a-z0-9-]*)$/);
|
|
29
|
+
if (m && !/^[a-zA-Z]$/.test(m[1]))
|
|
30
|
+
out.push({ path: norm(m[1]), rule: m[2] });
|
|
31
|
+
else
|
|
32
|
+
out.push({ path: norm(line) });
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
function pathMatches(entry, file) {
|
|
37
|
+
if (entry.endsWith("/"))
|
|
38
|
+
return file.startsWith(entry);
|
|
39
|
+
// "example.com" covers "example.com:443"; "src/a.py" covers "src/a.py:12" in the encryption map.
|
|
40
|
+
return file === entry || file.startsWith(`${entry}/`) || file.startsWith(`${entry}:`);
|
|
41
|
+
}
|
|
42
|
+
/** The same matching, for encryption map findings (websites, this machine), where the place is a target. */
|
|
43
|
+
export function applyIgnoreTargets(findings, entries) {
|
|
44
|
+
const kept = [];
|
|
45
|
+
const accepted = [];
|
|
46
|
+
for (const f of findings) {
|
|
47
|
+
const hit = entries.some((e) => {
|
|
48
|
+
if (e.rule && e.path)
|
|
49
|
+
return e.rule === f.ruleId && pathMatches(e.path, f.target);
|
|
50
|
+
if (e.rule)
|
|
51
|
+
return e.rule === f.ruleId && f.risk !== "secret";
|
|
52
|
+
return e.path ? pathMatches(e.path, f.target) : false;
|
|
53
|
+
});
|
|
54
|
+
(hit ? accepted : kept).push(f);
|
|
55
|
+
}
|
|
56
|
+
return { kept, accepted };
|
|
57
|
+
}
|
|
58
|
+
export function applyIgnore(findings, entries) {
|
|
59
|
+
const kept = [];
|
|
60
|
+
const ignored = {};
|
|
61
|
+
for (const f of findings) {
|
|
62
|
+
const hit = entries.some((e) => {
|
|
63
|
+
if (e.rule && e.path)
|
|
64
|
+
return e.rule === f.ruleId && pathMatches(e.path, f.file);
|
|
65
|
+
if (e.rule)
|
|
66
|
+
return e.rule === f.ruleId && f.kind !== "secret";
|
|
67
|
+
return e.path ? pathMatches(e.path, f.file) : false;
|
|
68
|
+
});
|
|
69
|
+
if (hit)
|
|
70
|
+
ignored[f.ruleId] = (ignored[f.ruleId] ?? 0) + 1;
|
|
71
|
+
else
|
|
72
|
+
kept.push(f);
|
|
73
|
+
}
|
|
74
|
+
return { kept, ignored };
|
|
75
|
+
}
|