@absolutejs/vulnerabilities-postgres 0.8.0 → 0.9.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/README.md +11 -12
- package/dist/coreDrizzle.d.ts +3230 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +826 -145
- package/dist/manifest.js +40 -0
- package/dist/manifest.json +42 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// src/index.ts
|
|
3
3
|
import {
|
|
4
|
-
ManagedVulnerabilityFindingSchema,
|
|
5
|
-
RemediationExecutionSchema,
|
|
6
|
-
RemediationPlanSchema,
|
|
7
|
-
RemediationVerificationSchema,
|
|
8
|
-
VulnerabilityObservationSchema,
|
|
9
|
-
VulnerabilityRiskAssessmentSchema,
|
|
10
|
-
VexDecisionSchema,
|
|
11
|
-
VexFindingApplicationSchema
|
|
4
|
+
ManagedVulnerabilityFindingSchema as ManagedVulnerabilityFindingSchema2,
|
|
5
|
+
RemediationExecutionSchema as RemediationExecutionSchema2,
|
|
6
|
+
RemediationPlanSchema as RemediationPlanSchema2,
|
|
7
|
+
RemediationVerificationSchema as RemediationVerificationSchema2,
|
|
8
|
+
VulnerabilityObservationSchema as VulnerabilityObservationSchema2,
|
|
9
|
+
VulnerabilityRiskAssessmentSchema as VulnerabilityRiskAssessmentSchema2,
|
|
10
|
+
VexDecisionSchema as VexDecisionSchema2,
|
|
11
|
+
VexFindingApplicationSchema as VexFindingApplicationSchema2
|
|
12
12
|
} from "@absolutejs/vulnerabilities";
|
|
13
|
-
import { Value } from "@sinclair/typebox/value";
|
|
13
|
+
import { Value as Value2 } from "@sinclair/typebox/value";
|
|
14
14
|
|
|
15
15
|
// src/alerts.ts
|
|
16
16
|
import {
|
|
@@ -338,6 +338,30 @@ var createPostgresVulnerabilityAlertStores = (options) => {
|
|
|
338
338
|
};
|
|
339
339
|
return { alertIncidents, alertPolicies, ensureAlertSchema };
|
|
340
340
|
};
|
|
341
|
+
// src/coreDrizzle.ts
|
|
342
|
+
import {
|
|
343
|
+
ManagedVulnerabilityFindingSchema,
|
|
344
|
+
RemediationExecutionSchema,
|
|
345
|
+
RemediationPlanSchema,
|
|
346
|
+
RemediationVerificationSchema,
|
|
347
|
+
VexDecisionSchema,
|
|
348
|
+
VexFindingApplicationSchema,
|
|
349
|
+
VulnerabilityObservationSchema,
|
|
350
|
+
VulnerabilityRiskAssessmentSchema
|
|
351
|
+
} from "@absolutejs/vulnerabilities";
|
|
352
|
+
import { Value } from "@sinclair/typebox/value";
|
|
353
|
+
import { and as and2, desc as desc2, eq as eq2, lte as lte2, notInArray, or as or2, sql as sql2 } from "drizzle-orm";
|
|
354
|
+
import {
|
|
355
|
+
check,
|
|
356
|
+
index as index2,
|
|
357
|
+
integer as integer2,
|
|
358
|
+
jsonb,
|
|
359
|
+
pgTable as pgTable2,
|
|
360
|
+
primaryKey as primaryKey2,
|
|
361
|
+
text as text2,
|
|
362
|
+
timestamp as timestamp2
|
|
363
|
+
} from "drizzle-orm/pg-core";
|
|
364
|
+
|
|
341
365
|
// src/drizzle.ts
|
|
342
366
|
import { and, asc, desc, eq, inArray, lte, max, or, sql } from "drizzle-orm";
|
|
343
367
|
import {
|
|
@@ -810,6 +834,649 @@ var createDrizzleVulnerabilityAlertStores = (db) => {
|
|
|
810
834
|
return { alertIncidents, alertPolicies };
|
|
811
835
|
};
|
|
812
836
|
|
|
837
|
+
// src/coreDrizzle.ts
|
|
838
|
+
var encodedJsonb2 = (value) => sql2`${JSON.stringify(value)}::text::jsonb`;
|
|
839
|
+
var databaseNow2 = sql2`now()`;
|
|
840
|
+
var requiredText = (value, label) => {
|
|
841
|
+
const normalized = value.trim();
|
|
842
|
+
if (normalized.length === 0)
|
|
843
|
+
throw new Error(`${label} is required`);
|
|
844
|
+
return normalized;
|
|
845
|
+
};
|
|
846
|
+
var boundedLimit3 = (value, fallback = 100) => {
|
|
847
|
+
const normalized = value ?? fallback;
|
|
848
|
+
if (!Number.isInteger(normalized) || normalized < 1 || normalized > 1000)
|
|
849
|
+
throw new Error("Postgres query limit must be an integer from 1 through 1000");
|
|
850
|
+
return normalized;
|
|
851
|
+
};
|
|
852
|
+
var valid = (schema, value, label) => {
|
|
853
|
+
if (!Value.Check(schema, value))
|
|
854
|
+
throw new Error(`${label} is invalid`);
|
|
855
|
+
return value;
|
|
856
|
+
};
|
|
857
|
+
var iso = (value) => value.toISOString();
|
|
858
|
+
var vulnerabilityFeedSnapshots = pgTable2("vulnerability_feed_snapshots", {
|
|
859
|
+
cursor: jsonb().$type().notNull(),
|
|
860
|
+
feed_id: text2().primaryKey(),
|
|
861
|
+
feed_name: text2().notNull(),
|
|
862
|
+
feed_url: text2().notNull(),
|
|
863
|
+
fetched_at: timestamp2({ mode: "date", withTimezone: true }).notNull(),
|
|
864
|
+
revision: text2(),
|
|
865
|
+
updated_at: timestamp2({ mode: "date", withTimezone: true }).notNull().defaultNow()
|
|
866
|
+
});
|
|
867
|
+
var vulnerabilityFeedRecords = pgTable2("vulnerability_feed_records", {
|
|
868
|
+
feed_id: text2().notNull().references(() => vulnerabilityFeedSnapshots.feed_id, {
|
|
869
|
+
onDelete: "cascade"
|
|
870
|
+
}),
|
|
871
|
+
modified_at: timestamp2({ mode: "date", withTimezone: true }).notNull(),
|
|
872
|
+
record_id: text2().notNull(),
|
|
873
|
+
value: jsonb().notNull()
|
|
874
|
+
}, (table) => [
|
|
875
|
+
primaryKey2({ columns: [table.feed_id, table.record_id] }),
|
|
876
|
+
index2("vulnerability_feed_records_modified_idx").on(table.feed_id, table.modified_at)
|
|
877
|
+
]);
|
|
878
|
+
var vulnerabilityFeedSyncRuns = pgTable2("vulnerability_feed_sync_runs", {
|
|
879
|
+
completed_at: timestamp2({ mode: "date", withTimezone: true }).notNull(),
|
|
880
|
+
error: text2(),
|
|
881
|
+
feed_id: text2().notNull(),
|
|
882
|
+
id: text2().primaryKey(),
|
|
883
|
+
records: integer2().notNull(),
|
|
884
|
+
revision: text2(),
|
|
885
|
+
started_at: timestamp2({ mode: "date", withTimezone: true }).notNull(),
|
|
886
|
+
status: text2().$type().notNull()
|
|
887
|
+
}, (table) => [
|
|
888
|
+
check("vulnerability_feed_sync_runs_records_check", sql2`${table.records} >= 0`),
|
|
889
|
+
check("vulnerability_feed_sync_runs_status_check", sql2`${table.status} IN ('failed', 'not_modified', 'stale', 'updated')`),
|
|
890
|
+
index2("vulnerability_feed_sync_runs_feed_started_idx").on(table.feed_id, table.started_at),
|
|
891
|
+
index2("vulnerability_feed_sync_runs_status_started_idx").on(table.status, table.started_at)
|
|
892
|
+
]);
|
|
893
|
+
var vulnerabilityFindings = pgTable2("vulnerability_findings", {
|
|
894
|
+
asset_id: text2().notNull(),
|
|
895
|
+
component_id: text2().notNull(),
|
|
896
|
+
finding_id: text2().notNull(),
|
|
897
|
+
first_seen_at: timestamp2({
|
|
898
|
+
mode: "date",
|
|
899
|
+
withTimezone: true
|
|
900
|
+
}).notNull(),
|
|
901
|
+
last_seen_at: timestamp2({ mode: "date", withTimezone: true }).notNull(),
|
|
902
|
+
severity: text2().notNull(),
|
|
903
|
+
status: text2().notNull(),
|
|
904
|
+
tenant_id: text2().notNull(),
|
|
905
|
+
updated_at: timestamp2({ mode: "date", withTimezone: true }).notNull().defaultNow(),
|
|
906
|
+
value: jsonb().$type().notNull()
|
|
907
|
+
}, (table) => [
|
|
908
|
+
primaryKey2({ columns: [table.tenant_id, table.finding_id] }),
|
|
909
|
+
index2("vulnerability_findings_tenant_status_idx").on(table.tenant_id, table.status, table.last_seen_at),
|
|
910
|
+
index2("vulnerability_findings_tenant_severity_idx").on(table.tenant_id, table.severity, table.last_seen_at),
|
|
911
|
+
index2("vulnerability_findings_tenant_asset_idx").on(table.tenant_id, table.asset_id, table.last_seen_at)
|
|
912
|
+
]);
|
|
913
|
+
var vulnerabilityObservations = pgTable2("vulnerability_observations", {
|
|
914
|
+
asset_id: text2().notNull(),
|
|
915
|
+
component_id: text2().notNull(),
|
|
916
|
+
observation_id: text2().notNull(),
|
|
917
|
+
observed_at: timestamp2({ mode: "date", withTimezone: true }).notNull(),
|
|
918
|
+
tenant_id: text2().notNull(),
|
|
919
|
+
updated_at: timestamp2({ mode: "date", withTimezone: true }).notNull().defaultNow(),
|
|
920
|
+
value: jsonb().$type().notNull()
|
|
921
|
+
}, (table) => [
|
|
922
|
+
primaryKey2({ columns: [table.tenant_id, table.observation_id] }),
|
|
923
|
+
index2("vulnerability_observations_tenant_asset_idx").on(table.tenant_id, table.asset_id, table.observed_at),
|
|
924
|
+
index2("vulnerability_observations_tenant_component_idx").on(table.tenant_id, table.component_id, table.observed_at)
|
|
925
|
+
]);
|
|
926
|
+
var vulnerabilityRiskAssessments = pgTable2("vulnerability_risk_assessments", {
|
|
927
|
+
assessed_at: timestamp2({ mode: "date", withTimezone: true }).notNull(),
|
|
928
|
+
finding_id: text2().notNull(),
|
|
929
|
+
priority: text2().notNull(),
|
|
930
|
+
remediate_by: timestamp2({ mode: "date", withTimezone: true }),
|
|
931
|
+
tenant_id: text2().notNull(),
|
|
932
|
+
updated_at: timestamp2({ mode: "date", withTimezone: true }).notNull().defaultNow(),
|
|
933
|
+
value: jsonb().$type().notNull()
|
|
934
|
+
}, (table) => [
|
|
935
|
+
primaryKey2({ columns: [table.tenant_id, table.finding_id] }),
|
|
936
|
+
index2("vulnerability_risk_assessments_tenant_priority_idx").on(table.tenant_id, table.priority, table.assessed_at),
|
|
937
|
+
index2("vulnerability_risk_assessments_tenant_due_idx").on(table.tenant_id, table.remediate_by).where(sql2`${table.remediate_by} IS NOT NULL`)
|
|
938
|
+
]);
|
|
939
|
+
var vulnerabilityRemediationPlans = pgTable2("vulnerability_remediation_plans", {
|
|
940
|
+
created_at: timestamp2({ mode: "date", withTimezone: true }).notNull(),
|
|
941
|
+
plan_id: text2().notNull(),
|
|
942
|
+
status: text2().notNull(),
|
|
943
|
+
tenant_id: text2().notNull(),
|
|
944
|
+
updated_at: timestamp2({ mode: "date", withTimezone: true }).notNull().defaultNow(),
|
|
945
|
+
value: jsonb().$type().notNull()
|
|
946
|
+
}, (table) => [
|
|
947
|
+
primaryKey2({ columns: [table.tenant_id, table.plan_id] }),
|
|
948
|
+
index2("vulnerability_remediation_plans_tenant_status_idx").on(table.tenant_id, table.status, table.created_at)
|
|
949
|
+
]);
|
|
950
|
+
var vulnerabilityRemediationExecutions = pgTable2("vulnerability_remediation_executions", {
|
|
951
|
+
completed_at: timestamp2({ mode: "date", withTimezone: true }),
|
|
952
|
+
execution_id: text2().notNull(),
|
|
953
|
+
plan_id: text2().notNull(),
|
|
954
|
+
started_at: timestamp2({ mode: "date", withTimezone: true }).notNull(),
|
|
955
|
+
status: text2().notNull(),
|
|
956
|
+
tenant_id: text2().notNull(),
|
|
957
|
+
updated_at: timestamp2({ mode: "date", withTimezone: true }).notNull().defaultNow(),
|
|
958
|
+
value: jsonb().$type().notNull()
|
|
959
|
+
}, (table) => [
|
|
960
|
+
primaryKey2({ columns: [table.tenant_id, table.execution_id] }),
|
|
961
|
+
index2("vulnerability_remediation_executions_tenant_plan_idx").on(table.tenant_id, table.plan_id, table.started_at)
|
|
962
|
+
]);
|
|
963
|
+
var vulnerabilityRemediationVerifications = pgTable2("vulnerability_remediation_verifications", {
|
|
964
|
+
execution_id: text2().notNull(),
|
|
965
|
+
observed_at: timestamp2({ mode: "date", withTimezone: true }).notNull(),
|
|
966
|
+
plan_id: text2().notNull(),
|
|
967
|
+
status: text2().notNull(),
|
|
968
|
+
tenant_id: text2().notNull(),
|
|
969
|
+
updated_at: timestamp2({ mode: "date", withTimezone: true }).notNull().defaultNow(),
|
|
970
|
+
value: jsonb().$type().notNull(),
|
|
971
|
+
verification_id: text2().notNull()
|
|
972
|
+
}, (table) => [
|
|
973
|
+
primaryKey2({ columns: [table.tenant_id, table.verification_id] }),
|
|
974
|
+
index2("vulnerability_remediation_verifications_tenant_execution_idx").on(table.tenant_id, table.execution_id, table.observed_at)
|
|
975
|
+
]);
|
|
976
|
+
var vulnerabilityVexDecisions = pgTable2("vulnerability_vex_decisions", {
|
|
977
|
+
created_at: timestamp2({ mode: "date", withTimezone: true }).notNull(),
|
|
978
|
+
decision_id: text2().notNull(),
|
|
979
|
+
expires_at: timestamp2({ mode: "date", withTimezone: true }),
|
|
980
|
+
product_id: text2().notNull(),
|
|
981
|
+
status: text2().notNull(),
|
|
982
|
+
tenant_id: text2().notNull(),
|
|
983
|
+
updated_at: timestamp2({ mode: "date", withTimezone: true }).notNull().defaultNow(),
|
|
984
|
+
value: jsonb().$type().notNull(),
|
|
985
|
+
vulnerability_id: text2().notNull()
|
|
986
|
+
}, (table) => [
|
|
987
|
+
primaryKey2({ columns: [table.tenant_id, table.decision_id] }),
|
|
988
|
+
index2("vulnerability_vex_decisions_tenant_product_idx").on(table.tenant_id, table.product_id, table.created_at),
|
|
989
|
+
index2("vulnerability_vex_decisions_tenant_vulnerability_idx").on(table.tenant_id, table.vulnerability_id, table.created_at)
|
|
990
|
+
]);
|
|
991
|
+
var vulnerabilityVexApplications = pgTable2("vulnerability_vex_applications", {
|
|
992
|
+
applied_at: timestamp2({ mode: "date", withTimezone: true }).notNull(),
|
|
993
|
+
decision_id: text2().notNull(),
|
|
994
|
+
ended_at: timestamp2({ mode: "date", withTimezone: true }),
|
|
995
|
+
finding_id: text2().notNull(),
|
|
996
|
+
tenant_id: text2().notNull(),
|
|
997
|
+
updated_at: timestamp2({ mode: "date", withTimezone: true }).notNull().defaultNow(),
|
|
998
|
+
value: jsonb().$type().notNull()
|
|
999
|
+
}, (table) => [
|
|
1000
|
+
primaryKey2({ columns: [table.tenant_id, table.finding_id] }),
|
|
1001
|
+
index2("vulnerability_vex_applications_tenant_decision_idx").on(table.tenant_id, table.decision_id, table.applied_at)
|
|
1002
|
+
]);
|
|
1003
|
+
var vulnerabilityFeedLeases = pgTable2("vulnerability_feed_leases", {
|
|
1004
|
+
expires_at: timestamp2({ mode: "date", withTimezone: true }).notNull(),
|
|
1005
|
+
feed_id: text2().primaryKey(),
|
|
1006
|
+
owner_id: text2().notNull(),
|
|
1007
|
+
updated_at: timestamp2({ mode: "date", withTimezone: true }).notNull().defaultNow()
|
|
1008
|
+
});
|
|
1009
|
+
var vulnerabilityCoreDrizzleSchema = {
|
|
1010
|
+
vulnerabilityFeedLeases,
|
|
1011
|
+
vulnerabilityFeedRecords,
|
|
1012
|
+
vulnerabilityFeedSnapshots,
|
|
1013
|
+
vulnerabilityFeedSyncRuns,
|
|
1014
|
+
vulnerabilityFindings,
|
|
1015
|
+
vulnerabilityObservations,
|
|
1016
|
+
vulnerabilityRemediationExecutions,
|
|
1017
|
+
vulnerabilityRemediationPlans,
|
|
1018
|
+
vulnerabilityRemediationVerifications,
|
|
1019
|
+
vulnerabilityRiskAssessments,
|
|
1020
|
+
vulnerabilityVexApplications,
|
|
1021
|
+
vulnerabilityVexDecisions
|
|
1022
|
+
};
|
|
1023
|
+
var createDrizzleVulnerabilityStore = (db) => {
|
|
1024
|
+
const alertStores = createDrizzleVulnerabilityAlertStores(db);
|
|
1025
|
+
const snapshots = () => ({
|
|
1026
|
+
load: async (feedId) => {
|
|
1027
|
+
const id = requiredText(feedId, "Feed id");
|
|
1028
|
+
const [snapshot] = await db.select().from(vulnerabilityFeedSnapshots).where(eq2(vulnerabilityFeedSnapshots.feed_id, id)).limit(1);
|
|
1029
|
+
if (!snapshot)
|
|
1030
|
+
return null;
|
|
1031
|
+
const records = await db.select().from(vulnerabilityFeedRecords).where(eq2(vulnerabilityFeedRecords.feed_id, id)).orderBy(vulnerabilityFeedRecords.record_id);
|
|
1032
|
+
return {
|
|
1033
|
+
cursor: snapshot.cursor,
|
|
1034
|
+
feed: {
|
|
1035
|
+
id: snapshot.feed_id,
|
|
1036
|
+
name: snapshot.feed_name,
|
|
1037
|
+
url: snapshot.feed_url
|
|
1038
|
+
},
|
|
1039
|
+
fetchedAt: iso(snapshot.fetched_at),
|
|
1040
|
+
records: records.map((record) => ({
|
|
1041
|
+
id: record.record_id,
|
|
1042
|
+
modifiedAt: iso(record.modified_at),
|
|
1043
|
+
value: record.value
|
|
1044
|
+
})),
|
|
1045
|
+
revision: snapshot.revision
|
|
1046
|
+
};
|
|
1047
|
+
},
|
|
1048
|
+
save: async (snapshot) => {
|
|
1049
|
+
const feedId = requiredText(snapshot.feed.id, "Feed id");
|
|
1050
|
+
await db.transaction(async (transaction2) => {
|
|
1051
|
+
await transaction2.insert(vulnerabilityFeedSnapshots).values({
|
|
1052
|
+
cursor: encodedJsonb2(snapshot.cursor),
|
|
1053
|
+
feed_id: feedId,
|
|
1054
|
+
feed_name: requiredText(snapshot.feed.name, "Feed name"),
|
|
1055
|
+
feed_url: requiredText(snapshot.feed.url, "Feed URL"),
|
|
1056
|
+
fetched_at: new Date(snapshot.fetchedAt),
|
|
1057
|
+
revision: snapshot.revision,
|
|
1058
|
+
updated_at: databaseNow2
|
|
1059
|
+
}).onConflictDoUpdate({
|
|
1060
|
+
set: {
|
|
1061
|
+
cursor: encodedJsonb2(snapshot.cursor),
|
|
1062
|
+
feed_name: requiredText(snapshot.feed.name, "Feed name"),
|
|
1063
|
+
feed_url: requiredText(snapshot.feed.url, "Feed URL"),
|
|
1064
|
+
fetched_at: new Date(snapshot.fetchedAt),
|
|
1065
|
+
revision: snapshot.revision,
|
|
1066
|
+
updated_at: databaseNow2
|
|
1067
|
+
},
|
|
1068
|
+
target: vulnerabilityFeedSnapshots.feed_id
|
|
1069
|
+
});
|
|
1070
|
+
const recordIds = snapshot.records.map((record) => requiredText(record.id, "Feed record id"));
|
|
1071
|
+
await transaction2.delete(vulnerabilityFeedRecords).where(and2(eq2(vulnerabilityFeedRecords.feed_id, feedId), recordIds.length === 0 ? undefined : notInArray(vulnerabilityFeedRecords.record_id, recordIds)));
|
|
1072
|
+
if (snapshot.records.length > 0)
|
|
1073
|
+
await transaction2.insert(vulnerabilityFeedRecords).values(snapshot.records.map((record) => ({
|
|
1074
|
+
feed_id: feedId,
|
|
1075
|
+
modified_at: new Date(record.modifiedAt),
|
|
1076
|
+
record_id: requiredText(record.id, "Feed record id"),
|
|
1077
|
+
value: encodedJsonb2(record.value)
|
|
1078
|
+
}))).onConflictDoUpdate({
|
|
1079
|
+
set: {
|
|
1080
|
+
modified_at: sql2`excluded.modified_at`,
|
|
1081
|
+
value: sql2`excluded.value`
|
|
1082
|
+
},
|
|
1083
|
+
target: [
|
|
1084
|
+
vulnerabilityFeedRecords.feed_id,
|
|
1085
|
+
vulnerabilityFeedRecords.record_id
|
|
1086
|
+
]
|
|
1087
|
+
});
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
1090
|
+
});
|
|
1091
|
+
const syncRuns = {
|
|
1092
|
+
append: async (run) => {
|
|
1093
|
+
if (!Number.isInteger(run.records) || run.records < 0)
|
|
1094
|
+
throw new Error("Feed sync records must be a non-negative integer");
|
|
1095
|
+
await db.insert(vulnerabilityFeedSyncRuns).values({
|
|
1096
|
+
completed_at: new Date(run.completedAt),
|
|
1097
|
+
error: run.error,
|
|
1098
|
+
feed_id: requiredText(run.feedId, "Feed sync feed id"),
|
|
1099
|
+
id: requiredText(run.id, "Feed sync run id"),
|
|
1100
|
+
records: run.records,
|
|
1101
|
+
revision: run.revision,
|
|
1102
|
+
started_at: new Date(run.startedAt),
|
|
1103
|
+
status: run.status
|
|
1104
|
+
}).onConflictDoUpdate({
|
|
1105
|
+
set: {
|
|
1106
|
+
completed_at: new Date(run.completedAt),
|
|
1107
|
+
error: run.error,
|
|
1108
|
+
feed_id: requiredText(run.feedId, "Feed sync feed id"),
|
|
1109
|
+
records: run.records,
|
|
1110
|
+
revision: run.revision,
|
|
1111
|
+
started_at: new Date(run.startedAt),
|
|
1112
|
+
status: run.status
|
|
1113
|
+
},
|
|
1114
|
+
target: vulnerabilityFeedSyncRuns.id
|
|
1115
|
+
});
|
|
1116
|
+
},
|
|
1117
|
+
list: async (filter = {}) => {
|
|
1118
|
+
const rows = await db.select().from(vulnerabilityFeedSyncRuns).where(and2(filter.feedId ? eq2(vulnerabilityFeedSyncRuns.feed_id, filter.feedId.trim()) : undefined, filter.status ? eq2(vulnerabilityFeedSyncRuns.status, filter.status) : undefined)).orderBy(desc2(vulnerabilityFeedSyncRuns.started_at), desc2(vulnerabilityFeedSyncRuns.id)).limit(boundedLimit3(filter.limit));
|
|
1119
|
+
return rows.map((row) => ({
|
|
1120
|
+
completedAt: iso(row.completed_at),
|
|
1121
|
+
error: row.error,
|
|
1122
|
+
feedId: row.feed_id,
|
|
1123
|
+
id: row.id,
|
|
1124
|
+
records: row.records,
|
|
1125
|
+
revision: row.revision,
|
|
1126
|
+
startedAt: iso(row.started_at),
|
|
1127
|
+
status: row.status
|
|
1128
|
+
}));
|
|
1129
|
+
}
|
|
1130
|
+
};
|
|
1131
|
+
const saveFindings = async (findings2) => {
|
|
1132
|
+
if (findings2.length === 0)
|
|
1133
|
+
return;
|
|
1134
|
+
for (const finding of findings2)
|
|
1135
|
+
valid(ManagedVulnerabilityFindingSchema, finding, `Managed finding ${finding.id}`);
|
|
1136
|
+
await db.insert(vulnerabilityFindings).values(findings2.map((finding) => ({
|
|
1137
|
+
asset_id: finding.assetId,
|
|
1138
|
+
component_id: finding.componentId,
|
|
1139
|
+
finding_id: finding.id,
|
|
1140
|
+
first_seen_at: new Date(finding.firstSeenAt),
|
|
1141
|
+
last_seen_at: new Date(finding.lastSeenAt),
|
|
1142
|
+
severity: finding.severity,
|
|
1143
|
+
status: finding.status,
|
|
1144
|
+
tenant_id: finding.tenantId,
|
|
1145
|
+
value: encodedJsonb2(finding)
|
|
1146
|
+
}))).onConflictDoUpdate({
|
|
1147
|
+
set: {
|
|
1148
|
+
asset_id: sql2`excluded.asset_id`,
|
|
1149
|
+
component_id: sql2`excluded.component_id`,
|
|
1150
|
+
first_seen_at: sql2`least(${vulnerabilityFindings.first_seen_at}, excluded.first_seen_at)`,
|
|
1151
|
+
last_seen_at: sql2`greatest(${vulnerabilityFindings.last_seen_at}, excluded.last_seen_at)`,
|
|
1152
|
+
severity: sql2`excluded.severity`,
|
|
1153
|
+
status: sql2`excluded.status`,
|
|
1154
|
+
updated_at: databaseNow2,
|
|
1155
|
+
value: sql2`excluded.value`
|
|
1156
|
+
},
|
|
1157
|
+
target: [
|
|
1158
|
+
vulnerabilityFindings.tenant_id,
|
|
1159
|
+
vulnerabilityFindings.finding_id
|
|
1160
|
+
]
|
|
1161
|
+
});
|
|
1162
|
+
};
|
|
1163
|
+
const findings = {
|
|
1164
|
+
get: async (tenantId, findingId) => {
|
|
1165
|
+
const [row] = await db.select({ value: vulnerabilityFindings.value }).from(vulnerabilityFindings).where(and2(eq2(vulnerabilityFindings.tenant_id, requiredText(tenantId, "Tenant id")), eq2(vulnerabilityFindings.finding_id, requiredText(findingId, "Finding id")))).limit(1);
|
|
1166
|
+
return row ? valid(ManagedVulnerabilityFindingSchema, row.value, "Stored managed finding") : null;
|
|
1167
|
+
},
|
|
1168
|
+
list: async (filter) => {
|
|
1169
|
+
const rows = await db.select({ value: vulnerabilityFindings.value }).from(vulnerabilityFindings).where(and2(eq2(vulnerabilityFindings.tenant_id, requiredText(filter.tenantId, "Tenant id")), filter.assetId ? eq2(vulnerabilityFindings.asset_id, filter.assetId.trim()) : undefined, filter.severity ? eq2(vulnerabilityFindings.severity, filter.severity) : undefined, filter.status ? eq2(vulnerabilityFindings.status, filter.status) : undefined)).orderBy(desc2(vulnerabilityFindings.last_seen_at), vulnerabilityFindings.finding_id).limit(boundedLimit3(filter.limit));
|
|
1170
|
+
return rows.map(({ value }) => valid(ManagedVulnerabilityFindingSchema, value, "Stored managed finding"));
|
|
1171
|
+
},
|
|
1172
|
+
save: async (finding) => saveFindings([finding]),
|
|
1173
|
+
saveMany: saveFindings
|
|
1174
|
+
};
|
|
1175
|
+
const saveObservations = async (tenantId, observations2) => {
|
|
1176
|
+
if (observations2.length === 0)
|
|
1177
|
+
return;
|
|
1178
|
+
const normalizedTenantId = requiredText(tenantId, "Tenant id");
|
|
1179
|
+
for (const observation of observations2)
|
|
1180
|
+
valid(VulnerabilityObservationSchema, observation, `Vulnerability observation ${observation.id}`);
|
|
1181
|
+
await db.insert(vulnerabilityObservations).values(observations2.map((observation) => ({
|
|
1182
|
+
asset_id: observation.assetId,
|
|
1183
|
+
component_id: observation.componentId,
|
|
1184
|
+
observation_id: observation.id,
|
|
1185
|
+
observed_at: new Date(observation.observedAt),
|
|
1186
|
+
tenant_id: normalizedTenantId,
|
|
1187
|
+
value: encodedJsonb2(observation)
|
|
1188
|
+
}))).onConflictDoUpdate({
|
|
1189
|
+
set: {
|
|
1190
|
+
asset_id: sql2`excluded.asset_id`,
|
|
1191
|
+
component_id: sql2`excluded.component_id`,
|
|
1192
|
+
observed_at: sql2`excluded.observed_at`,
|
|
1193
|
+
updated_at: databaseNow2,
|
|
1194
|
+
value: sql2`excluded.value`
|
|
1195
|
+
},
|
|
1196
|
+
target: [
|
|
1197
|
+
vulnerabilityObservations.tenant_id,
|
|
1198
|
+
vulnerabilityObservations.observation_id
|
|
1199
|
+
]
|
|
1200
|
+
});
|
|
1201
|
+
};
|
|
1202
|
+
const observations = {
|
|
1203
|
+
get: async (tenantId, observationId) => {
|
|
1204
|
+
const [row] = await db.select({ value: vulnerabilityObservations.value }).from(vulnerabilityObservations).where(and2(eq2(vulnerabilityObservations.tenant_id, requiredText(tenantId, "Tenant id")), eq2(vulnerabilityObservations.observation_id, requiredText(observationId, "Observation id")))).limit(1);
|
|
1205
|
+
return row ? valid(VulnerabilityObservationSchema, row.value, "Stored vulnerability observation") : null;
|
|
1206
|
+
},
|
|
1207
|
+
list: async (filter) => {
|
|
1208
|
+
const rows = await db.select({ value: vulnerabilityObservations.value }).from(vulnerabilityObservations).where(and2(eq2(vulnerabilityObservations.tenant_id, requiredText(filter.tenantId, "Tenant id")), filter.assetId ? eq2(vulnerabilityObservations.asset_id, filter.assetId.trim()) : undefined, filter.componentId ? eq2(vulnerabilityObservations.component_id, filter.componentId.trim()) : undefined)).orderBy(desc2(vulnerabilityObservations.observed_at), vulnerabilityObservations.observation_id).limit(boundedLimit3(filter.limit));
|
|
1209
|
+
return rows.map(({ value }) => valid(VulnerabilityObservationSchema, value, "Stored vulnerability observation"));
|
|
1210
|
+
},
|
|
1211
|
+
save: async (tenantId, observation) => saveObservations(tenantId, [observation]),
|
|
1212
|
+
saveMany: saveObservations
|
|
1213
|
+
};
|
|
1214
|
+
const saveRiskAssessments = async (tenantId, assessments) => {
|
|
1215
|
+
if (assessments.length === 0)
|
|
1216
|
+
return;
|
|
1217
|
+
const normalizedTenantId = requiredText(tenantId, "Tenant id");
|
|
1218
|
+
for (const assessment of assessments)
|
|
1219
|
+
valid(VulnerabilityRiskAssessmentSchema, assessment, `Vulnerability risk assessment ${assessment.findingId}`);
|
|
1220
|
+
await db.insert(vulnerabilityRiskAssessments).values(assessments.map((assessment) => ({
|
|
1221
|
+
assessed_at: new Date(assessment.assessedAt),
|
|
1222
|
+
finding_id: assessment.findingId,
|
|
1223
|
+
priority: assessment.priority,
|
|
1224
|
+
remediate_by: assessment.remediateBy ? new Date(assessment.remediateBy) : null,
|
|
1225
|
+
tenant_id: normalizedTenantId,
|
|
1226
|
+
value: encodedJsonb2(assessment)
|
|
1227
|
+
}))).onConflictDoUpdate({
|
|
1228
|
+
set: {
|
|
1229
|
+
assessed_at: sql2`excluded.assessed_at`,
|
|
1230
|
+
priority: sql2`excluded.priority`,
|
|
1231
|
+
remediate_by: sql2`excluded.remediate_by`,
|
|
1232
|
+
updated_at: databaseNow2,
|
|
1233
|
+
value: sql2`excluded.value`
|
|
1234
|
+
},
|
|
1235
|
+
target: [
|
|
1236
|
+
vulnerabilityRiskAssessments.tenant_id,
|
|
1237
|
+
vulnerabilityRiskAssessments.finding_id
|
|
1238
|
+
]
|
|
1239
|
+
});
|
|
1240
|
+
};
|
|
1241
|
+
const riskAssessments = {
|
|
1242
|
+
get: async (tenantId, findingId) => {
|
|
1243
|
+
const [row] = await db.select({ value: vulnerabilityRiskAssessments.value }).from(vulnerabilityRiskAssessments).where(and2(eq2(vulnerabilityRiskAssessments.tenant_id, requiredText(tenantId, "Tenant id")), eq2(vulnerabilityRiskAssessments.finding_id, requiredText(findingId, "Finding id")))).limit(1);
|
|
1244
|
+
return row ? valid(VulnerabilityRiskAssessmentSchema, row.value, "Stored vulnerability risk assessment") : null;
|
|
1245
|
+
},
|
|
1246
|
+
list: async (filter) => {
|
|
1247
|
+
const rows = await db.select({ value: vulnerabilityRiskAssessments.value }).from(vulnerabilityRiskAssessments).where(and2(eq2(vulnerabilityRiskAssessments.tenant_id, requiredText(filter.tenantId, "Tenant id")), filter.priority ? eq2(vulnerabilityRiskAssessments.priority, filter.priority) : undefined)).orderBy(desc2(vulnerabilityRiskAssessments.assessed_at), vulnerabilityRiskAssessments.finding_id).limit(boundedLimit3(filter.limit));
|
|
1248
|
+
return rows.map(({ value }) => valid(VulnerabilityRiskAssessmentSchema, value, "Stored vulnerability risk assessment"));
|
|
1249
|
+
},
|
|
1250
|
+
save: async (tenantId, assessment) => saveRiskAssessments(tenantId, [assessment]),
|
|
1251
|
+
saveMany: saveRiskAssessments
|
|
1252
|
+
};
|
|
1253
|
+
const remediationPlans = {
|
|
1254
|
+
get: async (tenantId, planId) => {
|
|
1255
|
+
const [row] = await db.select({ value: vulnerabilityRemediationPlans.value }).from(vulnerabilityRemediationPlans).where(and2(eq2(vulnerabilityRemediationPlans.tenant_id, requiredText(tenantId, "Tenant id")), eq2(vulnerabilityRemediationPlans.plan_id, requiredText(planId, "Remediation plan id")))).limit(1);
|
|
1256
|
+
return row ? valid(RemediationPlanSchema, row.value, "Stored remediation plan") : null;
|
|
1257
|
+
},
|
|
1258
|
+
list: async (filter) => {
|
|
1259
|
+
const rows = await db.select({ value: vulnerabilityRemediationPlans.value }).from(vulnerabilityRemediationPlans).where(and2(eq2(vulnerabilityRemediationPlans.tenant_id, requiredText(filter.tenantId, "Tenant id")), filter.status ? eq2(vulnerabilityRemediationPlans.status, filter.status) : undefined)).orderBy(desc2(vulnerabilityRemediationPlans.created_at), vulnerabilityRemediationPlans.plan_id).limit(boundedLimit3(filter.limit));
|
|
1260
|
+
return rows.map(({ value }) => valid(RemediationPlanSchema, value, "Stored remediation plan"));
|
|
1261
|
+
},
|
|
1262
|
+
save: async (tenantId, plan) => {
|
|
1263
|
+
valid(RemediationPlanSchema, plan, `Remediation plan ${plan.id}`);
|
|
1264
|
+
await db.insert(vulnerabilityRemediationPlans).values({
|
|
1265
|
+
created_at: new Date(plan.createdAt),
|
|
1266
|
+
plan_id: plan.id,
|
|
1267
|
+
status: plan.status,
|
|
1268
|
+
tenant_id: requiredText(tenantId, "Tenant id"),
|
|
1269
|
+
value: encodedJsonb2(plan)
|
|
1270
|
+
}).onConflictDoUpdate({
|
|
1271
|
+
set: {
|
|
1272
|
+
created_at: new Date(plan.createdAt),
|
|
1273
|
+
status: plan.status,
|
|
1274
|
+
updated_at: databaseNow2,
|
|
1275
|
+
value: encodedJsonb2(plan)
|
|
1276
|
+
},
|
|
1277
|
+
target: [
|
|
1278
|
+
vulnerabilityRemediationPlans.tenant_id,
|
|
1279
|
+
vulnerabilityRemediationPlans.plan_id
|
|
1280
|
+
]
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
};
|
|
1284
|
+
const remediationExecutions = {
|
|
1285
|
+
get: async (tenantId, executionId) => {
|
|
1286
|
+
const [row] = await db.select({ value: vulnerabilityRemediationExecutions.value }).from(vulnerabilityRemediationExecutions).where(and2(eq2(vulnerabilityRemediationExecutions.tenant_id, requiredText(tenantId, "Tenant id")), eq2(vulnerabilityRemediationExecutions.execution_id, requiredText(executionId, "Remediation execution id")))).limit(1);
|
|
1287
|
+
return row ? valid(RemediationExecutionSchema, row.value, "Stored remediation execution") : null;
|
|
1288
|
+
},
|
|
1289
|
+
list: async (tenantId, planId) => {
|
|
1290
|
+
const rows = await db.select({ value: vulnerabilityRemediationExecutions.value }).from(vulnerabilityRemediationExecutions).where(and2(eq2(vulnerabilityRemediationExecutions.tenant_id, requiredText(tenantId, "Tenant id")), eq2(vulnerabilityRemediationExecutions.plan_id, requiredText(planId, "Remediation plan id")))).orderBy(desc2(vulnerabilityRemediationExecutions.started_at), vulnerabilityRemediationExecutions.execution_id).limit(1000);
|
|
1291
|
+
return rows.map(({ value }) => valid(RemediationExecutionSchema, value, "Stored remediation execution"));
|
|
1292
|
+
},
|
|
1293
|
+
save: async (tenantId, execution) => {
|
|
1294
|
+
valid(RemediationExecutionSchema, execution, `Remediation execution ${execution.id}`);
|
|
1295
|
+
await db.insert(vulnerabilityRemediationExecutions).values({
|
|
1296
|
+
completed_at: execution.completedAt ? new Date(execution.completedAt) : null,
|
|
1297
|
+
execution_id: execution.id,
|
|
1298
|
+
plan_id: execution.planId,
|
|
1299
|
+
started_at: new Date(execution.startedAt),
|
|
1300
|
+
status: execution.status,
|
|
1301
|
+
tenant_id: requiredText(tenantId, "Tenant id"),
|
|
1302
|
+
value: encodedJsonb2(execution)
|
|
1303
|
+
}).onConflictDoUpdate({
|
|
1304
|
+
set: {
|
|
1305
|
+
completed_at: execution.completedAt ? new Date(execution.completedAt) : null,
|
|
1306
|
+
plan_id: execution.planId,
|
|
1307
|
+
started_at: new Date(execution.startedAt),
|
|
1308
|
+
status: execution.status,
|
|
1309
|
+
updated_at: databaseNow2,
|
|
1310
|
+
value: encodedJsonb2(execution)
|
|
1311
|
+
},
|
|
1312
|
+
target: [
|
|
1313
|
+
vulnerabilityRemediationExecutions.tenant_id,
|
|
1314
|
+
vulnerabilityRemediationExecutions.execution_id
|
|
1315
|
+
]
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1318
|
+
};
|
|
1319
|
+
const remediationVerifications = {
|
|
1320
|
+
get: async (tenantId, verificationId) => {
|
|
1321
|
+
const [row] = await db.select({
|
|
1322
|
+
value: vulnerabilityRemediationVerifications.value
|
|
1323
|
+
}).from(vulnerabilityRemediationVerifications).where(and2(eq2(vulnerabilityRemediationVerifications.tenant_id, requiredText(tenantId, "Tenant id")), eq2(vulnerabilityRemediationVerifications.verification_id, requiredText(verificationId, "Remediation verification id")))).limit(1);
|
|
1324
|
+
return row ? valid(RemediationVerificationSchema, row.value, "Stored remediation verification") : null;
|
|
1325
|
+
},
|
|
1326
|
+
list: async (tenantId, executionId) => {
|
|
1327
|
+
const rows = await db.select({
|
|
1328
|
+
value: vulnerabilityRemediationVerifications.value
|
|
1329
|
+
}).from(vulnerabilityRemediationVerifications).where(and2(eq2(vulnerabilityRemediationVerifications.tenant_id, requiredText(tenantId, "Tenant id")), eq2(vulnerabilityRemediationVerifications.execution_id, requiredText(executionId, "Remediation execution id")))).orderBy(desc2(vulnerabilityRemediationVerifications.observed_at), vulnerabilityRemediationVerifications.verification_id).limit(1000);
|
|
1330
|
+
return rows.map(({ value }) => valid(RemediationVerificationSchema, value, "Stored remediation verification"));
|
|
1331
|
+
},
|
|
1332
|
+
save: async (tenantId, verification) => {
|
|
1333
|
+
valid(RemediationVerificationSchema, verification, `Remediation verification ${verification.id}`);
|
|
1334
|
+
await db.insert(vulnerabilityRemediationVerifications).values({
|
|
1335
|
+
execution_id: verification.executionId,
|
|
1336
|
+
observed_at: new Date(verification.observedAt),
|
|
1337
|
+
plan_id: verification.planId,
|
|
1338
|
+
status: verification.status,
|
|
1339
|
+
tenant_id: requiredText(tenantId, "Tenant id"),
|
|
1340
|
+
value: encodedJsonb2(verification),
|
|
1341
|
+
verification_id: verification.id
|
|
1342
|
+
}).onConflictDoUpdate({
|
|
1343
|
+
set: {
|
|
1344
|
+
execution_id: verification.executionId,
|
|
1345
|
+
observed_at: new Date(verification.observedAt),
|
|
1346
|
+
plan_id: verification.planId,
|
|
1347
|
+
status: verification.status,
|
|
1348
|
+
updated_at: databaseNow2,
|
|
1349
|
+
value: encodedJsonb2(verification)
|
|
1350
|
+
},
|
|
1351
|
+
target: [
|
|
1352
|
+
vulnerabilityRemediationVerifications.tenant_id,
|
|
1353
|
+
vulnerabilityRemediationVerifications.verification_id
|
|
1354
|
+
]
|
|
1355
|
+
});
|
|
1356
|
+
}
|
|
1357
|
+
};
|
|
1358
|
+
const saveVexDecisions = async (tenantId, decisions) => {
|
|
1359
|
+
if (decisions.length === 0)
|
|
1360
|
+
return;
|
|
1361
|
+
const normalizedTenantId = requiredText(tenantId, "Tenant id");
|
|
1362
|
+
for (const decision of decisions)
|
|
1363
|
+
valid(VexDecisionSchema, decision, `VEX decision ${decision.id}`);
|
|
1364
|
+
await db.insert(vulnerabilityVexDecisions).values(decisions.map((decision) => ({
|
|
1365
|
+
created_at: new Date(decision.createdAt),
|
|
1366
|
+
decision_id: decision.id,
|
|
1367
|
+
expires_at: decision.expiresAt ? new Date(decision.expiresAt) : null,
|
|
1368
|
+
product_id: decision.productId,
|
|
1369
|
+
status: decision.status,
|
|
1370
|
+
tenant_id: normalizedTenantId,
|
|
1371
|
+
value: encodedJsonb2(decision),
|
|
1372
|
+
vulnerability_id: decision.vulnerabilityId
|
|
1373
|
+
}))).onConflictDoUpdate({
|
|
1374
|
+
set: {
|
|
1375
|
+
created_at: sql2`excluded.created_at`,
|
|
1376
|
+
expires_at: sql2`excluded.expires_at`,
|
|
1377
|
+
product_id: sql2`excluded.product_id`,
|
|
1378
|
+
status: sql2`excluded.status`,
|
|
1379
|
+
updated_at: databaseNow2,
|
|
1380
|
+
value: sql2`excluded.value`,
|
|
1381
|
+
vulnerability_id: sql2`excluded.vulnerability_id`
|
|
1382
|
+
},
|
|
1383
|
+
target: [
|
|
1384
|
+
vulnerabilityVexDecisions.tenant_id,
|
|
1385
|
+
vulnerabilityVexDecisions.decision_id
|
|
1386
|
+
]
|
|
1387
|
+
});
|
|
1388
|
+
};
|
|
1389
|
+
const vexDecisions = {
|
|
1390
|
+
get: async (tenantId, decisionId) => {
|
|
1391
|
+
const [row] = await db.select({ value: vulnerabilityVexDecisions.value }).from(vulnerabilityVexDecisions).where(and2(eq2(vulnerabilityVexDecisions.tenant_id, requiredText(tenantId, "Tenant id")), eq2(vulnerabilityVexDecisions.decision_id, requiredText(decisionId, "Decision id")))).limit(1);
|
|
1392
|
+
return row ? valid(VexDecisionSchema, row.value, "Stored VEX decision") : null;
|
|
1393
|
+
},
|
|
1394
|
+
list: async (filter) => {
|
|
1395
|
+
const rows = await db.select({ value: vulnerabilityVexDecisions.value }).from(vulnerabilityVexDecisions).where(and2(eq2(vulnerabilityVexDecisions.tenant_id, requiredText(filter.tenantId, "Tenant id")), filter.productId ? eq2(vulnerabilityVexDecisions.product_id, filter.productId.trim()) : undefined, filter.vulnerabilityId ? eq2(vulnerabilityVexDecisions.vulnerability_id, filter.vulnerabilityId.trim()) : undefined)).orderBy(desc2(vulnerabilityVexDecisions.created_at), vulnerabilityVexDecisions.decision_id).limit(boundedLimit3(filter.limit));
|
|
1396
|
+
return rows.map(({ value }) => valid(VexDecisionSchema, value, "Stored VEX decision"));
|
|
1397
|
+
},
|
|
1398
|
+
save: async (tenantId, decision) => saveVexDecisions(tenantId, [decision]),
|
|
1399
|
+
saveMany: saveVexDecisions
|
|
1400
|
+
};
|
|
1401
|
+
const saveVexApplications = async (applications) => {
|
|
1402
|
+
if (applications.length === 0)
|
|
1403
|
+
return;
|
|
1404
|
+
for (const application of applications)
|
|
1405
|
+
valid(VexFindingApplicationSchema, application, `VEX application ${application.findingId}`);
|
|
1406
|
+
await db.insert(vulnerabilityVexApplications).values(applications.map((application) => ({
|
|
1407
|
+
applied_at: new Date(application.appliedAt),
|
|
1408
|
+
decision_id: application.decisionId,
|
|
1409
|
+
ended_at: application.endedAt ? new Date(application.endedAt) : null,
|
|
1410
|
+
finding_id: application.findingId,
|
|
1411
|
+
tenant_id: application.tenantId,
|
|
1412
|
+
value: encodedJsonb2(application)
|
|
1413
|
+
}))).onConflictDoUpdate({
|
|
1414
|
+
set: {
|
|
1415
|
+
applied_at: sql2`excluded.applied_at`,
|
|
1416
|
+
decision_id: sql2`excluded.decision_id`,
|
|
1417
|
+
ended_at: sql2`excluded.ended_at`,
|
|
1418
|
+
updated_at: databaseNow2,
|
|
1419
|
+
value: sql2`excluded.value`
|
|
1420
|
+
},
|
|
1421
|
+
target: [
|
|
1422
|
+
vulnerabilityVexApplications.tenant_id,
|
|
1423
|
+
vulnerabilityVexApplications.finding_id
|
|
1424
|
+
]
|
|
1425
|
+
});
|
|
1426
|
+
};
|
|
1427
|
+
const vexApplications = {
|
|
1428
|
+
get: async (tenantId, findingId) => {
|
|
1429
|
+
const [row] = await db.select({ value: vulnerabilityVexApplications.value }).from(vulnerabilityVexApplications).where(and2(eq2(vulnerabilityVexApplications.tenant_id, requiredText(tenantId, "Tenant id")), eq2(vulnerabilityVexApplications.finding_id, requiredText(findingId, "Finding id")))).limit(1);
|
|
1430
|
+
return row ? valid(VexFindingApplicationSchema, row.value, "Stored VEX application") : null;
|
|
1431
|
+
},
|
|
1432
|
+
save: async (application) => saveVexApplications([application]),
|
|
1433
|
+
saveMany: saveVexApplications
|
|
1434
|
+
};
|
|
1435
|
+
const leases = {
|
|
1436
|
+
acquire: async (request) => {
|
|
1437
|
+
if (!Number.isFinite(request.ttlMs) || request.ttlMs <= 0)
|
|
1438
|
+
throw new Error("Feed lease ttlMs must be positive and finite");
|
|
1439
|
+
const now = request.now ?? new Date;
|
|
1440
|
+
const ownerId = requiredText(request.ownerId, "Feed lease owner id");
|
|
1441
|
+
const [row] = await db.insert(vulnerabilityFeedLeases).values({
|
|
1442
|
+
expires_at: new Date(now.getTime() + request.ttlMs),
|
|
1443
|
+
feed_id: requiredText(request.feedId, "Feed lease feed id"),
|
|
1444
|
+
owner_id: ownerId,
|
|
1445
|
+
updated_at: now
|
|
1446
|
+
}).onConflictDoUpdate({
|
|
1447
|
+
set: {
|
|
1448
|
+
expires_at: new Date(now.getTime() + request.ttlMs),
|
|
1449
|
+
owner_id: ownerId,
|
|
1450
|
+
updated_at: now
|
|
1451
|
+
},
|
|
1452
|
+
setWhere: or2(lte2(vulnerabilityFeedLeases.expires_at, now), eq2(vulnerabilityFeedLeases.owner_id, ownerId)),
|
|
1453
|
+
target: vulnerabilityFeedLeases.feed_id
|
|
1454
|
+
}).returning({ ownerId: vulnerabilityFeedLeases.owner_id });
|
|
1455
|
+
return row?.ownerId === ownerId;
|
|
1456
|
+
},
|
|
1457
|
+
release: async (feedId, ownerId) => {
|
|
1458
|
+
const rows = await db.delete(vulnerabilityFeedLeases).where(and2(eq2(vulnerabilityFeedLeases.feed_id, requiredText(feedId, "Feed lease feed id")), eq2(vulnerabilityFeedLeases.owner_id, requiredText(ownerId, "Feed lease owner id")))).returning({ feedId: vulnerabilityFeedLeases.feed_id });
|
|
1459
|
+
return rows.length > 0;
|
|
1460
|
+
}
|
|
1461
|
+
};
|
|
1462
|
+
return {
|
|
1463
|
+
alertIncidents: alertStores.alertIncidents,
|
|
1464
|
+
alertPolicies: alertStores.alertPolicies,
|
|
1465
|
+
ensureSchema: () => Promise.resolve(),
|
|
1466
|
+
findings,
|
|
1467
|
+
leases,
|
|
1468
|
+
observations,
|
|
1469
|
+
remediationExecutions,
|
|
1470
|
+
remediationPlans,
|
|
1471
|
+
remediationVerifications,
|
|
1472
|
+
riskAssessments,
|
|
1473
|
+
snapshots,
|
|
1474
|
+
syncRuns,
|
|
1475
|
+
vexApplications,
|
|
1476
|
+
vexDecisions
|
|
1477
|
+
};
|
|
1478
|
+
};
|
|
1479
|
+
|
|
813
1480
|
// src/index.ts
|
|
814
1481
|
var IDENTIFIER2 = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
815
1482
|
var SYNC_STATUSES = new Set([
|
|
@@ -818,7 +1485,7 @@ var SYNC_STATUSES = new Set([
|
|
|
818
1485
|
"stale",
|
|
819
1486
|
"updated"
|
|
820
1487
|
]);
|
|
821
|
-
var
|
|
1488
|
+
var requiredText2 = (value, label) => {
|
|
822
1489
|
const normalized = value.trim();
|
|
823
1490
|
if (normalized.length === 0)
|
|
824
1491
|
throw new Error(`${label} is required`);
|
|
@@ -830,7 +1497,7 @@ var limit = (value, fallback = 100) => {
|
|
|
830
1497
|
throw new Error("Postgres query limit must be an integer from 1 through 1000");
|
|
831
1498
|
return normalized;
|
|
832
1499
|
};
|
|
833
|
-
var
|
|
1500
|
+
var timestamp3 = (value, label) => {
|
|
834
1501
|
if (value instanceof Date)
|
|
835
1502
|
return value.toISOString();
|
|
836
1503
|
if (typeof value !== "string" || !Number.isFinite(Date.parse(value)))
|
|
@@ -1036,7 +1703,7 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1036
1703
|
const tablePrefix = options.tablePrefix ?? "vulnerability";
|
|
1037
1704
|
const ddl = vulnerabilityPostgresSchemaSql(tablePrefix);
|
|
1038
1705
|
const table = prefixTables(tablePrefix);
|
|
1039
|
-
const
|
|
1706
|
+
const sql3 = options.sql;
|
|
1040
1707
|
const shouldEnsureSchema = options.ensureSchema ?? true;
|
|
1041
1708
|
const alertStores = createPostgresVulnerabilityAlertStores({
|
|
1042
1709
|
ensureSchema: shouldEnsureSchema,
|
|
@@ -1049,7 +1716,7 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1049
1716
|
return Promise.resolve();
|
|
1050
1717
|
if (schemaPromise)
|
|
1051
1718
|
return schemaPromise;
|
|
1052
|
-
schemaPromise = Promise.resolve(
|
|
1719
|
+
schemaPromise = Promise.resolve(sql3.unsafe(ddl)).then(() => {
|
|
1053
1720
|
return;
|
|
1054
1721
|
});
|
|
1055
1722
|
return schemaPromise;
|
|
@@ -1057,8 +1724,8 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1057
1724
|
const snapshots = () => ({
|
|
1058
1725
|
load: async (feedId) => {
|
|
1059
1726
|
await ensureSchema();
|
|
1060
|
-
const id =
|
|
1061
|
-
const rows = await
|
|
1727
|
+
const id = requiredText2(feedId, "Feed id");
|
|
1728
|
+
const rows = await sql3`
|
|
1062
1729
|
SELECT
|
|
1063
1730
|
snapshot.feed_id,
|
|
1064
1731
|
snapshot.feed_name,
|
|
@@ -1074,10 +1741,10 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1074
1741
|
'value', record.value
|
|
1075
1742
|
) ORDER BY record.record_id
|
|
1076
1743
|
)
|
|
1077
|
-
FROM ${
|
|
1744
|
+
FROM ${sql3.unsafe(table.records)} record
|
|
1078
1745
|
WHERE record.feed_id = snapshot.feed_id
|
|
1079
1746
|
), '[]'::jsonb) AS records
|
|
1080
|
-
FROM ${
|
|
1747
|
+
FROM ${sql3.unsafe(table.snapshots)} snapshot
|
|
1081
1748
|
WHERE snapshot.feed_id = ${id}
|
|
1082
1749
|
`;
|
|
1083
1750
|
const row = rows[0];
|
|
@@ -1093,10 +1760,10 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1093
1760
|
name: row.feed_name,
|
|
1094
1761
|
url: row.feed_url
|
|
1095
1762
|
},
|
|
1096
|
-
fetchedAt:
|
|
1763
|
+
fetchedAt: timestamp3(row.fetched_at, "Feed fetchedAt"),
|
|
1097
1764
|
records: records.map((record) => ({
|
|
1098
|
-
id:
|
|
1099
|
-
modifiedAt:
|
|
1765
|
+
id: requiredText2(record.id, "Feed record id"),
|
|
1766
|
+
modifiedAt: timestamp3(record.modifiedAt, "Feed record modifiedAt"),
|
|
1100
1767
|
value: record.value
|
|
1101
1768
|
})),
|
|
1102
1769
|
revision: row.revision
|
|
@@ -1105,21 +1772,21 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1105
1772
|
save: async (snapshot) => {
|
|
1106
1773
|
await ensureSchema();
|
|
1107
1774
|
const records = JSON.stringify(snapshot.records.map((record) => ({
|
|
1108
|
-
id:
|
|
1109
|
-
modified_at:
|
|
1775
|
+
id: requiredText2(record.id, "Feed record id"),
|
|
1776
|
+
modified_at: timestamp3(record.modifiedAt, "Feed record modifiedAt"),
|
|
1110
1777
|
value: record.value
|
|
1111
1778
|
})));
|
|
1112
1779
|
const cursor = JSON.stringify(snapshot.cursor);
|
|
1113
|
-
await
|
|
1780
|
+
await sql3`
|
|
1114
1781
|
WITH saved_snapshot AS (
|
|
1115
|
-
INSERT INTO ${
|
|
1782
|
+
INSERT INTO ${sql3.unsafe(table.snapshots)} (
|
|
1116
1783
|
feed_id, feed_name, feed_url, cursor, fetched_at, revision, updated_at
|
|
1117
1784
|
) VALUES (
|
|
1118
|
-
${
|
|
1119
|
-
${
|
|
1120
|
-
${
|
|
1785
|
+
${requiredText2(snapshot.feed.id, "Feed id")},
|
|
1786
|
+
${requiredText2(snapshot.feed.name, "Feed name")},
|
|
1787
|
+
${requiredText2(snapshot.feed.url, "Feed URL")},
|
|
1121
1788
|
${cursor}::jsonb,
|
|
1122
|
-
${
|
|
1789
|
+
${timestamp3(snapshot.fetchedAt, "Feed fetchedAt")}::timestamptz,
|
|
1123
1790
|
${snapshot.revision},
|
|
1124
1791
|
now()
|
|
1125
1792
|
)
|
|
@@ -1136,14 +1803,14 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1136
1803
|
FROM jsonb_to_recordset(${records}::jsonb)
|
|
1137
1804
|
AS item(id text, modified_at text, value jsonb)
|
|
1138
1805
|
), removed AS (
|
|
1139
|
-
DELETE FROM ${
|
|
1806
|
+
DELETE FROM ${sql3.unsafe(table.records)} record
|
|
1140
1807
|
WHERE record.feed_id = ${snapshot.feed.id}
|
|
1141
1808
|
AND NOT EXISTS (
|
|
1142
1809
|
SELECT 1 FROM incoming WHERE incoming.id = record.record_id
|
|
1143
1810
|
)
|
|
1144
1811
|
RETURNING record_id
|
|
1145
1812
|
), written AS (
|
|
1146
|
-
INSERT INTO ${
|
|
1813
|
+
INSERT INTO ${sql3.unsafe(table.records)} (
|
|
1147
1814
|
feed_id, record_id, modified_at, value
|
|
1148
1815
|
)
|
|
1149
1816
|
SELECT saved_snapshot.feed_id, incoming.id, incoming.modified_at, incoming.value
|
|
@@ -1166,14 +1833,14 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1166
1833
|
throw new Error(`Unsupported feed sync status: ${run.status}`);
|
|
1167
1834
|
if (!Number.isInteger(run.records) || run.records < 0)
|
|
1168
1835
|
throw new Error("Feed sync records must be a non-negative integer");
|
|
1169
|
-
await
|
|
1170
|
-
INSERT INTO ${
|
|
1836
|
+
await sql3`
|
|
1837
|
+
INSERT INTO ${sql3.unsafe(table.runs)} (
|
|
1171
1838
|
id, feed_id, started_at, completed_at, status, error, records, revision
|
|
1172
1839
|
) VALUES (
|
|
1173
|
-
${
|
|
1174
|
-
${
|
|
1175
|
-
${
|
|
1176
|
-
${
|
|
1840
|
+
${requiredText2(run.id, "Feed sync run id")},
|
|
1841
|
+
${requiredText2(run.feedId, "Feed sync feed id")},
|
|
1842
|
+
${timestamp3(run.startedAt, "Feed sync startedAt")}::timestamptz,
|
|
1843
|
+
${timestamp3(run.completedAt, "Feed sync completedAt")}::timestamptz,
|
|
1177
1844
|
${run.status}, ${run.error}, ${run.records}, ${run.revision}
|
|
1178
1845
|
)
|
|
1179
1846
|
ON CONFLICT (id) DO UPDATE SET
|
|
@@ -1190,22 +1857,22 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1190
1857
|
await ensureSchema();
|
|
1191
1858
|
const feedId = filter.feedId?.trim() || null;
|
|
1192
1859
|
const status = filter.status ?? null;
|
|
1193
|
-
const rows = await
|
|
1860
|
+
const rows = await sql3`
|
|
1194
1861
|
SELECT id, feed_id, started_at, completed_at, status, error, records, revision
|
|
1195
|
-
FROM ${
|
|
1862
|
+
FROM ${sql3.unsafe(table.runs)}
|
|
1196
1863
|
WHERE (${feedId}::text IS NULL OR feed_id = ${feedId})
|
|
1197
1864
|
AND (${status}::text IS NULL OR status = ${status})
|
|
1198
1865
|
ORDER BY started_at DESC, id DESC
|
|
1199
1866
|
LIMIT ${limit(filter.limit)}
|
|
1200
1867
|
`;
|
|
1201
1868
|
return rows.map((row) => ({
|
|
1202
|
-
completedAt:
|
|
1869
|
+
completedAt: timestamp3(row.completed_at, "Feed sync completedAt"),
|
|
1203
1870
|
error: row.error,
|
|
1204
1871
|
feedId: row.feed_id,
|
|
1205
1872
|
id: row.id,
|
|
1206
1873
|
records: Number(row.records),
|
|
1207
1874
|
revision: row.revision,
|
|
1208
|
-
startedAt:
|
|
1875
|
+
startedAt: timestamp3(row.started_at, "Feed sync startedAt"),
|
|
1209
1876
|
status: row.status
|
|
1210
1877
|
}));
|
|
1211
1878
|
}
|
|
@@ -1216,7 +1883,7 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1216
1883
|
return;
|
|
1217
1884
|
for (const finding of findings2) {
|
|
1218
1885
|
const findingId = finding.id;
|
|
1219
|
-
if (!
|
|
1886
|
+
if (!Value2.Check(ManagedVulnerabilityFindingSchema2, finding))
|
|
1220
1887
|
throw new Error(`Managed finding ${findingId} is invalid`);
|
|
1221
1888
|
}
|
|
1222
1889
|
const payload = JSON.stringify(findings2.map((finding) => ({
|
|
@@ -1230,8 +1897,8 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1230
1897
|
tenant_id: finding.tenantId,
|
|
1231
1898
|
value: finding
|
|
1232
1899
|
})));
|
|
1233
|
-
await
|
|
1234
|
-
INSERT INTO ${
|
|
1900
|
+
await sql3`
|
|
1901
|
+
INSERT INTO ${sql3.unsafe(table.findings)} (
|
|
1235
1902
|
tenant_id, finding_id, asset_id, component_id, severity, status,
|
|
1236
1903
|
first_seen_at, last_seen_at, value, updated_at
|
|
1237
1904
|
)
|
|
@@ -1249,36 +1916,36 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1249
1916
|
component_id = EXCLUDED.component_id,
|
|
1250
1917
|
severity = EXCLUDED.severity,
|
|
1251
1918
|
status = EXCLUDED.status,
|
|
1252
|
-
first_seen_at = LEAST(${
|
|
1253
|
-
last_seen_at = GREATEST(${
|
|
1919
|
+
first_seen_at = LEAST(${sql3.unsafe(table.findings)}.first_seen_at, EXCLUDED.first_seen_at),
|
|
1920
|
+
last_seen_at = GREATEST(${sql3.unsafe(table.findings)}.last_seen_at, EXCLUDED.last_seen_at),
|
|
1254
1921
|
value = EXCLUDED.value,
|
|
1255
1922
|
updated_at = now()
|
|
1256
1923
|
`;
|
|
1257
1924
|
};
|
|
1258
1925
|
const parseFinding = (value) => {
|
|
1259
1926
|
const finding = json(value, "Managed finding");
|
|
1260
|
-
if (!
|
|
1927
|
+
if (!Value2.Check(ManagedVulnerabilityFindingSchema2, finding))
|
|
1261
1928
|
throw new Error("Stored managed finding is invalid");
|
|
1262
1929
|
return finding;
|
|
1263
1930
|
};
|
|
1264
1931
|
const findings = {
|
|
1265
1932
|
get: async (tenantId, findingId) => {
|
|
1266
1933
|
await ensureSchema();
|
|
1267
|
-
const rows = await
|
|
1268
|
-
SELECT value FROM ${
|
|
1269
|
-
WHERE tenant_id = ${
|
|
1270
|
-
AND finding_id = ${
|
|
1934
|
+
const rows = await sql3`
|
|
1935
|
+
SELECT value FROM ${sql3.unsafe(table.findings)}
|
|
1936
|
+
WHERE tenant_id = ${requiredText2(tenantId, "Tenant id")}
|
|
1937
|
+
AND finding_id = ${requiredText2(findingId, "Finding id")}
|
|
1271
1938
|
`;
|
|
1272
1939
|
return rows[0] ? parseFinding(rows[0].value) : null;
|
|
1273
1940
|
},
|
|
1274
1941
|
list: async (filter) => {
|
|
1275
1942
|
await ensureSchema();
|
|
1276
|
-
const tenantId =
|
|
1943
|
+
const tenantId = requiredText2(filter.tenantId, "Tenant id");
|
|
1277
1944
|
const assetId = filter.assetId?.trim() || null;
|
|
1278
1945
|
const severity = filter.severity ?? null;
|
|
1279
1946
|
const status = filter.status ?? null;
|
|
1280
|
-
const rows = await
|
|
1281
|
-
SELECT value FROM ${
|
|
1947
|
+
const rows = await sql3`
|
|
1948
|
+
SELECT value FROM ${sql3.unsafe(table.findings)}
|
|
1282
1949
|
WHERE tenant_id = ${tenantId}
|
|
1283
1950
|
AND (${assetId}::text IS NULL OR asset_id = ${assetId})
|
|
1284
1951
|
AND (${severity}::text IS NULL OR severity = ${severity})
|
|
@@ -1293,18 +1960,18 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1293
1960
|
};
|
|
1294
1961
|
const parseObservation = (value) => {
|
|
1295
1962
|
const observation = json(value, "Vulnerability observation");
|
|
1296
|
-
if (!
|
|
1963
|
+
if (!Value2.Check(VulnerabilityObservationSchema2, observation))
|
|
1297
1964
|
throw new Error("Stored vulnerability observation is invalid");
|
|
1298
1965
|
return observation;
|
|
1299
1966
|
};
|
|
1300
1967
|
const saveObservations = async (tenantId, observations2) => {
|
|
1301
1968
|
await ensureSchema();
|
|
1302
|
-
const normalizedTenantId =
|
|
1969
|
+
const normalizedTenantId = requiredText2(tenantId, "Tenant id");
|
|
1303
1970
|
if (observations2.length === 0)
|
|
1304
1971
|
return;
|
|
1305
1972
|
for (const observation of observations2) {
|
|
1306
1973
|
const observationId = observation.id;
|
|
1307
|
-
if (!
|
|
1974
|
+
if (!Value2.Check(VulnerabilityObservationSchema2, observation))
|
|
1308
1975
|
throw new Error(`Vulnerability observation ${observationId} is invalid`);
|
|
1309
1976
|
}
|
|
1310
1977
|
const payload = JSON.stringify(observations2.map((observation) => ({
|
|
@@ -1314,8 +1981,8 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1314
1981
|
observed_at: observation.observedAt,
|
|
1315
1982
|
value: observation
|
|
1316
1983
|
})));
|
|
1317
|
-
await
|
|
1318
|
-
INSERT INTO ${
|
|
1984
|
+
await sql3`
|
|
1985
|
+
INSERT INTO ${sql3.unsafe(table.observations)} (
|
|
1319
1986
|
tenant_id, observation_id, asset_id, component_id, observed_at, value,
|
|
1320
1987
|
updated_at
|
|
1321
1988
|
)
|
|
@@ -1337,20 +2004,20 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1337
2004
|
const observations = {
|
|
1338
2005
|
get: async (tenantId, observationId) => {
|
|
1339
2006
|
await ensureSchema();
|
|
1340
|
-
const rows = await
|
|
1341
|
-
SELECT value FROM ${
|
|
1342
|
-
WHERE tenant_id = ${
|
|
1343
|
-
AND observation_id = ${
|
|
2007
|
+
const rows = await sql3`
|
|
2008
|
+
SELECT value FROM ${sql3.unsafe(table.observations)}
|
|
2009
|
+
WHERE tenant_id = ${requiredText2(tenantId, "Tenant id")}
|
|
2010
|
+
AND observation_id = ${requiredText2(observationId, "Observation id")}
|
|
1344
2011
|
`;
|
|
1345
2012
|
return rows[0] ? parseObservation(rows[0].value) : null;
|
|
1346
2013
|
},
|
|
1347
2014
|
list: async (filter) => {
|
|
1348
2015
|
await ensureSchema();
|
|
1349
|
-
const tenantId =
|
|
2016
|
+
const tenantId = requiredText2(filter.tenantId, "Tenant id");
|
|
1350
2017
|
const assetId = filter.assetId?.trim() || null;
|
|
1351
2018
|
const componentId = filter.componentId?.trim() || null;
|
|
1352
|
-
const rows = await
|
|
1353
|
-
SELECT value FROM ${
|
|
2019
|
+
const rows = await sql3`
|
|
2020
|
+
SELECT value FROM ${sql3.unsafe(table.observations)}
|
|
1354
2021
|
WHERE tenant_id = ${tenantId}
|
|
1355
2022
|
AND (${assetId}::text IS NULL OR asset_id = ${assetId})
|
|
1356
2023
|
AND (${componentId}::text IS NULL OR component_id = ${componentId})
|
|
@@ -1364,18 +2031,18 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1364
2031
|
};
|
|
1365
2032
|
const parseRiskAssessment = (value) => {
|
|
1366
2033
|
const assessment = json(value, "Vulnerability risk assessment");
|
|
1367
|
-
if (!
|
|
2034
|
+
if (!Value2.Check(VulnerabilityRiskAssessmentSchema2, assessment))
|
|
1368
2035
|
throw new Error("Stored vulnerability risk assessment is invalid");
|
|
1369
2036
|
return assessment;
|
|
1370
2037
|
};
|
|
1371
2038
|
const saveRiskAssessments = async (tenantId, assessments) => {
|
|
1372
2039
|
await ensureSchema();
|
|
1373
|
-
const normalizedTenantId =
|
|
2040
|
+
const normalizedTenantId = requiredText2(tenantId, "Tenant id");
|
|
1374
2041
|
if (assessments.length === 0)
|
|
1375
2042
|
return;
|
|
1376
2043
|
for (const assessment of assessments) {
|
|
1377
2044
|
const findingId = assessment.findingId;
|
|
1378
|
-
if (!
|
|
2045
|
+
if (!Value2.Check(VulnerabilityRiskAssessmentSchema2, assessment))
|
|
1379
2046
|
throw new Error(`Vulnerability risk assessment ${findingId} is invalid`);
|
|
1380
2047
|
}
|
|
1381
2048
|
const payload = JSON.stringify(assessments.map((assessment) => ({
|
|
@@ -1385,8 +2052,8 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1385
2052
|
remediate_by: assessment.remediateBy,
|
|
1386
2053
|
value: assessment
|
|
1387
2054
|
})));
|
|
1388
|
-
await
|
|
1389
|
-
INSERT INTO ${
|
|
2055
|
+
await sql3`
|
|
2056
|
+
INSERT INTO ${sql3.unsafe(table.riskAssessments)} (
|
|
1390
2057
|
tenant_id, finding_id, priority, assessed_at, remediate_by, value,
|
|
1391
2058
|
updated_at
|
|
1392
2059
|
)
|
|
@@ -1409,19 +2076,19 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1409
2076
|
const riskAssessments = {
|
|
1410
2077
|
get: async (tenantId, findingId) => {
|
|
1411
2078
|
await ensureSchema();
|
|
1412
|
-
const rows = await
|
|
1413
|
-
SELECT value FROM ${
|
|
1414
|
-
WHERE tenant_id = ${
|
|
1415
|
-
AND finding_id = ${
|
|
2079
|
+
const rows = await sql3`
|
|
2080
|
+
SELECT value FROM ${sql3.unsafe(table.riskAssessments)}
|
|
2081
|
+
WHERE tenant_id = ${requiredText2(tenantId, "Tenant id")}
|
|
2082
|
+
AND finding_id = ${requiredText2(findingId, "Finding id")}
|
|
1416
2083
|
`;
|
|
1417
2084
|
return rows[0] ? parseRiskAssessment(rows[0].value) : null;
|
|
1418
2085
|
},
|
|
1419
2086
|
list: async (filter) => {
|
|
1420
2087
|
await ensureSchema();
|
|
1421
|
-
const tenantId =
|
|
2088
|
+
const tenantId = requiredText2(filter.tenantId, "Tenant id");
|
|
1422
2089
|
const priority = filter.priority ?? null;
|
|
1423
|
-
const rows = await
|
|
1424
|
-
SELECT value FROM ${
|
|
2090
|
+
const rows = await sql3`
|
|
2091
|
+
SELECT value FROM ${sql3.unsafe(table.riskAssessments)}
|
|
1425
2092
|
WHERE tenant_id = ${tenantId}
|
|
1426
2093
|
AND (${priority}::text IS NULL OR priority = ${priority})
|
|
1427
2094
|
ORDER BY assessed_at DESC, finding_id
|
|
@@ -1434,26 +2101,26 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1434
2101
|
};
|
|
1435
2102
|
const parseRemediationPlan = (value) => {
|
|
1436
2103
|
const plan = json(value, "Remediation plan");
|
|
1437
|
-
if (!
|
|
2104
|
+
if (!Value2.Check(RemediationPlanSchema2, plan))
|
|
1438
2105
|
throw new Error("Stored remediation plan is invalid");
|
|
1439
2106
|
return plan;
|
|
1440
2107
|
};
|
|
1441
2108
|
const remediationPlans = {
|
|
1442
2109
|
get: async (tenantId, planId) => {
|
|
1443
2110
|
await ensureSchema();
|
|
1444
|
-
const rows = await
|
|
1445
|
-
SELECT value FROM ${
|
|
1446
|
-
WHERE tenant_id = ${
|
|
1447
|
-
AND plan_id = ${
|
|
2111
|
+
const rows = await sql3`
|
|
2112
|
+
SELECT value FROM ${sql3.unsafe(table.remediationPlans)}
|
|
2113
|
+
WHERE tenant_id = ${requiredText2(tenantId, "Tenant id")}
|
|
2114
|
+
AND plan_id = ${requiredText2(planId, "Remediation plan id")}
|
|
1448
2115
|
`;
|
|
1449
2116
|
return rows[0] ? parseRemediationPlan(rows[0].value) : null;
|
|
1450
2117
|
},
|
|
1451
2118
|
list: async (filter) => {
|
|
1452
2119
|
await ensureSchema();
|
|
1453
|
-
const tenantId =
|
|
2120
|
+
const tenantId = requiredText2(filter.tenantId, "Tenant id");
|
|
1454
2121
|
const status = filter.status ?? null;
|
|
1455
|
-
const rows = await
|
|
1456
|
-
SELECT value FROM ${
|
|
2122
|
+
const rows = await sql3`
|
|
2123
|
+
SELECT value FROM ${sql3.unsafe(table.remediationPlans)}
|
|
1457
2124
|
WHERE tenant_id = ${tenantId}
|
|
1458
2125
|
AND (${status}::text IS NULL OR status = ${status})
|
|
1459
2126
|
ORDER BY created_at DESC, plan_id
|
|
@@ -1464,13 +2131,13 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1464
2131
|
save: async (tenantId, plan) => {
|
|
1465
2132
|
await ensureSchema();
|
|
1466
2133
|
const planId = plan.id;
|
|
1467
|
-
if (!
|
|
2134
|
+
if (!Value2.Check(RemediationPlanSchema2, plan))
|
|
1468
2135
|
throw new Error(`Remediation plan ${planId} is invalid`);
|
|
1469
|
-
await
|
|
1470
|
-
INSERT INTO ${
|
|
2136
|
+
await sql3`
|
|
2137
|
+
INSERT INTO ${sql3.unsafe(table.remediationPlans)} (
|
|
1471
2138
|
tenant_id, plan_id, status, created_at, value, updated_at
|
|
1472
2139
|
) VALUES (
|
|
1473
|
-
${
|
|
2140
|
+
${requiredText2(tenantId, "Tenant id")}, ${plan.id}, ${plan.status},
|
|
1474
2141
|
${plan.createdAt}::timestamptz, ${JSON.stringify(plan)}::jsonb, now()
|
|
1475
2142
|
)
|
|
1476
2143
|
ON CONFLICT (tenant_id, plan_id) DO UPDATE SET
|
|
@@ -1483,26 +2150,26 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1483
2150
|
};
|
|
1484
2151
|
const parseRemediationExecution = (value) => {
|
|
1485
2152
|
const execution = json(value, "Remediation execution");
|
|
1486
|
-
if (!
|
|
2153
|
+
if (!Value2.Check(RemediationExecutionSchema2, execution))
|
|
1487
2154
|
throw new Error("Stored remediation execution is invalid");
|
|
1488
2155
|
return execution;
|
|
1489
2156
|
};
|
|
1490
2157
|
const remediationExecutions = {
|
|
1491
2158
|
get: async (tenantId, executionId) => {
|
|
1492
2159
|
await ensureSchema();
|
|
1493
|
-
const rows = await
|
|
1494
|
-
SELECT value FROM ${
|
|
1495
|
-
WHERE tenant_id = ${
|
|
1496
|
-
AND execution_id = ${
|
|
2160
|
+
const rows = await sql3`
|
|
2161
|
+
SELECT value FROM ${sql3.unsafe(table.remediationExecutions)}
|
|
2162
|
+
WHERE tenant_id = ${requiredText2(tenantId, "Tenant id")}
|
|
2163
|
+
AND execution_id = ${requiredText2(executionId, "Remediation execution id")}
|
|
1497
2164
|
`;
|
|
1498
2165
|
return rows[0] ? parseRemediationExecution(rows[0].value) : null;
|
|
1499
2166
|
},
|
|
1500
2167
|
list: async (tenantId, planId) => {
|
|
1501
2168
|
await ensureSchema();
|
|
1502
|
-
const rows = await
|
|
1503
|
-
SELECT value FROM ${
|
|
1504
|
-
WHERE tenant_id = ${
|
|
1505
|
-
AND plan_id = ${
|
|
2169
|
+
const rows = await sql3`
|
|
2170
|
+
SELECT value FROM ${sql3.unsafe(table.remediationExecutions)}
|
|
2171
|
+
WHERE tenant_id = ${requiredText2(tenantId, "Tenant id")}
|
|
2172
|
+
AND plan_id = ${requiredText2(planId, "Remediation plan id")}
|
|
1506
2173
|
ORDER BY started_at DESC, execution_id
|
|
1507
2174
|
LIMIT 1000
|
|
1508
2175
|
`;
|
|
@@ -1511,14 +2178,14 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1511
2178
|
save: async (tenantId, execution) => {
|
|
1512
2179
|
await ensureSchema();
|
|
1513
2180
|
const executionId = execution.id;
|
|
1514
|
-
if (!
|
|
2181
|
+
if (!Value2.Check(RemediationExecutionSchema2, execution))
|
|
1515
2182
|
throw new Error(`Remediation execution ${executionId} is invalid`);
|
|
1516
|
-
await
|
|
1517
|
-
INSERT INTO ${
|
|
2183
|
+
await sql3`
|
|
2184
|
+
INSERT INTO ${sql3.unsafe(table.remediationExecutions)} (
|
|
1518
2185
|
tenant_id, execution_id, plan_id, status, started_at, completed_at,
|
|
1519
2186
|
value, updated_at
|
|
1520
2187
|
) VALUES (
|
|
1521
|
-
${
|
|
2188
|
+
${requiredText2(tenantId, "Tenant id")}, ${execution.id},
|
|
1522
2189
|
${execution.planId}, ${execution.status},
|
|
1523
2190
|
${execution.startedAt}::timestamptz,
|
|
1524
2191
|
${execution.completedAt}::timestamptz,
|
|
@@ -1536,26 +2203,26 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1536
2203
|
};
|
|
1537
2204
|
const parseRemediationVerification = (value) => {
|
|
1538
2205
|
const verification = json(value, "Remediation verification");
|
|
1539
|
-
if (!
|
|
2206
|
+
if (!Value2.Check(RemediationVerificationSchema2, verification))
|
|
1540
2207
|
throw new Error("Stored remediation verification is invalid");
|
|
1541
2208
|
return verification;
|
|
1542
2209
|
};
|
|
1543
2210
|
const remediationVerifications = {
|
|
1544
2211
|
get: async (tenantId, verificationId) => {
|
|
1545
2212
|
await ensureSchema();
|
|
1546
|
-
const rows = await
|
|
1547
|
-
SELECT value FROM ${
|
|
1548
|
-
WHERE tenant_id = ${
|
|
1549
|
-
AND verification_id = ${
|
|
2213
|
+
const rows = await sql3`
|
|
2214
|
+
SELECT value FROM ${sql3.unsafe(table.remediationVerifications)}
|
|
2215
|
+
WHERE tenant_id = ${requiredText2(tenantId, "Tenant id")}
|
|
2216
|
+
AND verification_id = ${requiredText2(verificationId, "Remediation verification id")}
|
|
1550
2217
|
`;
|
|
1551
2218
|
return rows[0] ? parseRemediationVerification(rows[0].value) : null;
|
|
1552
2219
|
},
|
|
1553
2220
|
list: async (tenantId, executionId) => {
|
|
1554
2221
|
await ensureSchema();
|
|
1555
|
-
const rows = await
|
|
1556
|
-
SELECT value FROM ${
|
|
1557
|
-
WHERE tenant_id = ${
|
|
1558
|
-
AND execution_id = ${
|
|
2222
|
+
const rows = await sql3`
|
|
2223
|
+
SELECT value FROM ${sql3.unsafe(table.remediationVerifications)}
|
|
2224
|
+
WHERE tenant_id = ${requiredText2(tenantId, "Tenant id")}
|
|
2225
|
+
AND execution_id = ${requiredText2(executionId, "Remediation execution id")}
|
|
1559
2226
|
ORDER BY observed_at DESC, verification_id
|
|
1560
2227
|
LIMIT 1000
|
|
1561
2228
|
`;
|
|
@@ -1564,14 +2231,14 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1564
2231
|
save: async (tenantId, verification) => {
|
|
1565
2232
|
await ensureSchema();
|
|
1566
2233
|
const verificationId = verification.id;
|
|
1567
|
-
if (!
|
|
2234
|
+
if (!Value2.Check(RemediationVerificationSchema2, verification))
|
|
1568
2235
|
throw new Error(`Remediation verification ${verificationId} is invalid`);
|
|
1569
|
-
await
|
|
1570
|
-
INSERT INTO ${
|
|
2236
|
+
await sql3`
|
|
2237
|
+
INSERT INTO ${sql3.unsafe(table.remediationVerifications)} (
|
|
1571
2238
|
tenant_id, verification_id, execution_id, plan_id, status,
|
|
1572
2239
|
observed_at, value, updated_at
|
|
1573
2240
|
) VALUES (
|
|
1574
|
-
${
|
|
2241
|
+
${requiredText2(tenantId, "Tenant id")}, ${verification.id},
|
|
1575
2242
|
${verification.executionId}, ${verification.planId},
|
|
1576
2243
|
${verification.status}, ${verification.observedAt}::timestamptz,
|
|
1577
2244
|
${JSON.stringify(verification)}::jsonb, now()
|
|
@@ -1588,18 +2255,18 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1588
2255
|
};
|
|
1589
2256
|
const parseVexDecision = (value) => {
|
|
1590
2257
|
const decision = json(value, "VEX decision");
|
|
1591
|
-
if (!
|
|
2258
|
+
if (!Value2.Check(VexDecisionSchema2, decision))
|
|
1592
2259
|
throw new Error("Stored VEX decision is invalid");
|
|
1593
2260
|
return decision;
|
|
1594
2261
|
};
|
|
1595
2262
|
const saveVexDecisions = async (tenantId, decisions) => {
|
|
1596
2263
|
await ensureSchema();
|
|
1597
|
-
const normalizedTenantId =
|
|
2264
|
+
const normalizedTenantId = requiredText2(tenantId, "Tenant id");
|
|
1598
2265
|
if (decisions.length === 0)
|
|
1599
2266
|
return;
|
|
1600
2267
|
for (const decision of decisions) {
|
|
1601
2268
|
const decisionId = decision.id;
|
|
1602
|
-
if (!
|
|
2269
|
+
if (!Value2.Check(VexDecisionSchema2, decision))
|
|
1603
2270
|
throw new Error(`VEX decision ${decisionId} is invalid`);
|
|
1604
2271
|
}
|
|
1605
2272
|
const payload = JSON.stringify(decisions.map((decision) => ({
|
|
@@ -1611,8 +2278,8 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1611
2278
|
value: decision,
|
|
1612
2279
|
vulnerability_id: decision.vulnerabilityId
|
|
1613
2280
|
})));
|
|
1614
|
-
await
|
|
1615
|
-
INSERT INTO ${
|
|
2281
|
+
await sql3`
|
|
2282
|
+
INSERT INTO ${sql3.unsafe(table.vexDecisions)} (
|
|
1616
2283
|
tenant_id, decision_id, product_id, vulnerability_id, status,
|
|
1617
2284
|
created_at, expires_at, value, updated_at
|
|
1618
2285
|
)
|
|
@@ -1637,20 +2304,20 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1637
2304
|
const vexDecisions = {
|
|
1638
2305
|
get: async (tenantId, decisionId) => {
|
|
1639
2306
|
await ensureSchema();
|
|
1640
|
-
const rows = await
|
|
1641
|
-
SELECT value FROM ${
|
|
1642
|
-
WHERE tenant_id = ${
|
|
1643
|
-
AND decision_id = ${
|
|
2307
|
+
const rows = await sql3`
|
|
2308
|
+
SELECT value FROM ${sql3.unsafe(table.vexDecisions)}
|
|
2309
|
+
WHERE tenant_id = ${requiredText2(tenantId, "Tenant id")}
|
|
2310
|
+
AND decision_id = ${requiredText2(decisionId, "Decision id")}
|
|
1644
2311
|
`;
|
|
1645
2312
|
return rows[0] ? parseVexDecision(rows[0].value) : null;
|
|
1646
2313
|
},
|
|
1647
2314
|
list: async (filter) => {
|
|
1648
2315
|
await ensureSchema();
|
|
1649
|
-
const tenantId =
|
|
2316
|
+
const tenantId = requiredText2(filter.tenantId, "Tenant id");
|
|
1650
2317
|
const productId = filter.productId?.trim() || null;
|
|
1651
2318
|
const vulnerabilityId = filter.vulnerabilityId?.trim() || null;
|
|
1652
|
-
const rows = await
|
|
1653
|
-
SELECT value FROM ${
|
|
2319
|
+
const rows = await sql3`
|
|
2320
|
+
SELECT value FROM ${sql3.unsafe(table.vexDecisions)}
|
|
1654
2321
|
WHERE tenant_id = ${tenantId}
|
|
1655
2322
|
AND (${productId}::text IS NULL OR product_id = ${productId})
|
|
1656
2323
|
AND (${vulnerabilityId}::text IS NULL OR vulnerability_id = ${vulnerabilityId})
|
|
@@ -1664,7 +2331,7 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1664
2331
|
};
|
|
1665
2332
|
const parseVexApplication = (value) => {
|
|
1666
2333
|
const application = json(value, "VEX application");
|
|
1667
|
-
if (!
|
|
2334
|
+
if (!Value2.Check(VexFindingApplicationSchema2, application))
|
|
1668
2335
|
throw new Error("Stored VEX application is invalid");
|
|
1669
2336
|
return application;
|
|
1670
2337
|
};
|
|
@@ -1674,7 +2341,7 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1674
2341
|
return;
|
|
1675
2342
|
for (const application of applications) {
|
|
1676
2343
|
const findingId = application.findingId;
|
|
1677
|
-
if (!
|
|
2344
|
+
if (!Value2.Check(VexFindingApplicationSchema2, application))
|
|
1678
2345
|
throw new Error(`VEX application ${findingId} is invalid`);
|
|
1679
2346
|
}
|
|
1680
2347
|
const payload = JSON.stringify(applications.map((application) => ({
|
|
@@ -1685,8 +2352,8 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1685
2352
|
tenant_id: application.tenantId,
|
|
1686
2353
|
value: application
|
|
1687
2354
|
})));
|
|
1688
|
-
await
|
|
1689
|
-
INSERT INTO ${
|
|
2355
|
+
await sql3`
|
|
2356
|
+
INSERT INTO ${sql3.unsafe(table.vexApplications)} (
|
|
1690
2357
|
tenant_id, finding_id, decision_id, applied_at, ended_at, value,
|
|
1691
2358
|
updated_at
|
|
1692
2359
|
)
|
|
@@ -1709,10 +2376,10 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1709
2376
|
const vexApplications = {
|
|
1710
2377
|
get: async (tenantId, findingId) => {
|
|
1711
2378
|
await ensureSchema();
|
|
1712
|
-
const rows = await
|
|
1713
|
-
SELECT value FROM ${
|
|
1714
|
-
WHERE tenant_id = ${
|
|
1715
|
-
AND finding_id = ${
|
|
2379
|
+
const rows = await sql3`
|
|
2380
|
+
SELECT value FROM ${sql3.unsafe(table.vexApplications)}
|
|
2381
|
+
WHERE tenant_id = ${requiredText2(tenantId, "Tenant id")}
|
|
2382
|
+
AND finding_id = ${requiredText2(findingId, "Finding id")}
|
|
1716
2383
|
`;
|
|
1717
2384
|
return rows[0] ? parseVexApplication(rows[0].value) : null;
|
|
1718
2385
|
},
|
|
@@ -1726,12 +2393,12 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1726
2393
|
throw new Error("Feed lease ttlMs must be positive and finite");
|
|
1727
2394
|
const now = request.now ?? new Date;
|
|
1728
2395
|
const expiresAt = new Date(now.getTime() + request.ttlMs);
|
|
1729
|
-
const rows = await
|
|
1730
|
-
INSERT INTO ${
|
|
2396
|
+
const rows = await sql3`
|
|
2397
|
+
INSERT INTO ${sql3.unsafe(table.leases)} (
|
|
1731
2398
|
feed_id, owner_id, expires_at, updated_at
|
|
1732
2399
|
) VALUES (
|
|
1733
|
-
${
|
|
1734
|
-
${
|
|
2400
|
+
${requiredText2(request.feedId, "Feed lease feed id")},
|
|
2401
|
+
${requiredText2(request.ownerId, "Feed lease owner id")},
|
|
1735
2402
|
${expiresAt.toISOString()}::timestamptz,
|
|
1736
2403
|
${now.toISOString()}::timestamptz
|
|
1737
2404
|
)
|
|
@@ -1739,18 +2406,18 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1739
2406
|
owner_id = EXCLUDED.owner_id,
|
|
1740
2407
|
expires_at = EXCLUDED.expires_at,
|
|
1741
2408
|
updated_at = EXCLUDED.updated_at
|
|
1742
|
-
WHERE ${
|
|
1743
|
-
OR ${
|
|
2409
|
+
WHERE ${sql3.unsafe(table.leases)}.expires_at <= ${now.toISOString()}::timestamptz
|
|
2410
|
+
OR ${sql3.unsafe(table.leases)}.owner_id = EXCLUDED.owner_id
|
|
1744
2411
|
RETURNING owner_id
|
|
1745
2412
|
`;
|
|
1746
2413
|
return rows[0]?.owner_id === request.ownerId.trim();
|
|
1747
2414
|
},
|
|
1748
2415
|
release: async (feedId, ownerId) => {
|
|
1749
2416
|
await ensureSchema();
|
|
1750
|
-
const rows = await
|
|
1751
|
-
DELETE FROM ${
|
|
1752
|
-
WHERE feed_id = ${
|
|
1753
|
-
AND owner_id = ${
|
|
2417
|
+
const rows = await sql3`
|
|
2418
|
+
DELETE FROM ${sql3.unsafe(table.leases)}
|
|
2419
|
+
WHERE feed_id = ${requiredText2(feedId, "Feed lease feed id")}
|
|
2420
|
+
AND owner_id = ${requiredText2(ownerId, "Feed lease owner id")}
|
|
1754
2421
|
RETURNING feed_id
|
|
1755
2422
|
`;
|
|
1756
2423
|
return rows.length > 0;
|
|
@@ -1774,7 +2441,20 @@ var createPostgresVulnerabilityStore = (options) => {
|
|
|
1774
2441
|
};
|
|
1775
2442
|
};
|
|
1776
2443
|
export {
|
|
2444
|
+
vulnerabilityVexDecisions,
|
|
2445
|
+
vulnerabilityVexApplications,
|
|
2446
|
+
vulnerabilityRiskAssessments,
|
|
2447
|
+
vulnerabilityRemediationVerifications,
|
|
2448
|
+
vulnerabilityRemediationPlans,
|
|
2449
|
+
vulnerabilityRemediationExecutions,
|
|
1777
2450
|
vulnerabilityPostgresSchemaSql,
|
|
2451
|
+
vulnerabilityObservations,
|
|
2452
|
+
vulnerabilityFindings,
|
|
2453
|
+
vulnerabilityFeedSyncRuns,
|
|
2454
|
+
vulnerabilityFeedSnapshots,
|
|
2455
|
+
vulnerabilityFeedRecords,
|
|
2456
|
+
vulnerabilityFeedLeases,
|
|
2457
|
+
vulnerabilityCoreDrizzleSchema,
|
|
1778
2458
|
vulnerabilityAlertPostgresSchemaSql,
|
|
1779
2459
|
vulnerabilityAlertPolicyVersions,
|
|
1780
2460
|
vulnerabilityAlertIncidents,
|
|
@@ -1783,6 +2463,7 @@ export {
|
|
|
1783
2463
|
vulnerabilityAlertDeliveries,
|
|
1784
2464
|
createPostgresVulnerabilityStore,
|
|
1785
2465
|
createPostgresVulnerabilityAlertStores,
|
|
2466
|
+
createDrizzleVulnerabilityStore,
|
|
1786
2467
|
createDrizzleVulnerabilityAlertStores,
|
|
1787
2468
|
VulnerabilityAlertValidationError,
|
|
1788
2469
|
VulnerabilityAlertNotFoundError,
|