@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.
- package/CHANGELOG.md +18 -0
- package/LICENSE +202 -202
- package/README.md +162 -151
- package/action.yml +44 -44
- package/dist/badge.js +60 -60
- package/dist/cbom.js +59 -59
- package/dist/cli.js +305 -305
- package/dist/community-rules.js +30 -30
- package/dist/community.js +28 -28
- package/dist/ignore.js +75 -75
- package/dist/infra.js +557 -557
- package/dist/map-activity.js +22 -22
- package/dist/map-areas.js +50 -41
- package/dist/map-cloud-keys.js +108 -0
- package/dist/map-host.js +333 -333
- package/dist/map-network.js +518 -0
- package/dist/map-people.js +77 -0
- package/dist/map-rank.js +48 -48
- package/dist/map-report.js +178 -138
- package/dist/map-run.js +271 -205
- package/dist/map-types.js +16 -16
- package/dist/map-web.js +640 -640
- package/dist/pqc.js +32 -32
- package/dist/report.js +179 -179
- package/dist/rules.js +135 -133
- package/dist/sarif.js +43 -43
- package/dist/scan.js +220 -214
- package/dist/score.js +122 -122
- package/dist/secrets.js +108 -97
- package/dist/share-config.js +111 -111
- package/dist/share.js +114 -112
- package/dist/types.js +2 -2
- package/dist/walk.js +63 -63
- package/package.json +53 -52
package/dist/map-activity.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
// Activity log: every connection and every file the encryption map reads, with time, target and reason.
|
|
2
|
-
// Written next to the report, so a customer can hand it to their security team.
|
|
3
|
-
import { appendFileSync } from "node:fs";
|
|
4
|
-
export class ActivityLog {
|
|
5
|
-
entries = [];
|
|
6
|
-
file;
|
|
7
|
-
constructor(file) {
|
|
8
|
-
this.file = file;
|
|
9
|
-
}
|
|
10
|
-
record(area, target, what) {
|
|
11
|
-
const line = `${new Date().toISOString()} ${area.padEnd(5)} ${target} ${what}`;
|
|
12
|
-
this.entries.push(line);
|
|
13
|
-
if (this.file) {
|
|
14
|
-
try {
|
|
15
|
-
appendFileSync(this.file, line + "\n");
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
// the log in memory still goes into the report
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
1
|
+
// Activity log: every connection and every file the encryption map reads, with time, target and reason.
|
|
2
|
+
// Written next to the report, so a customer can hand it to their security team.
|
|
3
|
+
import { appendFileSync } from "node:fs";
|
|
4
|
+
export class ActivityLog {
|
|
5
|
+
entries = [];
|
|
6
|
+
file;
|
|
7
|
+
constructor(file) {
|
|
8
|
+
this.file = file;
|
|
9
|
+
}
|
|
10
|
+
record(area, target, what) {
|
|
11
|
+
const line = `${new Date().toISOString()} ${area.padEnd(5)} ${target} ${what}`;
|
|
12
|
+
this.entries.push(line);
|
|
13
|
+
if (this.file) {
|
|
14
|
+
try {
|
|
15
|
+
appendFileSync(this.file, line + "\n");
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// the log in memory still goes into the report
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
package/dist/map-areas.js
CHANGED
|
@@ -1,41 +1,50 @@
|
|
|
1
|
-
// The permission card for each area: what it touches, what it reads, what it never does.
|
|
2
|
-
// Shown before an area runs. The answer is no unless the person says yes.
|
|
3
|
-
const list = (t) => (t.length <= 4 ? t.join(", ") : `${t.slice(0, 3).join(", ")} and ${t.length - 3} more`);
|
|
4
|
-
export const CARDS = {
|
|
5
|
-
code: {
|
|
6
|
-
area: "code",
|
|
7
|
-
title: "Code and config",
|
|
8
|
-
touch: (t) => `the files in ${list(t)}.`,
|
|
9
|
-
read: "source code and infrastructure config, in memory, to find encryption, leaked keys and exposed settings.",
|
|
10
|
-
never: "change a file, run any code, or send code anywhere.",
|
|
11
|
-
cost: "Reads files only. No network connections.",
|
|
12
|
-
},
|
|
13
|
-
web: {
|
|
14
|
-
area: "web",
|
|
15
|
-
title: "Websites and public services",
|
|
16
|
-
touch: (t) => `${t.length} address${t.length === 1 ? "" : "es"} (${list(t)}), each under a domain you proved you own with a DNS record.`,
|
|
17
|
-
read: "the encryption each one offers when connecting, the same handshake a browser makes, and its certificate. For SSH addresses, the settings the server announces before any login.",
|
|
18
|
-
never: "log in, test for vulnerabilities, send attack traffic, or touch any address you haven't proved.",
|
|
19
|
-
cost: "About 6 connections per address, one at a time.",
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
area: "
|
|
23
|
-
title: "
|
|
24
|
-
touch: () =>
|
|
25
|
-
read: "
|
|
26
|
-
never: "
|
|
27
|
-
cost: "
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
1
|
+
// The permission card for each area: what it touches, what it reads, what it never does.
|
|
2
|
+
// Shown before an area runs. The answer is no unless the person says yes.
|
|
3
|
+
const list = (t) => (t.length <= 4 ? t.join(", ") : `${t.slice(0, 3).join(", ")} and ${t.length - 3} more`);
|
|
4
|
+
export const CARDS = {
|
|
5
|
+
code: {
|
|
6
|
+
area: "code",
|
|
7
|
+
title: "Code and config",
|
|
8
|
+
touch: (t) => `the files in ${list(t)}.`,
|
|
9
|
+
read: "source code and infrastructure config, in memory, to find encryption, leaked keys and exposed settings.",
|
|
10
|
+
never: "change a file, run any code, or send code anywhere.",
|
|
11
|
+
cost: "Reads files only. No network connections.",
|
|
12
|
+
},
|
|
13
|
+
web: {
|
|
14
|
+
area: "web",
|
|
15
|
+
title: "Websites and public services",
|
|
16
|
+
touch: (t) => `${t.length} address${t.length === 1 ? "" : "es"} (${list(t)}), each under a domain you proved you own with a DNS record.`,
|
|
17
|
+
read: "the encryption each one offers when connecting, the same handshake a browser makes, and its certificate. For SSH addresses, the settings the server announces before any login.",
|
|
18
|
+
never: "log in, test for vulnerabilities, send attack traffic, or touch any address you haven't proved.",
|
|
19
|
+
cost: "About 6 connections per address, one at a time.",
|
|
20
|
+
},
|
|
21
|
+
network: {
|
|
22
|
+
area: "network",
|
|
23
|
+
title: "Network and connected equipment",
|
|
24
|
+
touch: (t) => `the addresses in ${list(t)}: private ranges on your own network only, at most 1,024 addresses.`,
|
|
25
|
+
read: "which of about 30 common ports answer on each device, the title of any web page they serve, the certificate on secure admin pages, and the router's list of automatic port forwards (UPnP), if it publishes one.",
|
|
26
|
+
never: "log in, try a password, send commands to equipment, change a setting, or touch any address outside these ranges.",
|
|
27
|
+
cost: "One connection at a time per device, a few a second. Usually a few minutes.",
|
|
28
|
+
warning: "Some older industrial, medical or building controllers can misbehave even when gently connected to. List any under exclude in the scope file, or answer no and skip this area.",
|
|
29
|
+
},
|
|
30
|
+
host: {
|
|
31
|
+
area: "host",
|
|
32
|
+
title: "This machine",
|
|
33
|
+
touch: () => "this computer only.",
|
|
34
|
+
read: "SSH and TLS settings, Windows encryption settings, the machine's own certificates, and the type and size of public key files.",
|
|
35
|
+
never: "change a setting, read a private key, or connect to anything.",
|
|
36
|
+
cost: "Reads local settings only. No network connections.",
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
export function cardText(card, targets) {
|
|
40
|
+
const lines = [
|
|
41
|
+
card.title,
|
|
42
|
+
` What I'll touch: ${card.touch(targets)}`,
|
|
43
|
+
` What I read: ${card.read}`,
|
|
44
|
+
` What I never do: ${card.never}`,
|
|
45
|
+
` ${card.cost}`,
|
|
46
|
+
];
|
|
47
|
+
if (card.warning)
|
|
48
|
+
lines.push(` ${card.warning}`);
|
|
49
|
+
return lines.join("\n");
|
|
50
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Who holds the keys to your cloud data. Reads Terraform/OpenTofu and CloudFormation for storage,
|
|
2
|
+
// databases and backups, and notes where the cloud provider holds the encryption keys.
|
|
3
|
+
// Provider-held keys protect against a stolen disk, not against the provider, an insider there,
|
|
4
|
+
// or a legal demand made to them. For data no third party should be able to read, encrypt it
|
|
5
|
+
// before it leaves your hands, or keep the keys yourself.
|
|
6
|
+
// Advice only: it is listed in the map report and does not change the readiness score.
|
|
7
|
+
export const CUSTODY_FIX = {
|
|
8
|
+
provider: "The provider holds the keys, so it can read this data. Encrypt sensitive data before it's uploaded (client-side encryption), or use keys you hold: an external key store such as AWS KMS External Key Store, Google Cloud External Key Manager or Azure Key Vault Managed HSM with your own keys.",
|
|
9
|
+
"provider-kms": "You manage the key, but it lives in the provider's key service, so the provider could still use it. For data no third party should read, encrypt it before upload or move the key to an external key store you hold.",
|
|
10
|
+
};
|
|
11
|
+
/** Resource types we know, what they hold, and which keys name a key you chose. */
|
|
12
|
+
const TF = {
|
|
13
|
+
aws_s3_bucket_server_side_encryption_configuration: { kind: "storage", keyAttr: /kms_master_key_id\s*=/, defaultOn: true },
|
|
14
|
+
aws_db_instance: { kind: "database", keyAttr: /kms_key_id\s*=/, needsOn: /storage_encrypted\s*=\s*true/ },
|
|
15
|
+
aws_rds_cluster: { kind: "database", keyAttr: /kms_key_id\s*=/, needsOn: /storage_encrypted\s*=\s*true/ },
|
|
16
|
+
aws_docdb_cluster: { kind: "database", keyAttr: /kms_key_id\s*=/, needsOn: /storage_encrypted\s*=\s*true/ },
|
|
17
|
+
aws_neptune_cluster: { kind: "database", keyAttr: /kms_key_arn\s*=/, needsOn: /storage_encrypted\s*=\s*true/ },
|
|
18
|
+
aws_redshift_cluster: { kind: "database", keyAttr: /kms_key_id\s*=/, needsOn: /encrypted\s*=\s*true/ },
|
|
19
|
+
aws_dynamodb_table: { kind: "database", keyAttr: /kms_key_arn\s*=/, defaultOn: true },
|
|
20
|
+
aws_ebs_volume: { kind: "disk", keyAttr: /kms_key_id\s*=/, needsOn: /encrypted\s*=\s*true/ },
|
|
21
|
+
aws_efs_file_system: { kind: "storage", keyAttr: /kms_key_id\s*=/, needsOn: /encrypted\s*=\s*true/ },
|
|
22
|
+
aws_backup_vault: { kind: "backup", keyAttr: /kms_key_arn\s*=/, defaultOn: true },
|
|
23
|
+
aws_sqs_queue: { kind: "storage", keyAttr: /kms_master_key_id\s*=/, needsOn: /sqs_managed_sse_enabled\s*=\s*true|kms_master_key_id/ },
|
|
24
|
+
google_storage_bucket: { kind: "storage", keyAttr: /default_kms_key_name\s*=/, defaultOn: true },
|
|
25
|
+
google_sql_database_instance: { kind: "database", keyAttr: /encryption_key_name\s*=/, defaultOn: true },
|
|
26
|
+
google_bigquery_dataset: { kind: "database", keyAttr: /kms_key_name\s*=/, defaultOn: true },
|
|
27
|
+
google_compute_disk: { kind: "disk", keyAttr: /kms_key_self_link\s*=|raw_key\s*=|rsa_encrypted_key\s*=/, defaultOn: true },
|
|
28
|
+
azurerm_storage_account: { kind: "storage", keyAttr: /customer_managed_key\s*\{/, defaultOn: true },
|
|
29
|
+
azurerm_mssql_database: { kind: "database", keyAttr: /transparent_data_encryption_key_vault_key_id\s*=/, defaultOn: true },
|
|
30
|
+
azurerm_postgresql_flexible_server: { kind: "database", keyAttr: /customer_managed_key\s*\{/, defaultOn: true },
|
|
31
|
+
azurerm_cosmosdb_account: { kind: "database", keyAttr: /key_vault_key_id\s*=/, defaultOn: true },
|
|
32
|
+
};
|
|
33
|
+
const KIND_WORD = { storage: "Cloud storage", database: "Cloud database", backup: "Cloud backups", disk: "Cloud disk" };
|
|
34
|
+
function title(kind, c) {
|
|
35
|
+
return c === "provider" ? `${KIND_WORD[kind]} encrypted with keys the provider holds` : `${KIND_WORD[kind]} keys live in the provider's key service`;
|
|
36
|
+
}
|
|
37
|
+
function advice(path, line, resource, kind, custody) {
|
|
38
|
+
return { target: `${path}:${line}`, resource, kind, custody, ruleId: custody === "provider" ? "cloud-provider-held-keys" : "cloud-keys-in-provider-kms", title: title(kind, custody), fix: CUSTODY_FIX[custody] };
|
|
39
|
+
}
|
|
40
|
+
const strip = (s) => s.replace(/"(?:[^"\\]|\\.)*"/g, '""').replace(/#.*$|\/\/.*$/, "");
|
|
41
|
+
/** Terraform resource blocks: type, name, first line (1-based) and body text. */
|
|
42
|
+
export function tfResources(text) {
|
|
43
|
+
const lines = text.split("\n");
|
|
44
|
+
const out = [];
|
|
45
|
+
for (let i = 0; i < lines.length; i++) {
|
|
46
|
+
const m = lines[i].match(/^\s*resource\s+"([a-z0-9_]+)"\s+"([A-Za-z0-9_-]+)"\s*\{/);
|
|
47
|
+
if (!m)
|
|
48
|
+
continue;
|
|
49
|
+
let depth = 0;
|
|
50
|
+
let j = i;
|
|
51
|
+
for (; j < lines.length; j++) {
|
|
52
|
+
for (const ch of strip(lines[j])) {
|
|
53
|
+
if (ch === "{")
|
|
54
|
+
depth++;
|
|
55
|
+
else if (ch === "}")
|
|
56
|
+
depth--;
|
|
57
|
+
}
|
|
58
|
+
if (depth <= 0)
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
out.push({ type: m[1], name: m[2], line: i + 1, body: lines.slice(i + 1, j).map((l) => l.replace(/^\s*(#|\/\/).*$/, "")).join("\n") });
|
|
62
|
+
i = j;
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
export function cloudKeyAdvice(path, text) {
|
|
67
|
+
const p = path.toLowerCase();
|
|
68
|
+
const out = [];
|
|
69
|
+
if (/\.(tf|hcl)$/.test(p)) {
|
|
70
|
+
const res = tfResources(text);
|
|
71
|
+
// An Azure storage account can get its key from a separate resource in the same file.
|
|
72
|
+
const separateAzureKey = res.some((r) => r.type === "azurerm_storage_account_customer_managed_key");
|
|
73
|
+
for (const r of res) {
|
|
74
|
+
const spec = TF[r.type];
|
|
75
|
+
if (!spec)
|
|
76
|
+
continue;
|
|
77
|
+
if (spec.needsOn && !spec.needsOn.test(r.body))
|
|
78
|
+
continue; // encryption off is already a finding of its own
|
|
79
|
+
const id = `${r.type}.${r.name}`;
|
|
80
|
+
if (r.type === "aws_s3_bucket_server_side_encryption_configuration") {
|
|
81
|
+
const own = !/sse_algorithm\s*=\s*"AES256"/.test(r.body) && spec.keyAttr.test(r.body);
|
|
82
|
+
out.push(advice(path, r.line, id, spec.kind, own ? "provider-kms" : "provider"));
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
// A customer-supplied key (raw_key or rsa_encrypted_key) is one you hold: Google keeps only a hash of it.
|
|
86
|
+
if (r.type === "google_compute_disk" && /raw_key\s*=|rsa_encrypted_key\s*=/.test(r.body))
|
|
87
|
+
continue;
|
|
88
|
+
if (r.type === "azurerm_storage_account" && separateAzureKey) {
|
|
89
|
+
out.push(advice(path, r.line, id, spec.kind, "provider-kms"));
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
out.push(advice(path, r.line, id, spec.kind, spec.keyAttr.test(r.body) ? "provider-kms" : "provider"));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else if (/\.(ya?ml|json|template)$/.test(p) && /AWSTemplateFormatVersion|AWS::/.test(text)) {
|
|
96
|
+
const lines = text.split("\n");
|
|
97
|
+
lines.forEach((l, i) => {
|
|
98
|
+
const m = l.match(/["']?SSEAlgorithm["']?\s*:\s*["']?(AES256|aws:kms)["']?/);
|
|
99
|
+
if (!m)
|
|
100
|
+
return;
|
|
101
|
+
// The key can sit just before or just after (JSON tools often sort keys, putting KMSMasterKeyID first).
|
|
102
|
+
const near = lines.slice(Math.max(0, i - 3), i + 4).join("\n");
|
|
103
|
+
const custody = m[1] === "AES256" || !/KMSMasterKeyID/.test(near) ? "provider" : "provider-kms";
|
|
104
|
+
out.push(advice(path, i + 1, "S3 bucket encryption", "storage", custody));
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
}
|