@hardkeel/quantum-scan 0.2.0 → 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.
@@ -1,30 +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
- ];
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
+ ];
package/dist/community.js CHANGED
@@ -1,28 +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;
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 CHANGED
@@ -1,75 +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
- }
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
+ }