@quantakrypto/core 0.2.2 → 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/dist/detect-utils.d.ts +26 -1
- package/dist/detect-utils.d.ts.map +1 -1
- package/dist/detect-utils.js +26 -0
- package/dist/detect-utils.js.map +1 -1
- package/dist/detectors/pem.d.ts +4 -0
- package/dist/detectors/pem.d.ts.map +1 -1
- package/dist/detectors/pem.js +113 -91
- package/dist/detectors/pem.js.map +1 -1
- package/dist/detectors/source.d.ts +9 -2
- package/dist/detectors/source.d.ts.map +1 -1
- package/dist/detectors/source.js +366 -265
- package/dist/detectors/source.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/parallel.d.ts.map +1 -1
- package/dist/parallel.js +2 -0
- package/dist/parallel.js.map +1 -1
- package/dist/registry.d.ts +16 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +31 -0
- package/dist/registry.js.map +1 -1
- package/dist/report.d.ts +9 -1
- package/dist/report.d.ts.map +1 -1
- package/dist/report.js +56 -23
- package/dist/report.js.map +1 -1
- package/dist/scan-worker.js +1 -1
- package/dist/scan-worker.js.map +1 -1
- package/dist/scan.d.ts +1 -1
- package/dist/scan.d.ts.map +1 -1
- package/dist/scan.js +8 -2
- package/dist/scan.js.map +1 -1
- package/dist/types.d.ts +53 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/detect-utils.ts +57 -1
- package/src/detectors/pem.ts +124 -105
- package/src/detectors/source.ts +466 -343
- package/src/index.ts +2 -1
- package/src/parallel.ts +9 -1
- package/src/registry.ts +39 -1
- package/src/report.ts +79 -23
- package/src/scan-worker.ts +12 -5
- package/src/scan.ts +19 -5
- package/src/types.ts +54 -0
- package/src/version.ts +1 -1
package/dist/detect-utils.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* into a 1-based line/column, extracting a trimmed single-line snippet, and a
|
|
4
4
|
* small factory for building Finding objects with consistent remediation text.
|
|
5
5
|
*/
|
|
6
|
-
import type { AlgorithmFamily, Confidence, Finding, FindingCategory, Severity } from "./types.js";
|
|
6
|
+
import type { AlgorithmFamily, Confidence, Finding, FindingCategory, RuleMeta, Severity } from "./types.js";
|
|
7
7
|
/** A 1-based line/column position derived from a character offset. */
|
|
8
8
|
export interface LineCol {
|
|
9
9
|
line: number;
|
|
@@ -46,6 +46,31 @@ export interface FindingSpec {
|
|
|
46
46
|
* remediation text for that family is used.
|
|
47
47
|
*/
|
|
48
48
|
export declare function makeFinding(spec: FindingSpec): Finding;
|
|
49
|
+
/** Where a match occurred, plus optional per-finding field overrides. */
|
|
50
|
+
export interface RuleMatch {
|
|
51
|
+
file: string;
|
|
52
|
+
content: string;
|
|
53
|
+
/** Match start offset within `content`. */
|
|
54
|
+
index: number;
|
|
55
|
+
/** Length of the match (used to compute endLine for multi-line matches). */
|
|
56
|
+
matchLength?: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Fields of a {@link RuleMeta} a detector may refine at match time. Multi-variant
|
|
60
|
+
* rules (e.g. key generation across algorithm families) override these; fixed
|
|
61
|
+
* rules pass none and inherit the catalog metadata verbatim.
|
|
62
|
+
*/
|
|
63
|
+
export type RuleOverrides = Partial<Pick<RuleMeta, "title" | "category" | "severity" | "confidence" | "algorithm" | "hndl" | "message" | "cwe">> & {
|
|
64
|
+
remediation?: string;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Build a {@link Finding} from a rule's catalog metadata plus a match location,
|
|
68
|
+
* applying any per-finding overrides. This is the single construction path for
|
|
69
|
+
* detector findings: the invariant fields (title/severity/category/…) live once
|
|
70
|
+
* in the {@link RuleMeta} declaration, so they can't drift from what the SARIF
|
|
71
|
+
* catalog and the MCP resolver report.
|
|
72
|
+
*/
|
|
73
|
+
export declare function findingFromRule(rule: RuleMeta, at: RuleMatch, overrides?: RuleOverrides): Finding;
|
|
49
74
|
/** True if `filePath` has one of the given (lower-case, dotted) extensions. */
|
|
50
75
|
export declare function hasExtension(filePath: string, exts: readonly string[]): boolean;
|
|
51
76
|
/** JavaScript / TypeScript source extensions handled by the source detectors. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect-utils.d.ts","sourceRoot":"","sources":["../src/detect-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"detect-utils.d.ts","sourceRoot":"","sources":["../src/detect-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EACV,OAAO,EACP,eAAe,EACf,QAAQ,EACR,QAAQ,EACT,MAAM,YAAY,CAAC;AAGpB,sEAAsE;AACtE,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAUxE;AAED,oEAAoE;AACpE,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAM9D;AAED,sCAAsC;AACtC,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,eAAe,CAAC;IAC1B,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0CAA0C;IAC1C,GAAG,CAAC,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AAS,CACvB,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,GACxC,IAAI,CAQN"}
|
package/dist/detect-utils.js
CHANGED
|
@@ -66,6 +66,32 @@ export function makeFinding(spec) {
|
|
|
66
66
|
finding.sensitive = true;
|
|
67
67
|
return finding;
|
|
68
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Build a {@link Finding} from a rule's catalog metadata plus a match location,
|
|
71
|
+
* applying any per-finding overrides. This is the single construction path for
|
|
72
|
+
* detector findings: the invariant fields (title/severity/category/…) live once
|
|
73
|
+
* in the {@link RuleMeta} declaration, so they can't drift from what the SARIF
|
|
74
|
+
* catalog and the MCP resolver report.
|
|
75
|
+
*/
|
|
76
|
+
export function findingFromRule(rule, at, overrides) {
|
|
77
|
+
return makeFinding({
|
|
78
|
+
ruleId: rule.id,
|
|
79
|
+
title: overrides?.title ?? rule.title,
|
|
80
|
+
category: overrides?.category ?? rule.category,
|
|
81
|
+
severity: overrides?.severity ?? rule.severity,
|
|
82
|
+
confidence: overrides?.confidence ?? rule.confidence,
|
|
83
|
+
algorithm: overrides?.algorithm ?? rule.algorithm,
|
|
84
|
+
hndl: overrides?.hndl ?? rule.hndl,
|
|
85
|
+
cwe: overrides?.cwe ?? rule.cwe,
|
|
86
|
+
remediation: overrides?.remediation ?? rule.remediation,
|
|
87
|
+
sensitive: rule.sensitive,
|
|
88
|
+
message: overrides?.message ?? rule.message,
|
|
89
|
+
file: at.file,
|
|
90
|
+
content: at.content,
|
|
91
|
+
index: at.index,
|
|
92
|
+
matchLength: at.matchLength,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
69
95
|
/** True if `filePath` has one of the given (lower-case, dotted) extensions. */
|
|
70
96
|
export function hasExtension(filePath, exts) {
|
|
71
97
|
const lower = filePath.toLowerCase();
|
package/dist/detect-utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect-utils.js","sourceRoot":"","sources":["../src/detect-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"detect-utils.js","sourceRoot":"","sources":["../src/detect-utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAQnD;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,OAAe,EAAE,MAAc;IAC7D,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,WAAW,GAAG,CAAC,CAAC,CAAC;IACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtD,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,CAAC;YAC1C,IAAI,EAAE,CAAC;YACP,WAAW,GAAG,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,EAAE,CAAC;AAChD,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,MAAM,CAAC,OAAe,EAAE,MAAc;IACpD,IAAI,KAAK,GAAG,MAAM,CAAC;IACnB,OAAO,KAAK,GAAG,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,CAAC;IAClE,IAAI,GAAG,GAAG,MAAM,CAAC;IACjB,OAAO,GAAG,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE;QAAE,GAAG,EAAE,CAAC;IACrE,OAAO,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AAC7D,CAAC;AA0BD;;;;GAIG;AAC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;;GAGG;AACH,MAAM,UAAU,SAAS,CACvB,EAAU,EACV,OAAe,EACf,OAAyC;IAEzC,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC;IACjE,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC;IAChB,IAAI,CAAyB,CAAC;IAC9B,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACtC,OAAO,CAAC,CAAC,CAAC,CAAC;QACX,IAAI,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,SAAS;YAAE,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,qCAAqC;IACnF,CAAC;AACH,CAAC"}
|
package/dist/detectors/pem.d.ts
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* Config / certificate detector: finds PEM-encoded cryptographic material in
|
|
3
3
|
* any text file (source, config, .pem, .key, .crt, .env, …). This catches
|
|
4
4
|
* embedded private keys and X.509 certificates regardless of language.
|
|
5
|
+
*
|
|
6
|
+
* Every rule's metadata lives in the {@link RuleMeta} declaration below (the
|
|
7
|
+
* catalog entry); `detect()` builds findings straight from it via
|
|
8
|
+
* `findingFromRule`. All PEM findings are high-confidence exact-marker matches.
|
|
5
9
|
*/
|
|
6
10
|
import type { Detector } from "../types.js";
|
|
7
11
|
/** Detects PEM key/certificate material in arbitrary files. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pem.d.ts","sourceRoot":"","sources":["../../src/detectors/pem.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"pem.d.ts","sourceRoot":"","sources":["../../src/detectors/pem.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;AAwJ/D,+DAA+D;AAC/D,eAAO,MAAM,WAAW,EAAE,QA2BzB,CAAC"}
|
package/dist/detectors/pem.js
CHANGED
|
@@ -1,107 +1,139 @@
|
|
|
1
|
-
import { eachMatch,
|
|
1
|
+
import { eachMatch, findingFromRule } from "../detect-utils.js";
|
|
2
2
|
import { CWE_BROKEN_CRYPTO, CWE_HARDCODED_KEY } from "../cwe.js";
|
|
3
3
|
const PEM_RULES = [
|
|
4
4
|
{
|
|
5
5
|
re: /-----BEGIN RSA PRIVATE KEY-----/g,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
meta: {
|
|
7
|
+
id: "pem-rsa-private-key",
|
|
8
|
+
title: "RSA private key (PEM)",
|
|
9
|
+
description: "PKCS#1 RSA private key block",
|
|
10
|
+
category: "certificate",
|
|
11
|
+
severity: "critical",
|
|
12
|
+
confidence: "high",
|
|
13
|
+
algorithm: "RSA",
|
|
14
|
+
hndl: true,
|
|
15
|
+
cwe: CWE_HARDCODED_KEY,
|
|
16
|
+
sensitive: true,
|
|
17
|
+
message: "Embedded RSA private key (PKCS#1 PEM); classical and not quantum-safe.",
|
|
18
|
+
remediation: "Migrate to ML-DSA / ML-KEM keys and remove embedded private keys from source.",
|
|
19
|
+
},
|
|
16
20
|
},
|
|
17
21
|
{
|
|
18
22
|
re: /-----BEGIN EC PRIVATE KEY-----/g,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
meta: {
|
|
24
|
+
id: "pem-ec-private-key",
|
|
25
|
+
title: "EC private key (PEM)",
|
|
26
|
+
description: "SEC1 EC private key block",
|
|
27
|
+
category: "certificate",
|
|
28
|
+
severity: "critical",
|
|
29
|
+
confidence: "high",
|
|
30
|
+
algorithm: "ECDSA",
|
|
31
|
+
hndl: true,
|
|
32
|
+
cwe: CWE_HARDCODED_KEY,
|
|
33
|
+
sensitive: true,
|
|
34
|
+
message: "Embedded EC private key (SEC1 PEM); classical ECDSA/ECDH key, not quantum-safe.",
|
|
35
|
+
remediation: "Migrate to ML-DSA (FIPS 204) keys and remove embedded private keys from source.",
|
|
36
|
+
},
|
|
29
37
|
},
|
|
30
38
|
{
|
|
31
39
|
re: /-----BEGIN DSA PRIVATE KEY-----/g,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
meta: {
|
|
41
|
+
id: "pem-dsa-private-key",
|
|
42
|
+
title: "DSA private key (PEM)",
|
|
43
|
+
description: "DSA private key block",
|
|
44
|
+
category: "certificate",
|
|
45
|
+
severity: "critical",
|
|
46
|
+
confidence: "high",
|
|
47
|
+
algorithm: "DSA",
|
|
48
|
+
hndl: false,
|
|
49
|
+
cwe: CWE_HARDCODED_KEY,
|
|
50
|
+
sensitive: true,
|
|
51
|
+
message: "Embedded DSA private key (PEM); classical, already deprecated, and not quantum-safe.",
|
|
52
|
+
remediation: "Rotate immediately (DSA is deprecated) and migrate to ML-DSA-65 (FIPS 204).",
|
|
53
|
+
},
|
|
42
54
|
},
|
|
43
55
|
{
|
|
44
56
|
re: /-----BEGIN OPENSSH PRIVATE KEY-----/g,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
meta: {
|
|
58
|
+
id: "pem-openssh-private-key",
|
|
59
|
+
title: "OpenSSH private key",
|
|
60
|
+
description: "OpenSSH private key block",
|
|
61
|
+
category: "certificate",
|
|
62
|
+
severity: "critical",
|
|
63
|
+
confidence: "high",
|
|
64
|
+
algorithm: "unknown",
|
|
65
|
+
hndl: true,
|
|
66
|
+
cwe: CWE_HARDCODED_KEY,
|
|
67
|
+
sensitive: true,
|
|
68
|
+
message: "Embedded OpenSSH private key (RSA/ECDSA/Ed25519); classical and not quantum-safe.",
|
|
69
|
+
remediation: "Rotate the key; plan migration to PQC-capable SSH (e.g. sntrup761x25519).",
|
|
70
|
+
},
|
|
55
71
|
},
|
|
56
72
|
{
|
|
57
73
|
re: /-----BEGIN PGP PRIVATE KEY BLOCK-----/g,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
74
|
+
meta: {
|
|
75
|
+
id: "pem-pgp-private-key",
|
|
76
|
+
title: "PGP/GPG private key block",
|
|
77
|
+
description: "OpenPGP private key block",
|
|
78
|
+
category: "certificate",
|
|
79
|
+
severity: "critical",
|
|
80
|
+
confidence: "high",
|
|
81
|
+
algorithm: "unknown",
|
|
82
|
+
hndl: true,
|
|
83
|
+
cwe: CWE_HARDCODED_KEY,
|
|
84
|
+
sensitive: true,
|
|
85
|
+
message: "Embedded PGP/GPG private key block (RSA/ECDSA/EdDSA/ElGamal); classical and not quantum-safe.",
|
|
86
|
+
remediation: "Rotate the key; track OpenPGP PQC drafts for migration.",
|
|
87
|
+
},
|
|
68
88
|
},
|
|
69
89
|
{
|
|
70
90
|
re: /-----BEGIN PGP MESSAGE-----/g,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
91
|
+
meta: {
|
|
92
|
+
id: "pem-pgp-message",
|
|
93
|
+
title: "PGP/GPG encrypted message",
|
|
94
|
+
description: "OpenPGP encrypted message block",
|
|
95
|
+
category: "certificate",
|
|
96
|
+
severity: "low",
|
|
97
|
+
confidence: "high",
|
|
98
|
+
algorithm: "unknown",
|
|
99
|
+
hndl: true,
|
|
100
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
101
|
+
message: "Embedded PGP/GPG message; likely encrypted with classical RSA/ElGamal (harvest-now-decrypt-later).",
|
|
102
|
+
remediation: "Re-encrypt with PQC-capable tooling as OpenPGP PQC profiles mature.",
|
|
103
|
+
},
|
|
80
104
|
},
|
|
81
105
|
{
|
|
82
106
|
re: /-----BEGIN (?:ENCRYPTED )?PRIVATE KEY-----/g,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
107
|
+
meta: {
|
|
108
|
+
id: "pem-pkcs8-private-key",
|
|
109
|
+
title: "Private key (PKCS#8 PEM)",
|
|
110
|
+
description: "PKCS#8 private key block",
|
|
111
|
+
category: "certificate",
|
|
112
|
+
severity: "critical",
|
|
113
|
+
confidence: "high",
|
|
114
|
+
algorithm: "unknown",
|
|
115
|
+
hndl: true,
|
|
116
|
+
cwe: CWE_HARDCODED_KEY,
|
|
117
|
+
sensitive: true,
|
|
118
|
+
message: "Embedded PKCS#8 private key; likely classical RSA/EC, not quantum-safe.",
|
|
119
|
+
remediation: "Migrate to PQC keys and remove embedded private keys from source.",
|
|
120
|
+
},
|
|
93
121
|
},
|
|
94
122
|
{
|
|
95
123
|
re: /-----BEGIN CERTIFICATE-----/g,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
124
|
+
meta: {
|
|
125
|
+
id: "pem-certificate",
|
|
126
|
+
title: "X.509 certificate (PEM)",
|
|
127
|
+
description: "X.509 certificate block",
|
|
128
|
+
category: "certificate",
|
|
129
|
+
severity: "low",
|
|
130
|
+
confidence: "high",
|
|
131
|
+
algorithm: "unknown",
|
|
132
|
+
hndl: false,
|
|
133
|
+
cwe: CWE_BROKEN_CRYPTO,
|
|
134
|
+
message: "Embedded X.509 certificate; almost certainly signed with classical RSA/ECDSA.",
|
|
135
|
+
remediation: "Plan re-issuance with PQC-capable CAs as ML-DSA certificate profiles mature.",
|
|
136
|
+
},
|
|
105
137
|
},
|
|
106
138
|
];
|
|
107
139
|
/** Detects PEM key/certificate material in arbitrary files. */
|
|
@@ -110,6 +142,7 @@ export const pemDetector = {
|
|
|
110
142
|
description: "PEM-encoded private keys and X.509 certificates in any file",
|
|
111
143
|
scope: "config",
|
|
112
144
|
language: "any",
|
|
145
|
+
rules: PEM_RULES.map((r) => r.meta),
|
|
113
146
|
// Applies to every text file; the walker already filters out binaries.
|
|
114
147
|
appliesTo: () => true,
|
|
115
148
|
detect({ file, content }) {
|
|
@@ -119,18 +152,7 @@ export const pemDetector = {
|
|
|
119
152
|
const findings = [];
|
|
120
153
|
for (const rule of PEM_RULES) {
|
|
121
154
|
eachMatch(rule.re, content, (m) => {
|
|
122
|
-
findings.push(
|
|
123
|
-
ruleId: rule.ruleId,
|
|
124
|
-
title: rule.title,
|
|
125
|
-
category: rule.category,
|
|
126
|
-
severity: rule.severity,
|
|
127
|
-
confidence: "high",
|
|
128
|
-
algorithm: rule.algorithm,
|
|
129
|
-
hndl: rule.hndl,
|
|
130
|
-
cwe: rule.cwe,
|
|
131
|
-
sensitive: rule.sensitive,
|
|
132
|
-
message: rule.message,
|
|
133
|
-
remediation: rule.remediation,
|
|
155
|
+
findings.push(findingFromRule(rule.meta, {
|
|
134
156
|
file,
|
|
135
157
|
content,
|
|
136
158
|
index: m.index,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pem.js","sourceRoot":"","sources":["../../src/detectors/pem.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pem.js","sourceRoot":"","sources":["../../src/detectors/pem.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAChE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C,KAAK;oBACd,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM;iBACzB,CAAC,CACH,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAC"}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Source-code detectors for classical, non-quantum-safe asymmetric cryptography
|
|
3
3
|
* in JavaScript / TypeScript. Each detector is pure and stateless: it declares
|
|
4
|
-
* which files it applies to
|
|
5
|
-
* contents.
|
|
4
|
+
* which files it applies to, the catalog of rules it can emit (`rules`), and
|
|
5
|
+
* returns zero or more Findings for a file's contents.
|
|
6
|
+
*
|
|
7
|
+
* Rule metadata (title / severity / category / remediation / …) lives ONCE in
|
|
8
|
+
* the per-detector `RuleMeta` declarations below, not inline in `detect()`.
|
|
9
|
+
* `detect()` builds findings from those declarations via `findingFromRule`,
|
|
10
|
+
* overriding only the fields that genuinely vary per match (e.g. the concrete
|
|
11
|
+
* algorithm family of a `generateKeyPair('ec')` call). The declarations are the
|
|
12
|
+
* catalog surfaced by the registry, SARIF `rules[]`, and the MCP resolver.
|
|
6
13
|
*
|
|
7
14
|
* The detection strategy is deliberately lexical (regex over source text). This
|
|
8
15
|
* is robust to bundling and partial files and keeps the package dependency-free.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/detectors/source.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/detectors/source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,aAAa,CAAC;AAszB/D,0DAA0D;AAC1D,eAAO,MAAM,eAAe,EAAE,QAAQ,EAOrC,CAAC"}
|