@intellectual-frontiers/grc 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +8 -2
- package/dist/assess.d.ts +247 -0
- package/dist/assess.js +289 -0
- package/dist/attest.d.ts +164 -0
- package/dist/attest.js +213 -0
- package/dist/evidence.d.ts +212 -0
- package/dist/evidence.js +453 -0
- package/dist/grc.d.ts +356 -0
- package/dist/grc.js +487 -0
- package/dist/host/grc.d.ts +159 -0
- package/dist/host/grc.js +358 -0
- package/dist/host/mod.d.ts +14 -0
- package/dist/host/mod.js +15 -0
- package/dist/host/sign.d.ts +141 -0
- package/dist/host/sign.js +282 -0
- package/dist/mod.d.ts +19 -0
- package/dist/mod.js +20 -0
- package/dist/ocsf-types.auto.d.ts +4374 -0
- package/dist/ocsf-types.auto.js +24 -0
- package/dist/ocsf.d.ts +160 -0
- package/dist/ocsf.js +257 -0
- package/dist/oscal.d.ts +356 -0
- package/dist/oscal.js +513 -0
- package/package.json +87 -4
- package/src/assess.ts +472 -0
- package/src/attest.ts +354 -0
- package/src/evidence.ts +551 -0
- package/src/grc.ts +771 -0
- package/src/host/grc.ts +435 -0
- package/src/host/mod.ts +15 -0
- package/src/host/sign.ts +364 -0
- package/src/mod.ts +20 -0
- package/src/ocsf-types.auto.ts +4680 -0
- package/src/ocsf.ts +471 -0
- package/src/oscal.ts +850 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript types for the OCSF 1.9.0 classes the harnesses emit (commons 0001-grc FR-016), and every object they use. A required
|
|
3
|
+
* attribute is required here; an attribute a profile adds is optional; a deprecated one says so. The classes:
|
|
4
|
+
* - Compliance Finding (2003, `compliance_finding`)
|
|
5
|
+
* - Vulnerability Finding (2002, `vulnerability_finding`)
|
|
6
|
+
* - Device Inventory Info (5001, `inventory_info`)
|
|
7
|
+
* - User Inventory Info (5003, `user_inventory`)
|
|
8
|
+
* - Cloud Resources Inventory Info (5023, `cloud_resources_inventory_info`)
|
|
9
|
+
*
|
|
10
|
+
* GENERATED by `bun tools/ocsf-gen.ts` from the OCSF 1.9.0 schema (schema.ocsf.io, every response pinned by its SHA-256 in the
|
|
11
|
+
* generator); never edit by hand. OCSF is Apache-2.0, a Linux Foundation project.
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
/** The OCSF version these types are for. */
|
|
16
|
+
export const OCSF_VERSION = "1.9.0";
|
|
17
|
+
/** The classes these types are for: their uid, caption, and category. */
|
|
18
|
+
export const OCSF_CLASSES = {
|
|
19
|
+
compliance_finding: { uid: 2003, caption: "Compliance Finding", category_uid: 2, category_name: "Findings" },
|
|
20
|
+
vulnerability_finding: { uid: 2002, caption: "Vulnerability Finding", category_uid: 2, category_name: "Findings" },
|
|
21
|
+
inventory_info: { uid: 5001, caption: "Device Inventory Info", category_uid: 5, category_name: "Discovery" },
|
|
22
|
+
user_inventory: { uid: 5003, caption: "User Inventory Info", category_uid: 5, category_name: "Discovery" },
|
|
23
|
+
cloud_resources_inventory_info: { uid: 5023, caption: "Cloud Resources Inventory Info", category_uid: 5, category_name: "Discovery" },
|
|
24
|
+
};
|
package/dist/ocsf.d.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { type Assessment, type Finding, type Instant, type Outcome, type Severity, type SubjectRef } from "./grc.js";
|
|
2
|
+
import { type OcsfCloudResourcesInventoryInfo, type OcsfCompliance, type OcsfComplianceFinding, type OcsfDevice, type OcsfDeviceInventoryInfo, type OcsfFindingInfo, type OcsfMetadata, type OcsfOpenObject, type OcsfProduct, type OcsfResourceDetails, type OcsfUser, type OcsfUserInventoryInfo, type OcsfVulnerability, type OcsfVulnerabilityFinding } from "./ocsf-types.auto.js";
|
|
3
|
+
export * from "./ocsf-types.auto.js";
|
|
4
|
+
/** `T` with the members `K` present: what this module always writes of an attribute OCSF leaves optional. */
|
|
5
|
+
export type Present<T, K extends keyof T> = T & {
|
|
6
|
+
readonly [P in K]-?: Exclude<T[P], undefined>;
|
|
7
|
+
};
|
|
8
|
+
/** The metadata an event carries beyond the schema version and the product: an event id, the tenant, a correlation id, labels, ... */
|
|
9
|
+
export type MetadataExtra = Partial<Omit<OcsfMetadata, "version" | "product">>;
|
|
10
|
+
/** OCSF's `severity_id` (every class here has the same): 0 Unknown, 1 Informational, 2 Low, 3 Medium, 4 High, 5 Critical, 6 Fatal, 99 Other. */
|
|
11
|
+
export type OcsfSeverityId = OcsfComplianceFinding["severity_id"];
|
|
12
|
+
/** The captions of the severities this module writes. */
|
|
13
|
+
export type OcsfSeverity = "Unknown" | "Informational" | "Low" | "Medium" | "High" | "Critical";
|
|
14
|
+
/** A severity as OCSF's `severity_id` and its caption. */
|
|
15
|
+
export declare const OCSF_SEVERITY: Readonly<Record<Severity, {
|
|
16
|
+
readonly id: OcsfSeverityId;
|
|
17
|
+
readonly caption: OcsfSeverity;
|
|
18
|
+
}>>;
|
|
19
|
+
/** The activities of a finding (classes 2002 and 2003): 1 Create, 2 Update, 3 Close. */
|
|
20
|
+
export type FindingActivity = "create" | "update" | "close";
|
|
21
|
+
/** The activities of an inventory (classes 5001, 5003 and 5023): 1 Log, 2 Collect. */
|
|
22
|
+
export type InventoryActivity = "log" | "collect";
|
|
23
|
+
/** The members every event of a class has here: its class, category, activity and type, with their captions. */
|
|
24
|
+
type Envelope<C extends number, Cat extends number, A extends number, T extends number, Name extends string, CatName extends string> = {
|
|
25
|
+
readonly class_uid: C;
|
|
26
|
+
readonly class_name: Name;
|
|
27
|
+
readonly category_uid: Cat;
|
|
28
|
+
readonly category_name: CatName;
|
|
29
|
+
readonly activity_id: A;
|
|
30
|
+
readonly activity_name: string;
|
|
31
|
+
readonly type_uid: T;
|
|
32
|
+
readonly type_name: `${Name}: ${string}`;
|
|
33
|
+
readonly severity: OcsfSeverity;
|
|
34
|
+
readonly metadata: OcsfMetadata;
|
|
35
|
+
};
|
|
36
|
+
/** OCSF's compliance `status_id`: 0 Unknown, 1 Pass, 2 Warning, 3 Fail, 99 Other. */
|
|
37
|
+
export type OcsfComplianceStatusId = Exclude<OcsfCompliance["status_id"], undefined>;
|
|
38
|
+
/** The captions of the compliance statuses this module writes. */
|
|
39
|
+
export type OcsfComplianceStatus = "Unknown" | "Pass" | "Warning" | "Fail" | "Not Applicable";
|
|
40
|
+
/** A finding's `status_id` (OCSF Findings): 0 Unknown, 1 New, 2 In Progress, 3 Suppressed, 4 Resolved, 5 Archived, 6 Deleted, 99 Other. */
|
|
41
|
+
export type OcsfFindingStatusId = Exclude<OcsfComplianceFinding["status_id"], undefined>;
|
|
42
|
+
/** The captions of the finding statuses this module writes. */
|
|
43
|
+
export type OcsfFindingStatus = "Unknown" | "New" | "In Progress" | "Suppressed" | "Resolved";
|
|
44
|
+
/** A resource as this module writes it: its uid, name and type always there. */
|
|
45
|
+
export type ResourceEvent = Present<OcsfResourceDetails, "uid" | "name" | "type">;
|
|
46
|
+
/** An OCSF 1.9.0 Compliance Finding (class 2003) as this module writes it. */
|
|
47
|
+
export type ComplianceFindingEvent = OcsfComplianceFinding & Envelope<2003, 2, 1 | 2 | 3, 200301 | 200302 | 200303, "Compliance Finding", "Findings"> & {
|
|
48
|
+
readonly status_id: OcsfFindingStatusId;
|
|
49
|
+
readonly status: OcsfFindingStatus;
|
|
50
|
+
readonly message: string;
|
|
51
|
+
readonly finding_info: Present<OcsfFindingInfo, "title" | "created_time" | "types">;
|
|
52
|
+
readonly compliance: Present<OcsfCompliance, "control" | "standards" | "status_id" | "status" | "status_code"> & {
|
|
53
|
+
readonly status_id: OcsfComplianceStatusId;
|
|
54
|
+
readonly status: OcsfComplianceStatus;
|
|
55
|
+
};
|
|
56
|
+
readonly resources: readonly ResourceEvent[];
|
|
57
|
+
};
|
|
58
|
+
/** What a Compliance Finding needs beyond the finding: the product, and optionally the activity, the standards and more metadata. */
|
|
59
|
+
export type ComplianceFindingOptions = {
|
|
60
|
+
readonly product: OcsfProduct;
|
|
61
|
+
/** `create` (the default) for a finding first reported, `update` for one reported again, `close` for one resolved. */
|
|
62
|
+
readonly activity?: FindingActivity;
|
|
63
|
+
/** The standards the control is checked against; by default the catalogs the control implements, or its own id where it implements none. */
|
|
64
|
+
readonly standards?: (f: Finding) => readonly string[];
|
|
65
|
+
readonly metadata?: MetadataExtra;
|
|
66
|
+
};
|
|
67
|
+
/** How an outcome maps to the compliance status and to the finding's status (the table in the module's documentation). */
|
|
68
|
+
export declare function ocsfStatus(outcome: Outcome, status: Outcome): {
|
|
69
|
+
readonly compliance: {
|
|
70
|
+
readonly id: OcsfComplianceStatusId;
|
|
71
|
+
readonly caption: OcsfComplianceStatus;
|
|
72
|
+
};
|
|
73
|
+
readonly finding: {
|
|
74
|
+
readonly id: OcsfFindingStatusId;
|
|
75
|
+
readonly caption: OcsfFindingStatus;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
/** A finding as an OCSF 1.9.0 Compliance Finding. */
|
|
79
|
+
export declare function complianceFinding(f: Finding, options: ComplianceFindingOptions): ComplianceFindingEvent;
|
|
80
|
+
/** Every finding of an assessment as Compliance Findings, in the assessment's order. */
|
|
81
|
+
export declare function complianceFindings(a: Assessment, options: ComplianceFindingOptions): readonly ComplianceFindingEvent[];
|
|
82
|
+
/** Where a vulnerability finding stands: 1 New, 2 In Progress, 3 Suppressed (dismissed), 4 Resolved (fixed); unknown where not said. */
|
|
83
|
+
export type VulnerabilityStatus = "new" | "in-progress" | "suppressed" | "resolved";
|
|
84
|
+
/** A scanner's finding: its stable id and title, its severity and status where known, its vulnerabilities and what they affect. */
|
|
85
|
+
export type VulnerabilityInput = {
|
|
86
|
+
/** The finding's id at its source, the same in every report of it (`finding_info.uid`). */
|
|
87
|
+
readonly uid: string;
|
|
88
|
+
readonly title: string;
|
|
89
|
+
/** Its severity; 0 Unknown where not given. */
|
|
90
|
+
readonly severity?: Severity;
|
|
91
|
+
/** Its status; 0 Unknown where not given. */
|
|
92
|
+
readonly status?: VulnerabilityStatus;
|
|
93
|
+
/** The vulnerabilities (OCSF asks each for a CVE, a CWE or an advisory). */
|
|
94
|
+
readonly vulnerabilities: readonly [OcsfVulnerability, ...OcsfVulnerability[]];
|
|
95
|
+
/** The resources affected. */
|
|
96
|
+
readonly resources?: readonly OcsfResourceDetails[];
|
|
97
|
+
/** More of `finding_info`: `first_seen_time`, `data_sources`, `src_url`, ... */
|
|
98
|
+
readonly findingInfo?: Partial<Omit<OcsfFindingInfo, "uid" | "title">>;
|
|
99
|
+
};
|
|
100
|
+
/** What a Vulnerability Finding needs beyond the finding: the product, the instant it is reported, and optionally the activity and metadata. */
|
|
101
|
+
export type VulnerabilityOptions = {
|
|
102
|
+
readonly product: OcsfProduct;
|
|
103
|
+
readonly at: Instant;
|
|
104
|
+
readonly activity?: FindingActivity;
|
|
105
|
+
readonly metadata?: MetadataExtra;
|
|
106
|
+
};
|
|
107
|
+
/** An OCSF 1.9.0 Vulnerability Finding (class 2002) as this module writes it. */
|
|
108
|
+
export type VulnerabilityFindingEvent = OcsfVulnerabilityFinding & Envelope<2002, 2, 1 | 2 | 3, 200201 | 200202 | 200203, "Vulnerability Finding", "Findings"> & {
|
|
109
|
+
readonly status_id: OcsfFindingStatusId;
|
|
110
|
+
readonly status: OcsfFindingStatus;
|
|
111
|
+
readonly message: string;
|
|
112
|
+
readonly finding_info: Present<OcsfFindingInfo, "title">;
|
|
113
|
+
};
|
|
114
|
+
/** A scanner's finding as an OCSF 1.9.0 Vulnerability Finding. */
|
|
115
|
+
export declare function vulnerabilityFinding(v: VulnerabilityInput, options: VulnerabilityOptions): VulnerabilityFindingEvent;
|
|
116
|
+
/** What an inventory event needs: the product, the instant it was taken, whether it was collected (the default) or logged, more metadata. */
|
|
117
|
+
export type InventoryOptions = {
|
|
118
|
+
readonly product: OcsfProduct;
|
|
119
|
+
readonly at: Instant;
|
|
120
|
+
readonly activity?: InventoryActivity;
|
|
121
|
+
readonly metadata?: MetadataExtra;
|
|
122
|
+
/** What the source said that OCSF has no attribute for (`unmapped`). */
|
|
123
|
+
readonly unmapped?: OcsfOpenObject;
|
|
124
|
+
};
|
|
125
|
+
/** An OCSF 1.9.0 Device Inventory Info event (class 5001) as this module writes it. */
|
|
126
|
+
export type DeviceInventoryEvent = OcsfDeviceInventoryInfo & Envelope<5001, 5, 1 | 2, 500101 | 500102, "Device Inventory Info", "Discovery"> & {
|
|
127
|
+
readonly severity_id: 1;
|
|
128
|
+
};
|
|
129
|
+
/** An OCSF 1.9.0 User Inventory Info event (class 5003) as this module writes it. */
|
|
130
|
+
export type UserInventoryEvent = OcsfUserInventoryInfo & Envelope<5003, 5, 1 | 2, 500301 | 500302, "User Inventory Info", "Discovery"> & {
|
|
131
|
+
readonly severity_id: 1;
|
|
132
|
+
};
|
|
133
|
+
/** An OCSF 1.9.0 Cloud Resources Inventory Info event (class 5023) as this module writes it. */
|
|
134
|
+
export type CloudResourcesInventoryEvent = OcsfCloudResourcesInventoryInfo & Envelope<5023, 5, 1 | 2, 502301 | 502302, "Cloud Resources Inventory Info", "Discovery"> & {
|
|
135
|
+
readonly severity_id: 1;
|
|
136
|
+
readonly resources: readonly OcsfResourceDetails[];
|
|
137
|
+
};
|
|
138
|
+
/** Any event this module writes. */
|
|
139
|
+
export type OcsfEvent = ComplianceFindingEvent | VulnerabilityFindingEvent | DeviceInventoryEvent | UserInventoryEvent | CloudResourcesInventoryEvent;
|
|
140
|
+
/** A device as an OCSF 1.9.0 Device Inventory Info event. */
|
|
141
|
+
export declare function deviceInventoryInfo(device: OcsfDevice, options: InventoryOptions): DeviceInventoryEvent;
|
|
142
|
+
/** A user (a person, or an account in some system) as an OCSF 1.9.0 User Inventory Info event. */
|
|
143
|
+
export declare function userInventoryInfo(user: OcsfUser, options: InventoryOptions): UserInventoryEvent;
|
|
144
|
+
/** Resources of a cloud or a service (a repository, a bucket, a tenant, ...) as an OCSF 1.9.0 Cloud Resources Inventory Info event. */
|
|
145
|
+
export declare function cloudResourcesInventoryInfo(resources: readonly OcsfResourceDetails[], options: InventoryOptions): CloudResourcesInventoryEvent;
|
|
146
|
+
/** OCSF 1.9.0's device `type_id`. */
|
|
147
|
+
export type OcsfDeviceTypeId = OcsfDevice["type_id"];
|
|
148
|
+
/** The device type captions, by `type_id`. */
|
|
149
|
+
export declare const OCSF_DEVICE_TYPE: Readonly<Record<OcsfDeviceTypeId, string>>;
|
|
150
|
+
/** A subject of an assessment, with what is known of it beyond its kind and id. */
|
|
151
|
+
export type InventoryItem = {
|
|
152
|
+
readonly subject: SubjectRef;
|
|
153
|
+
readonly name?: string;
|
|
154
|
+
readonly hostname?: string;
|
|
155
|
+
readonly type?: OcsfDeviceTypeId;
|
|
156
|
+
};
|
|
157
|
+
/** A subject of an assessment as a Device Inventory Info event: the device's uid is `kind:id`, and the subject's kind is its group. */
|
|
158
|
+
export declare function inventoryInfo(item: InventoryItem, options: InventoryOptions): DeviceInventoryEvent;
|
|
159
|
+
/** The subjects of an assessment as Device Inventory Info events, in the order of their kinds and then ids, each subject once. */
|
|
160
|
+
export declare function inventory(items: readonly InventoryItem[], options: InventoryOptions): readonly DeviceInventoryEvent[];
|
package/dist/ocsf.js
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
// Spec: 0001-grc FR-016
|
|
2
|
+
/**
|
|
3
|
+
* Findings and inventories as OCSF 1.9.0 events (commons 0001-grc FR-016), typed by the types `tools/ocsf-gen.ts` generates from the
|
|
4
|
+
* pinned OCSF 1.9.0 schema (`ocsf-types.auto.ts`, re-exported here), so a missing required attribute does not compile. The classes are the
|
|
5
|
+
* ones the harnesses emit:
|
|
6
|
+
*
|
|
7
|
+
* | Class | What it is made from |
|
|
8
|
+
* | --- | --- |
|
|
9
|
+
* | 2003 Compliance Finding (category 2 Findings) | a GRC finding (`complianceFinding`) |
|
|
10
|
+
* | 2002 Vulnerability Finding (category 2 Findings) | a scanner's finding and its vulnerabilities (`vulnerabilityFinding`) |
|
|
11
|
+
* | 5001 Device Inventory Info (category 5 Discovery) | a device (`deviceInventoryInfo`), or a subject of an assessment (`inventoryInfo`) |
|
|
12
|
+
* | 5003 User Inventory Info (category 5 Discovery) | a user: a person, or an account of one (`userInventoryInfo`) |
|
|
13
|
+
* | 5023 Cloud Resources Inventory Info (category 5 Discovery) | resources of a cloud or a service (`cloudResourcesInventoryInfo`) |
|
|
14
|
+
*
|
|
15
|
+
* Pure and synchronous: the product that writes the events, the instant of an inventory and any further metadata (`tenant_uid`, `uid`,
|
|
16
|
+
* `correlation_uid`, `labels`) are values the caller gives. `type_uid` is `class_uid * 100 + activity_id`; times are milliseconds since
|
|
17
|
+
* the epoch; findings are activity 1 Create, 2 Update or 3 Close, inventories 1 Log or 2 Collect (the default).
|
|
18
|
+
*
|
|
19
|
+
* How a GRC finding maps (its `status` is kept in `compliance.status_code`, its waiver in `compliance.status_details`):
|
|
20
|
+
*
|
|
21
|
+
* | outcome | `compliance.status_id` | `status_id` (the finding's) |
|
|
22
|
+
* | --- | --- | --- |
|
|
23
|
+
* | `pass` | 1 Pass | 4 Resolved |
|
|
24
|
+
* | `warn` | 2 Warning | 1 New |
|
|
25
|
+
* | `fail`, `gap` | 3 Fail | 1 New |
|
|
26
|
+
* | `accepted` | 2 Warning or 3 Fail, as its status | 3 Suppressed |
|
|
27
|
+
* | `error` | 0 Unknown | 1 New |
|
|
28
|
+
* | `not-applicable` | 99 Other ("Not Applicable") | 4 Resolved |
|
|
29
|
+
*
|
|
30
|
+
* Severity: `info` 1 Informational, `low` 2 Low, `medium` 3 Medium, `high` 4 High, `critical` 5 Critical, none 0 Unknown.
|
|
31
|
+
* `finding_info.uid` is the finding's `findingKey`, the same for the same control and subject in every run, so a later event of the same
|
|
32
|
+
* finding updates it.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { complianceFinding } from "./ocsf.ts";
|
|
37
|
+
* const product = { name: "Example Checker", vendor_name: "Example", version: "1.0.0" };
|
|
38
|
+
* // complianceFinding(finding, { product }).class_uid === 2003
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @module
|
|
42
|
+
*/
|
|
43
|
+
import { absurd } from "@intellectual-frontiers/core";
|
|
44
|
+
import { epochMs, findingKey } from "./grc.js";
|
|
45
|
+
import { OCSF_VERSION, } from "./ocsf-types.auto.js";
|
|
46
|
+
export * from "./ocsf-types.auto.js";
|
|
47
|
+
/** A severity as OCSF's `severity_id` and its caption. */
|
|
48
|
+
export const OCSF_SEVERITY = {
|
|
49
|
+
info: { id: 1, caption: "Informational" },
|
|
50
|
+
low: { id: 2, caption: "Low" },
|
|
51
|
+
medium: { id: 3, caption: "Medium" },
|
|
52
|
+
high: { id: 4, caption: "High" },
|
|
53
|
+
critical: { id: 5, caption: "Critical" },
|
|
54
|
+
};
|
|
55
|
+
const UNKNOWN_SEVERITY = { id: 0, caption: "Unknown" };
|
|
56
|
+
const FINDING_ACTIVITY = {
|
|
57
|
+
create: { id: 1, name: "Create" },
|
|
58
|
+
update: { id: 2, name: "Update" },
|
|
59
|
+
close: { id: 3, name: "Close" },
|
|
60
|
+
};
|
|
61
|
+
const INVENTORY_ACTIVITY = {
|
|
62
|
+
log: { id: 1, name: "Log" },
|
|
63
|
+
collect: { id: 2, name: "Collect" },
|
|
64
|
+
};
|
|
65
|
+
function metadataOf(product, extra) {
|
|
66
|
+
return { ...extra, version: OCSF_VERSION, product };
|
|
67
|
+
}
|
|
68
|
+
const byText = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
69
|
+
const unique = (xs) => [...new Set(xs)].sort(byText);
|
|
70
|
+
const COMPLIANCE_TYPE = { create: 200301, update: 200302, close: 200303 };
|
|
71
|
+
/** How an outcome maps to the compliance status and to the finding's status (the table in the module's documentation). */
|
|
72
|
+
export function ocsfStatus(outcome, status) {
|
|
73
|
+
switch (outcome) {
|
|
74
|
+
case "pass":
|
|
75
|
+
return { compliance: { id: 1, caption: "Pass" }, finding: { id: 4, caption: "Resolved" } };
|
|
76
|
+
case "warn":
|
|
77
|
+
return { compliance: { id: 2, caption: "Warning" }, finding: { id: 1, caption: "New" } };
|
|
78
|
+
case "fail":
|
|
79
|
+
case "gap":
|
|
80
|
+
return { compliance: { id: 3, caption: "Fail" }, finding: { id: 1, caption: "New" } };
|
|
81
|
+
case "accepted":
|
|
82
|
+
return {
|
|
83
|
+
compliance: status === "warn" ? { id: 2, caption: "Warning" } : { id: 3, caption: "Fail" },
|
|
84
|
+
finding: { id: 3, caption: "Suppressed" },
|
|
85
|
+
};
|
|
86
|
+
case "error":
|
|
87
|
+
return { compliance: { id: 0, caption: "Unknown" }, finding: { id: 1, caption: "New" } };
|
|
88
|
+
case "not-applicable":
|
|
89
|
+
return { compliance: { id: 99, caption: "Not Applicable" }, finding: { id: 4, caption: "Resolved" } };
|
|
90
|
+
default:
|
|
91
|
+
return absurd(outcome);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function defaultStandards(f) {
|
|
95
|
+
const catalogs = unique(f.control.implements.map((r) => r.catalog));
|
|
96
|
+
return catalogs.length > 0 ? catalogs : [f.control.id];
|
|
97
|
+
}
|
|
98
|
+
function resourceOf(s) {
|
|
99
|
+
return { uid: `${s.kind}:${s.id}`, name: s.id, type: s.kind };
|
|
100
|
+
}
|
|
101
|
+
/** A finding as an OCSF 1.9.0 Compliance Finding. */
|
|
102
|
+
export function complianceFinding(f, options) {
|
|
103
|
+
const kind = options.activity ?? "create";
|
|
104
|
+
const activity = FINDING_ACTIVITY[kind];
|
|
105
|
+
const severity = OCSF_SEVERITY[f.severity];
|
|
106
|
+
const s = ocsfStatus(f.outcome, f.status);
|
|
107
|
+
const time = epochMs(f.at);
|
|
108
|
+
const requirements = unique(f.control.implements.map((r) => `${r.catalog}:${r.id}`));
|
|
109
|
+
return {
|
|
110
|
+
class_uid: 2003,
|
|
111
|
+
class_name: "Compliance Finding",
|
|
112
|
+
category_uid: 2,
|
|
113
|
+
category_name: "Findings",
|
|
114
|
+
activity_id: activity.id,
|
|
115
|
+
activity_name: activity.name,
|
|
116
|
+
type_uid: COMPLIANCE_TYPE[kind],
|
|
117
|
+
type_name: `Compliance Finding: ${activity.name}`,
|
|
118
|
+
severity_id: severity.id,
|
|
119
|
+
severity: severity.caption,
|
|
120
|
+
status_id: s.finding.id,
|
|
121
|
+
status: s.finding.caption,
|
|
122
|
+
time,
|
|
123
|
+
message: `${f.control.id} ${f.outcome} for ${f.subject.kind} ${f.subject.id}: ${f.title}`,
|
|
124
|
+
metadata: metadataOf(options.product, options.metadata),
|
|
125
|
+
finding_info: {
|
|
126
|
+
uid: findingKey(f),
|
|
127
|
+
title: f.title,
|
|
128
|
+
...(f.detail === "" ? {} : { desc: f.detail }),
|
|
129
|
+
created_time: time,
|
|
130
|
+
types: [f.control.id],
|
|
131
|
+
},
|
|
132
|
+
compliance: {
|
|
133
|
+
control: f.control.id,
|
|
134
|
+
standards: (options.standards ?? defaultStandards)(f),
|
|
135
|
+
...(requirements.length > 0 ? { requirements } : {}),
|
|
136
|
+
status_id: s.compliance.id,
|
|
137
|
+
status: s.compliance.caption,
|
|
138
|
+
status_code: f.status,
|
|
139
|
+
...(f.waiver === undefined ? {} : { status_details: [`accepted under waiver ${f.waiver}`] }),
|
|
140
|
+
},
|
|
141
|
+
resources: [resourceOf(f.subject)],
|
|
142
|
+
...(f.evidence.length > 0 ? { evidences: f.evidence.map((d) => ({ data: { sha256: d } })) } : {}),
|
|
143
|
+
...(f.remediation === undefined || f.outcome === "pass" ? {} : { remediation: { desc: f.remediation } }),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/** Every finding of an assessment as Compliance Findings, in the assessment's order. */
|
|
147
|
+
export function complianceFindings(a, options) {
|
|
148
|
+
return a.findings.map((f) => complianceFinding(f, options));
|
|
149
|
+
}
|
|
150
|
+
const VULNERABILITY_STATUS = {
|
|
151
|
+
new: { id: 1, caption: "New" },
|
|
152
|
+
"in-progress": { id: 2, caption: "In Progress" },
|
|
153
|
+
suppressed: { id: 3, caption: "Suppressed" },
|
|
154
|
+
resolved: { id: 4, caption: "Resolved" },
|
|
155
|
+
};
|
|
156
|
+
const UNKNOWN_STATUS = { id: 0, caption: "Unknown" };
|
|
157
|
+
const VULNERABILITY_TYPE = { create: 200201, update: 200202, close: 200203 };
|
|
158
|
+
/** A scanner's finding as an OCSF 1.9.0 Vulnerability Finding. */
|
|
159
|
+
export function vulnerabilityFinding(v, options) {
|
|
160
|
+
const kind = options.activity ?? "create";
|
|
161
|
+
const activity = FINDING_ACTIVITY[kind];
|
|
162
|
+
const severity = v.severity === undefined ? UNKNOWN_SEVERITY : OCSF_SEVERITY[v.severity];
|
|
163
|
+
const status = v.status === undefined ? UNKNOWN_STATUS : VULNERABILITY_STATUS[v.status];
|
|
164
|
+
return {
|
|
165
|
+
class_uid: 2002,
|
|
166
|
+
class_name: "Vulnerability Finding",
|
|
167
|
+
category_uid: 2,
|
|
168
|
+
category_name: "Findings",
|
|
169
|
+
activity_id: activity.id,
|
|
170
|
+
activity_name: activity.name,
|
|
171
|
+
type_uid: VULNERABILITY_TYPE[kind],
|
|
172
|
+
type_name: `Vulnerability Finding: ${activity.name}`,
|
|
173
|
+
severity_id: severity.id,
|
|
174
|
+
severity: severity.caption,
|
|
175
|
+
status_id: status.id,
|
|
176
|
+
status: status.caption,
|
|
177
|
+
time: epochMs(options.at),
|
|
178
|
+
message: v.title,
|
|
179
|
+
metadata: metadataOf(options.product, options.metadata),
|
|
180
|
+
finding_info: { ...v.findingInfo, uid: v.uid, title: v.title },
|
|
181
|
+
vulnerabilities: v.vulnerabilities,
|
|
182
|
+
...(v.resources === undefined || v.resources.length === 0 ? {} : { resources: v.resources }),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function inventoryEnvelope(classUid, name, types, options) {
|
|
186
|
+
const kind = options.activity ?? "collect";
|
|
187
|
+
const activity = INVENTORY_ACTIVITY[kind];
|
|
188
|
+
return {
|
|
189
|
+
class_uid: classUid,
|
|
190
|
+
class_name: name,
|
|
191
|
+
category_uid: 5,
|
|
192
|
+
category_name: "Discovery",
|
|
193
|
+
activity_id: activity.id,
|
|
194
|
+
activity_name: activity.name,
|
|
195
|
+
type_uid: types[kind],
|
|
196
|
+
type_name: `${name}: ${activity.name}`,
|
|
197
|
+
severity_id: 1,
|
|
198
|
+
severity: "Informational",
|
|
199
|
+
time: epochMs(options.at),
|
|
200
|
+
metadata: metadataOf(options.product, options.metadata),
|
|
201
|
+
...(options.unmapped === undefined ? {} : { unmapped: options.unmapped }),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/** A device as an OCSF 1.9.0 Device Inventory Info event. */
|
|
205
|
+
export function deviceInventoryInfo(device, options) {
|
|
206
|
+
return { ...inventoryEnvelope(5001, "Device Inventory Info", { log: 500101, collect: 500102 }, options), device };
|
|
207
|
+
}
|
|
208
|
+
/** A user (a person, or an account in some system) as an OCSF 1.9.0 User Inventory Info event. */
|
|
209
|
+
export function userInventoryInfo(user, options) {
|
|
210
|
+
return { ...inventoryEnvelope(5003, "User Inventory Info", { log: 500301, collect: 500302 }, options), user };
|
|
211
|
+
}
|
|
212
|
+
/** Resources of a cloud or a service (a repository, a bucket, a tenant, ...) as an OCSF 1.9.0 Cloud Resources Inventory Info event. */
|
|
213
|
+
export function cloudResourcesInventoryInfo(resources, options) {
|
|
214
|
+
return { ...inventoryEnvelope(5023, "Cloud Resources Inventory Info", { log: 502301, collect: 502302 }, options), resources };
|
|
215
|
+
}
|
|
216
|
+
/** The device type captions, by `type_id`. */
|
|
217
|
+
export const OCSF_DEVICE_TYPE = {
|
|
218
|
+
0: "Unknown",
|
|
219
|
+
1: "Server",
|
|
220
|
+
2: "Desktop",
|
|
221
|
+
3: "Laptop",
|
|
222
|
+
4: "Tablet",
|
|
223
|
+
5: "Mobile",
|
|
224
|
+
6: "Virtual",
|
|
225
|
+
7: "IOT",
|
|
226
|
+
8: "Browser",
|
|
227
|
+
9: "Firewall",
|
|
228
|
+
10: "Switch",
|
|
229
|
+
11: "Hub",
|
|
230
|
+
12: "Router",
|
|
231
|
+
13: "IDS",
|
|
232
|
+
14: "IPS",
|
|
233
|
+
15: "Load Balancer",
|
|
234
|
+
99: "Other",
|
|
235
|
+
};
|
|
236
|
+
/** A subject of an assessment as a Device Inventory Info event: the device's uid is `kind:id`, and the subject's kind is its group. */
|
|
237
|
+
export function inventoryInfo(item, options) {
|
|
238
|
+
const typeId = item.type ?? 0;
|
|
239
|
+
return deviceInventoryInfo({
|
|
240
|
+
uid: `${item.subject.kind}:${item.subject.id}`,
|
|
241
|
+
name: item.name ?? item.subject.id,
|
|
242
|
+
type_id: typeId,
|
|
243
|
+
type: OCSF_DEVICE_TYPE[typeId],
|
|
244
|
+
...(item.hostname === undefined ? {} : { hostname: item.hostname }),
|
|
245
|
+
groups: [{ name: item.subject.kind }],
|
|
246
|
+
}, options);
|
|
247
|
+
}
|
|
248
|
+
/** The subjects of an assessment as Device Inventory Info events, in the order of their kinds and then ids, each subject once. */
|
|
249
|
+
export function inventory(items, options) {
|
|
250
|
+
const seen = new Map();
|
|
251
|
+
for (const item of items) {
|
|
252
|
+
const k = JSON.stringify([item.subject.kind, item.subject.id]);
|
|
253
|
+
if (!seen.has(k))
|
|
254
|
+
seen.set(k, item);
|
|
255
|
+
}
|
|
256
|
+
return [...seen.entries()].sort(([a], [b]) => byText(a, b)).map(([, item]) => inventoryInfo(item, options));
|
|
257
|
+
}
|