@oneuptime/common 14.0.96 → 14.0.97

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.
Files changed (215) hide show
  1. package/Models/AnalyticsModels/NetworkFlow.d.mts +4 -0
  2. package/Models/AnalyticsModels/NetworkFlow.d.ts +4 -0
  3. package/Models/AnalyticsModels/NetworkFlow.js +50 -0
  4. package/Models/DatabaseModels/Alert.d.mts +2 -0
  5. package/Models/DatabaseModels/Alert.d.ts +2 -0
  6. package/Models/DatabaseModels/Alert.js +63 -0
  7. package/Models/DatabaseModels/Incident.d.mts +2 -0
  8. package/Models/DatabaseModels/Incident.d.ts +2 -0
  9. package/Models/DatabaseModels/Incident.js +63 -0
  10. package/Models/DatabaseModels/Index.js +10 -0
  11. package/Models/DatabaseModels/NetworkAddressName.d.mts +14 -0
  12. package/Models/DatabaseModels/NetworkAddressName.d.ts +14 -0
  13. package/Models/DatabaseModels/NetworkAddressName.js +300 -0
  14. package/Models/DatabaseModels/NetworkAddressName.mjs +2 -0
  15. package/Models/DatabaseModels/NetworkDevice.d.mts +1 -0
  16. package/Models/DatabaseModels/NetworkDevice.d.ts +1 -0
  17. package/Models/DatabaseModels/NetworkDevice.js +38 -0
  18. package/Models/DatabaseModels/SecurityCase.d.mts +8 -0
  19. package/Models/DatabaseModels/SecurityCase.d.ts +8 -0
  20. package/Models/DatabaseModels/SecurityCase.js +145 -0
  21. package/Models/DatabaseModels/SecurityCaseEvidence.d.mts +28 -0
  22. package/Models/DatabaseModels/SecurityCaseEvidence.d.ts +28 -0
  23. package/Models/DatabaseModels/SecurityCaseEvidence.js +489 -0
  24. package/Models/DatabaseModels/SecurityCaseEvidence.mjs +2 -0
  25. package/Models/DatabaseModels/SecurityCaseFeed.d.mts +4 -1
  26. package/Models/DatabaseModels/SecurityCaseFeed.d.ts +4 -1
  27. package/Models/DatabaseModels/SecurityCaseFeed.js +6 -0
  28. package/Models/DatabaseModels/SecurityCasePriority.d.mts +2 -0
  29. package/Models/DatabaseModels/SecurityCasePriority.d.ts +2 -0
  30. package/Models/DatabaseModels/SecurityCasePriority.js +44 -0
  31. package/Models/DatabaseModels/SecurityCaseTask.d.mts +22 -0
  32. package/Models/DatabaseModels/SecurityCaseTask.d.ts +22 -0
  33. package/Models/DatabaseModels/SecurityCaseTask.js +467 -0
  34. package/Models/DatabaseModels/SecurityCaseTask.mjs +2 -0
  35. package/Models/DatabaseModels/SecurityWatchlist.d.mts +22 -0
  36. package/Models/DatabaseModels/SecurityWatchlist.d.ts +22 -0
  37. package/Models/DatabaseModels/SecurityWatchlist.js +411 -0
  38. package/Models/DatabaseModels/SecurityWatchlist.mjs +2 -0
  39. package/Models/DatabaseModels/SecurityWatchlistItem.d.mts +17 -0
  40. package/Models/DatabaseModels/SecurityWatchlistItem.d.ts +17 -0
  41. package/Models/DatabaseModels/SecurityWatchlistItem.js +321 -0
  42. package/Models/DatabaseModels/SecurityWatchlistItem.mjs +2 -0
  43. package/Types/AI/AiAffectedResources.d.mts +2 -1
  44. package/Types/AI/AiAffectedResources.d.ts +2 -1
  45. package/Types/AI/AiAffectedResources.js +12 -1
  46. package/Types/AffectedResources/AffectedResourceSearch.d.mts +53 -0
  47. package/Types/AffectedResources/AffectedResourceSearch.d.ts +53 -0
  48. package/Types/AffectedResources/AffectedResourceSearch.js +224 -0
  49. package/Types/AffectedResources/AffectedResourceSearch.mjs +11 -0
  50. package/Types/ArchivableValue/ArchivableValueUsage.d.mts +21 -2
  51. package/Types/ArchivableValue/ArchivableValueUsage.d.ts +21 -2
  52. package/Types/ArchivableValue/ArchivableValueUsage.js +91 -12
  53. package/Types/ArchivableValue/ArchivableValueUsage.mjs +1 -0
  54. package/Types/Color.d.mts +0 -2
  55. package/Types/Color.d.ts +0 -2
  56. package/Types/Color.js +0 -14
  57. package/Types/Database/DatabaseProperty.d.mts +0 -2
  58. package/Types/Database/DatabaseProperty.d.ts +0 -2
  59. package/Types/Database/DatabaseProperty.js +0 -3
  60. package/Types/Date.d.mts +0 -2
  61. package/Types/Date.d.ts +0 -2
  62. package/Types/Date.js +0 -23
  63. package/Types/Domain.d.mts +0 -2
  64. package/Types/Domain.d.ts +0 -2
  65. package/Types/Domain.js +0 -14
  66. package/Types/Email/EmailTemplateType.d.mts +2 -0
  67. package/Types/Email/EmailTemplateType.d.ts +2 -0
  68. package/Types/Email/EmailTemplateType.js +2 -0
  69. package/Types/Email.d.mts +0 -2
  70. package/Types/Email.d.ts +0 -2
  71. package/Types/Email.js +0 -15
  72. package/Types/IP/IP.d.mts +0 -2
  73. package/Types/IP/IP.d.ts +0 -2
  74. package/Types/IP/IP.js +0 -14
  75. package/Types/Monitor/CriteriaAlert.d.mts +0 -2
  76. package/Types/Monitor/CriteriaAlert.d.ts +0 -2
  77. package/Types/Monitor/CriteriaAlert.js +0 -18
  78. package/Types/Monitor/CriteriaAlert.mjs +1 -2
  79. package/Types/Monitor/CriteriaFilter.d.mts +0 -2
  80. package/Types/Monitor/CriteriaFilter.d.ts +0 -2
  81. package/Types/Monitor/CriteriaFilter.js +1 -42
  82. package/Types/Monitor/CriteriaFilter.mjs +0 -1
  83. package/Types/Monitor/CriteriaIncident.d.mts +0 -2
  84. package/Types/Monitor/CriteriaIncident.d.ts +0 -2
  85. package/Types/Monitor/CriteriaIncident.js +0 -23
  86. package/Types/Monitor/CriteriaIncident.mjs +1 -2
  87. package/Types/Monitor/IncomingMonitor/IncidentGroupingConfig.d.mts +0 -2
  88. package/Types/Monitor/IncomingMonitor/IncidentGroupingConfig.d.ts +0 -2
  89. package/Types/Monitor/IncomingMonitor/IncidentGroupingConfig.js +0 -11
  90. package/Types/Monitor/IncomingMonitor/IncidentGroupingConfig.mjs +1 -2
  91. package/Types/Monitor/MonitorCriteria.d.mts +0 -2
  92. package/Types/Monitor/MonitorCriteria.d.ts +0 -2
  93. package/Types/Monitor/MonitorCriteria.js +0 -21
  94. package/Types/Monitor/MonitorCriteriaInstance.d.mts +0 -2
  95. package/Types/Monitor/MonitorCriteriaInstance.d.ts +0 -2
  96. package/Types/Monitor/MonitorCriteriaInstance.js +0 -54
  97. package/Types/Monitor/MonitorStep.d.mts +0 -2
  98. package/Types/Monitor/MonitorStep.d.ts +0 -2
  99. package/Types/Monitor/MonitorStep.js +0 -80
  100. package/Types/Monitor/MonitorSteps.d.mts +0 -2
  101. package/Types/Monitor/MonitorSteps.d.ts +0 -2
  102. package/Types/Monitor/MonitorSteps.js +0 -31
  103. package/Types/Name.d.mts +0 -2
  104. package/Types/Name.d.ts +0 -2
  105. package/Types/Name.js +0 -14
  106. package/Types/NetFlow/NetworkAddressName.d.mts +30 -0
  107. package/Types/NetFlow/NetworkAddressName.d.ts +30 -0
  108. package/Types/NetFlow/NetworkAddressName.js +149 -0
  109. package/Types/NetFlow/NetworkAddressName.mjs +6 -0
  110. package/Types/NetFlow/NetworkTraffic.d.mts +20 -0
  111. package/Types/NetFlow/NetworkTraffic.d.ts +20 -0
  112. package/Types/NetFlow/NetworkTraffic.js +5 -1
  113. package/Types/NetFlow/NetworkTraffic.mjs +2 -0
  114. package/Types/NetworkController/NetworkControllerReadSummary.d.mts +2 -0
  115. package/Types/NetworkController/NetworkControllerReadSummary.d.ts +2 -0
  116. package/Types/NetworkController/NetworkControllerReadSummary.js +7 -1
  117. package/Types/NetworkDevice/NetworkDeviceDiscoveredDetails.d.mts +47 -1
  118. package/Types/NetworkDevice/NetworkDeviceDiscoveredDetails.d.ts +47 -1
  119. package/Types/NetworkDevice/NetworkDeviceDiscoveredDetails.js +173 -8
  120. package/Types/NetworkDevice/NetworkDeviceDiscoveredDetails.mjs +7 -0
  121. package/Types/NotificationSetting/NotificationEmailRollupCategory.js +3 -0
  122. package/Types/NotificationSetting/NotificationEmailRollupPolicy.js +6 -0
  123. package/Types/NotificationSetting/NotificationSettingEventType.d.mts +2 -0
  124. package/Types/NotificationSetting/NotificationSettingEventType.d.ts +2 -0
  125. package/Types/NotificationSetting/NotificationSettingEventType.js +9 -0
  126. package/Types/ObjectID.d.mts +0 -1
  127. package/Types/ObjectID.d.ts +0 -1
  128. package/Types/ObjectID.js +0 -9
  129. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRunEnding.d.mts +4 -0
  130. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRunEnding.d.ts +4 -0
  131. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRunEnding.js +25 -1
  132. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRunEnding.mjs +4 -0
  133. package/Types/OnCallDutyPolicy/OnCallEmptyLevel.d.mts +15 -0
  134. package/Types/OnCallDutyPolicy/OnCallEmptyLevel.d.ts +15 -0
  135. package/Types/OnCallDutyPolicy/OnCallEmptyLevel.js +118 -0
  136. package/Types/OnCallDutyPolicy/OnCallEmptyLevel.mjs +9 -0
  137. package/Types/Permission.d.mts +8 -0
  138. package/Types/Permission.d.ts +8 -0
  139. package/Types/Permission.js +87 -3
  140. package/Types/Phone.d.mts +0 -2
  141. package/Types/Phone.d.ts +0 -2
  142. package/Types/Phone.js +0 -14
  143. package/Types/Port.d.mts +0 -2
  144. package/Types/Port.d.ts +0 -2
  145. package/Types/Port.js +0 -14
  146. package/Types/ProviderLogo/ProviderLogo.d.mts +8 -1
  147. package/Types/ProviderLogo/ProviderLogo.d.ts +8 -1
  148. package/Types/ProviderLogo/ProviderLogo.js +14 -0
  149. package/Types/SecurityCase/SecurityCaseEvidenceKind.d.mts +7 -0
  150. package/Types/SecurityCase/SecurityCaseEvidenceKind.d.ts +7 -0
  151. package/Types/SecurityCase/SecurityCaseEvidenceKind.js +24 -0
  152. package/Types/SecurityCase/SecurityCaseEvidenceKind.mjs +4 -0
  153. package/Types/SecurityEvent/SecurityWatchlist.d.mts +167 -0
  154. package/Types/SecurityEvent/SecurityWatchlist.d.ts +167 -0
  155. package/Types/SecurityEvent/SecurityWatchlist.js +648 -0
  156. package/Types/SecurityEvent/SecurityWatchlist.mjs +51 -0
  157. package/Types/SecurityEvent/SigmaRule.d.mts +2 -0
  158. package/Types/SecurityEvent/SigmaRule.d.ts +2 -0
  159. package/Types/SecurityEvent/SigmaRule.js +5 -0
  160. package/Types/Telemetry/OpenTelemetryGuides.js +177 -5
  161. package/Types/Version.d.mts +0 -2
  162. package/Types/Version.d.ts +0 -2
  163. package/Types/Version.js +0 -14
  164. package/Types/Workflow/AffectedResourcesSetting.d.mts +13 -0
  165. package/Types/Workflow/AffectedResourcesSetting.d.ts +13 -0
  166. package/Types/Workflow/AffectedResourcesSetting.js +120 -0
  167. package/Types/Workflow/AffectedResourcesSetting.mjs +8 -0
  168. package/Types/Workflow/Components/BaseModel.js +15 -3
  169. package/Types/Workflow/Documentation/DatabaseDocumentation.js +36 -0
  170. package/Utils/Inventory/AssetFactSource.d.mts +6 -2
  171. package/Utils/Inventory/AssetFactSource.d.ts +6 -2
  172. package/Utils/Inventory/AssetFactSource.js +18 -1
  173. package/Utils/Inventory/AssetFactSource.mjs +1 -0
  174. package/Utils/Markdown/FeedLead.d.mts +10 -0
  175. package/Utils/Markdown/FeedLead.d.ts +10 -0
  176. package/Utils/Markdown/FeedLead.js +198 -0
  177. package/Utils/Markdown/FeedLead.mjs +8 -0
  178. package/Utils/NetworkDevice/NetworkDeviceAssetFacts.d.mts +9 -1
  179. package/Utils/NetworkDevice/NetworkDeviceAssetFacts.d.ts +9 -1
  180. package/Utils/NetworkDevice/NetworkDeviceAssetFacts.js +139 -18
  181. package/Utils/NetworkDevice/NetworkDeviceAssetFacts.mjs +1 -0
  182. package/Utils/NetworkDevice/NetworkDeviceRefresh.d.mts +88 -0
  183. package/Utils/NetworkDevice/NetworkDeviceRefresh.d.ts +88 -0
  184. package/Utils/NetworkDevice/NetworkDeviceRefresh.js +232 -0
  185. package/Utils/NetworkDevice/NetworkDeviceRefresh.mjs +16 -0
  186. package/Utils/NetworkTraffic/NetworkAddressBlock.d.mts +20 -0
  187. package/Utils/NetworkTraffic/NetworkAddressBlock.d.ts +20 -0
  188. package/Utils/NetworkTraffic/NetworkAddressBlock.js +264 -0
  189. package/Utils/NetworkTraffic/NetworkAddressBlock.mjs +3 -0
  190. package/Utils/Schema/MonitorSchemas.d.mts +9 -0
  191. package/Utils/Schema/MonitorSchemas.d.ts +9 -0
  192. package/Utils/Schema/MonitorSchemas.js +291 -0
  193. package/Utils/Schema/MonitorSchemas.mjs +9 -0
  194. package/Utils/Schema/TypeSchemas.d.mts +12 -0
  195. package/Utils/Schema/TypeSchemas.d.ts +12 -0
  196. package/Utils/Schema/TypeSchemas.js +176 -0
  197. package/Utils/Schema/TypeSchemas.mjs +11 -0
  198. package/Utils/Schema/Zod.js +17 -17
  199. package/Utils/SecurityCase/SecurityCaseMarkdown.d.mts +34 -0
  200. package/Utils/SecurityCase/SecurityCaseMarkdown.d.ts +34 -0
  201. package/Utils/SecurityCase/SecurityCaseMarkdown.js +69 -0
  202. package/Utils/SecurityCase/SecurityCaseMarkdown.mjs +9 -0
  203. package/Utils/SecurityCase/SecurityCasePriorities.d.mts +2 -0
  204. package/Utils/SecurityCase/SecurityCasePriorities.d.ts +2 -0
  205. package/Utils/SecurityCase/SecurityCasePriorities.js +15 -1
  206. package/Utils/SecurityCase/SecurityCaseTargets.d.mts +128 -0
  207. package/Utils/SecurityCase/SecurityCaseTargets.d.ts +128 -0
  208. package/Utils/SecurityCase/SecurityCaseTargets.js +482 -0
  209. package/Utils/SecurityCase/SecurityCaseTargets.mjs +28 -0
  210. package/Utils/SecurityEvent/Sigma/SigmaRuleParser.js +22 -0
  211. package/Utils/SecurityEvent/Sigma/SigmaWatchlists.d.mts +24 -0
  212. package/Utils/SecurityEvent/Sigma/SigmaWatchlists.d.ts +24 -0
  213. package/Utils/SecurityEvent/Sigma/SigmaWatchlists.js +183 -0
  214. package/Utils/SecurityEvent/Sigma/SigmaWatchlists.mjs +9 -0
  215. package/package.json +1 -1
@@ -0,0 +1,648 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SecurityWatchlistImportMode = exports.SecurityWatchlistValueMatch = exports.SECURITY_WATCHLIST_MESSAGES = exports.SECURITY_WATCHLIST_WILDCARD = exports.SECURITY_WATCHLIST_IMPORT_MAX_CHARACTERS = exports.SECURITY_WATCHLISTS_PER_PROJECT_MAX = exports.SECURITY_WATCHLIST_NOTE_MAX_LENGTH = exports.SECURITY_WATCHLIST_VALUE_MAX_LENGTH = exports.SECURITY_WATCHLIST_RANGE_VALUES_MAX = exports.SECURITY_WATCHLIST_PATTERN_VALUES_MAX = exports.SECURITY_WATCHLIST_VALUES_MAX = exports.SECURITY_WATCHLIST_DESCRIPTION_MAX_LENGTH = exports.SECURITY_WATCHLIST_NAME_MAX_LENGTH = exports.SECURITY_WATCHLIST_PLACEHOLDER_MARK = exports.SECURITY_WATCHLIST_MODIFIER = exports.SECURITY_WATCHLIST_DEFAULT_SNIPPET_FIELD = exports.SECURITY_WATCHLIST_SNIPPET_FIELDS = exports.SECURITY_WATCHLIST_FEED_ENTITY_TYPES = exports.SECURITY_WATCHLIST_FEED_INDICATOR_TYPES = exports.SECURITY_WATCHLIST_ENTITY_TYPES = exports.SECURITY_WATCHLIST_SOURCES = exports.SecurityWatchlistSource = void 0;
4
+ exports.isSecurityWatchlistSource = isSecurityWatchlistSource;
5
+ exports.isSecurityWatchlistEntityType = isSecurityWatchlistEntityType;
6
+ exports.canSecurityWatchlistFollowFeed = canSecurityWatchlistFollowFeed;
7
+ exports.getSecurityWatchlistFeedIndicatorTypes = getSecurityWatchlistFeedIndicatorTypes;
8
+ exports.normalizeSecurityWatchlistName = normalizeSecurityWatchlistName;
9
+ exports.getSecurityWatchlistNameKey = getSecurityWatchlistNameKey;
10
+ exports.isSecurityWatchlistName = isSecurityWatchlistName;
11
+ exports.getSecurityWatchlistPlaceholder = getSecurityWatchlistPlaceholder;
12
+ exports.readSecurityWatchlistPlaceholder = readSecurityWatchlistPlaceholder;
13
+ exports.getMissingSecurityWatchlistsMessage = getMissingSecurityWatchlistsMessage;
14
+ exports.getSecurityWatchlistSnippetField = getSecurityWatchlistSnippetField;
15
+ exports.getSecurityWatchlistRuleSnippet = getSecurityWatchlistRuleSnippet;
16
+ exports.normalizeSecurityWatchlistValue = normalizeSecurityWatchlistValue;
17
+ exports.getSecurityWatchlistValueKey = getSecurityWatchlistValueKey;
18
+ exports.normalizeSecurityWatchlistNote = normalizeSecurityWatchlistNote;
19
+ exports.getSecurityWatchlistValueMatch = getSecurityWatchlistValueMatch;
20
+ exports.getSecurityWatchlistValueProblem = getSecurityWatchlistValueProblem;
21
+ exports.getSecurityWatchlistNoteProblem = getSecurityWatchlistNoteProblem;
22
+ exports.getSecurityWatchlistNameProblem = getSecurityWatchlistNameProblem;
23
+ exports.getSecurityWatchlistProblems = getSecurityWatchlistProblems;
24
+ exports.getSecurityWatchlistProblem = getSecurityWatchlistProblem;
25
+ exports.isSecurityWatchlistImportMode = isSecurityWatchlistImportMode;
26
+ exports.readSecurityWatchlistImportLine = readSecurityWatchlistImportLine;
27
+ exports.parseSecurityWatchlistImport = parseSecurityWatchlistImport;
28
+ exports.countSecurityWatchlistValues = countSecurityWatchlistValues;
29
+ exports.getSecurityWatchlistSizeProblem = getSecurityWatchlistSizeProblem;
30
+ exports.splitSecurityWatchlistValues = splitSecurityWatchlistValues;
31
+ exports.matchesSecurityWatchlistPattern = matchesSecurityWatchlistPattern;
32
+ const SecurityEntity_1 = require("../SecurityCase/SecurityEntity");
33
+ const DetectionRuleException_1 = require("./DetectionRuleException");
34
+ const ThreatIntelConstants_1 = require("./ThreatIntelConstants");
35
+ /*
36
+ * WATCHLISTS: LISTS A TEAM KEEPS THAT RULES MATCH AGAINST.
37
+ *
38
+ * VIP users, critical hosts, known-bad file hashes, the addresses admins
39
+ * may sign in from: values a team knows about its own world, kept in one
40
+ * list each so every detection and correlation rule can read them by name
41
+ * rather than repeat them. A rule reads a watchlist the way Sigma writes a
42
+ * value kept outside the rule - a placeholder, with the `expand` modifier:
43
+ *
44
+ * detection:
45
+ * selection:
46
+ * principalUser|expand: '%vip_users%'
47
+ * condition: selection
48
+ *
49
+ * A watchlist holds one kind of thing (users, hosts, IP addresses...) and
50
+ * its values come from one of two places:
51
+ *
52
+ * - values the team keeps: added by hand or imported from a file, each
53
+ * with an optional note;
54
+ * - a threat intel feed: the feed's active indicators of the list's kind,
55
+ * kept up to date by the feed itself (an IP address list follows a
56
+ * feed's addresses).
57
+ *
58
+ * Values are matched as rule exceptions, protected entities and entity
59
+ * criticality match theirs: whatever the case, with * for any run of
60
+ * characters (svc-* is every service account), and an IP address list may
61
+ * hold ranges (10.20.0.0/16).
62
+ *
63
+ * Kept free of anything server-side: the Dashboard's forms, the import and
64
+ * the list read the same rules the API enforces. Each message below is a
65
+ * Dashboard translation key, read from here by the string extractor, so a
66
+ * form shows it in the reader's language and the API answers in the same
67
+ * words.
68
+ */
69
+ // Where a watchlist's values come from.
70
+ var SecurityWatchlistSource;
71
+ (function (SecurityWatchlistSource) {
72
+ // Values the team adds by hand or imports.
73
+ SecurityWatchlistSource["Values"] = "Values";
74
+ // A threat intel feed's active indicators of the list's kind.
75
+ SecurityWatchlistSource["ThreatIntelFeed"] = "Threat Intel Feed";
76
+ })(SecurityWatchlistSource || (exports.SecurityWatchlistSource = SecurityWatchlistSource = {}));
77
+ exports.SECURITY_WATCHLIST_SOURCES = [SecurityWatchlistSource.Values, SecurityWatchlistSource.ThreatIntelFeed];
78
+ /*
79
+ * What a watchlist can hold, in the order the form offers them: the kinds
80
+ * of entity a security event names, and Other for any value (an
81
+ * application, a user agent, a country).
82
+ */
83
+ exports.SECURITY_WATCHLIST_ENTITY_TYPES = [
84
+ SecurityEntity_1.SecurityEntityType.User,
85
+ SecurityEntity_1.SecurityEntityType.Host,
86
+ SecurityEntity_1.SecurityEntityType.IpAddress,
87
+ SecurityEntity_1.SecurityEntityType.FileHash,
88
+ SecurityEntity_1.SecurityEntityType.Domain,
89
+ SecurityEntity_1.SecurityEntityType.Url,
90
+ SecurityEntity_1.SecurityEntityType.Process,
91
+ SecurityEntity_1.SecurityEntityType.Other,
92
+ ];
93
+ /*
94
+ * The indicator types a watchlist of each kind takes from a threat intel
95
+ * feed. Users, hosts, processes and other values have no indicator type: a
96
+ * list of them is kept by the team.
97
+ */
98
+ exports.SECURITY_WATCHLIST_FEED_INDICATOR_TYPES = {
99
+ [SecurityEntity_1.SecurityEntityType.IpAddress]: [
100
+ ThreatIntelConstants_1.ThreatIntelIndicatorType.Ipv4Address,
101
+ ThreatIntelConstants_1.ThreatIntelIndicatorType.Ipv6Address,
102
+ ],
103
+ [SecurityEntity_1.SecurityEntityType.FileHash]: [
104
+ ThreatIntelConstants_1.ThreatIntelIndicatorType.FileHashSha256,
105
+ ThreatIntelConstants_1.ThreatIntelIndicatorType.FileHashSha1,
106
+ ThreatIntelConstants_1.ThreatIntelIndicatorType.FileHashMd5,
107
+ ],
108
+ [SecurityEntity_1.SecurityEntityType.Domain]: [ThreatIntelConstants_1.ThreatIntelIndicatorType.DomainName],
109
+ [SecurityEntity_1.SecurityEntityType.Url]: [ThreatIntelConstants_1.ThreatIntelIndicatorType.Url],
110
+ };
111
+ // The kinds a watchlist can take from a threat intel feed, in the form's order.
112
+ exports.SECURITY_WATCHLIST_FEED_ENTITY_TYPES = exports.SECURITY_WATCHLIST_ENTITY_TYPES.filter((type) => {
113
+ return Boolean(exports.SECURITY_WATCHLIST_FEED_INDICATOR_TYPES[type]);
114
+ });
115
+ /*
116
+ * The event field a rule most often matches a watchlist of each kind
117
+ * against: the snippet a watchlist's page offers starts with it. A kind
118
+ * with no field of its own is looked for among the event's observables,
119
+ * which hold every address, domain, URL and hash an event names.
120
+ */
121
+ exports.SECURITY_WATCHLIST_SNIPPET_FIELDS = {
122
+ [SecurityEntity_1.SecurityEntityType.User]: "principalUser",
123
+ [SecurityEntity_1.SecurityEntityType.Host]: "principalHost",
124
+ [SecurityEntity_1.SecurityEntityType.IpAddress]: "principalIp",
125
+ [SecurityEntity_1.SecurityEntityType.Process]: "processName",
126
+ };
127
+ exports.SECURITY_WATCHLIST_DEFAULT_SNIPPET_FIELD = "observables";
128
+ // The Sigma modifier a rule reads a watchlist with: `field|expand: '%name%'`.
129
+ exports.SECURITY_WATCHLIST_MODIFIER = "expand";
130
+ // What wraps a watchlist's name in a rule: '%vip_users%'.
131
+ exports.SECURITY_WATCHLIST_PLACEHOLDER_MARK = "%";
132
+ /*
133
+ * Limits. A name is what rules write, so it is short and plain. A list's
134
+ * values travel to the database with every run of a rule that reads it, so
135
+ * a list stays a size one run can send; a pattern or a range costs a
136
+ * comparison of its own for every event, so a list keeps few of them. A
137
+ * list too long to keep by hand belongs in a threat intel feed, which a
138
+ * watchlist can follow without a limit of its own.
139
+ */
140
+ exports.SECURITY_WATCHLIST_NAME_MAX_LENGTH = 50;
141
+ exports.SECURITY_WATCHLIST_DESCRIPTION_MAX_LENGTH = 500;
142
+ exports.SECURITY_WATCHLIST_VALUES_MAX = 5000;
143
+ exports.SECURITY_WATCHLIST_PATTERN_VALUES_MAX = 100;
144
+ exports.SECURITY_WATCHLIST_RANGE_VALUES_MAX = 100;
145
+ exports.SECURITY_WATCHLIST_VALUE_MAX_LENGTH = 256;
146
+ exports.SECURITY_WATCHLIST_NOTE_MAX_LENGTH = 500;
147
+ // The most watchlists one project keeps.
148
+ exports.SECURITY_WATCHLISTS_PER_PROJECT_MAX = 200;
149
+ // The most text one import reads: 5,000 lines of a long value and a note.
150
+ exports.SECURITY_WATCHLIST_IMPORT_MAX_CHARACTERS = 4 * 1024 * 1024;
151
+ exports.SECURITY_WATCHLIST_WILDCARD = "*";
152
+ /*
153
+ * A name: a letter, then letters, digits and underscores - the words a
154
+ * Sigma placeholder is made of, so a rule written for another tool reads
155
+ * the same list.
156
+ */
157
+ const NAME_REGEX = /^[A-Za-z][A-Za-z0-9_]*$/;
158
+ // A file hash: the hex digest of MD5, SHA-1, SHA-256 or SHA-512.
159
+ const FILE_HASH_REGEX = /^(?:[0-9a-f]{32}|[0-9a-f]{40}|[0-9a-f]{64}|[0-9a-f]{128})$/i;
160
+ /*
161
+ * Every problem the rules below answer with, as Dashboard translation keys:
162
+ * the string extractor reads each `message`, so a form shows it in the
163
+ * reader's language, and the API answers in the same words. The numbers
164
+ * are written out, so a translator reads whole sentences; a test holds each
165
+ * one to its constant.
166
+ */
167
+ exports.SECURITY_WATCHLIST_MESSAGES = {
168
+ enterValue: { message: "Enter a value." },
169
+ loneWildcard: { message: "A value of only * would match everything." },
170
+ valueTooLong: { message: "A value is at most 256 characters." },
171
+ valueNotOneLine: { message: "A value is one line, without tabs." },
172
+ notAnAddress: {
173
+ message: "Enter an IP address, a range such as 10.20.0.0/16, or a pattern with *.",
174
+ },
175
+ notAHash: { message: "Enter an MD5, SHA-1, SHA-256 or SHA-512 hash." },
176
+ noteTooLong: { message: "A note is at most 500 characters." },
177
+ enterName: { message: "Enter a name, such as vip_users." },
178
+ nameTooLong: { message: "A name is at most 50 characters." },
179
+ nameCharacters: {
180
+ message: "Use letters, digits and underscores, starting with a letter, such as vip_users.",
181
+ },
182
+ tooManyValues: {
183
+ message: "A watchlist holds at most 5,000 values. Follow a threat intel feed for a longer list.",
184
+ },
185
+ tooManyPatterns: { message: "A watchlist holds at most 100 values with *." },
186
+ tooManyRanges: { message: "A watchlist holds at most 100 address ranges." },
187
+ };
188
+ // How a value matches: as written, as a pattern with *, or as an address range.
189
+ var SecurityWatchlistValueMatch;
190
+ (function (SecurityWatchlistValueMatch) {
191
+ SecurityWatchlistValueMatch["Exact"] = "exact";
192
+ SecurityWatchlistValueMatch["Pattern"] = "pattern";
193
+ SecurityWatchlistValueMatch["Range"] = "range";
194
+ })(SecurityWatchlistValueMatch || (exports.SecurityWatchlistValueMatch = SecurityWatchlistValueMatch = {}));
195
+ function isSecurityWatchlistSource(value) {
196
+ return (typeof value === "string" &&
197
+ exports.SECURITY_WATCHLIST_SOURCES.includes(value));
198
+ }
199
+ function isSecurityWatchlistEntityType(value) {
200
+ return (typeof value === "string" &&
201
+ exports.SECURITY_WATCHLIST_ENTITY_TYPES.includes(value));
202
+ }
203
+ function canSecurityWatchlistFollowFeed(value) {
204
+ return (typeof value === "string" &&
205
+ exports.SECURITY_WATCHLIST_FEED_ENTITY_TYPES.includes(value));
206
+ }
207
+ // The indicator types a list of this kind follows in a feed: empty for a kind no feed carries.
208
+ function getSecurityWatchlistFeedIndicatorTypes(entityType) {
209
+ if (!canSecurityWatchlistFollowFeed(entityType)) {
210
+ return [];
211
+ }
212
+ return [
213
+ ...(exports.SECURITY_WATCHLIST_FEED_INDICATOR_TYPES[entityType] || []),
214
+ ];
215
+ }
216
+ // A name as stored: trimmed.
217
+ function normalizeSecurityWatchlistName(value) {
218
+ return typeof value === "string" ? value.trim() : "";
219
+ }
220
+ /*
221
+ * The key a name is found by: names are told apart whatever their case, so
222
+ * VIP_Users and vip_users are one list, and a rule may write either.
223
+ */
224
+ function getSecurityWatchlistNameKey(value) {
225
+ return normalizeSecurityWatchlistName(value).toLowerCase();
226
+ }
227
+ function isSecurityWatchlistName(value) {
228
+ const name = normalizeSecurityWatchlistName(value);
229
+ return (name.length > 0 &&
230
+ name.length <= exports.SECURITY_WATCHLIST_NAME_MAX_LENGTH &&
231
+ NAME_REGEX.test(name));
232
+ }
233
+ // What a rule writes for a watchlist: '%vip_users%'.
234
+ function getSecurityWatchlistPlaceholder(name) {
235
+ return `${exports.SECURITY_WATCHLIST_PLACEHOLDER_MARK}${normalizeSecurityWatchlistName(name)}${exports.SECURITY_WATCHLIST_PLACEHOLDER_MARK}`;
236
+ }
237
+ /*
238
+ * The watchlist a rule's value names, or null when the value is not a
239
+ * placeholder: the whole value, a name between two % signs.
240
+ */
241
+ function readSecurityWatchlistPlaceholder(value) {
242
+ if (typeof value !== "string") {
243
+ return null;
244
+ }
245
+ const text = value.trim();
246
+ const mark = exports.SECURITY_WATCHLIST_PLACEHOLDER_MARK;
247
+ if (text.length < 3 ||
248
+ !text.startsWith(mark) ||
249
+ !text.endsWith(mark) ||
250
+ text.slice(1, -1).includes(mark)) {
251
+ return null;
252
+ }
253
+ const name = text.slice(1, -1);
254
+ return isSecurityWatchlistName(name) ? name : null;
255
+ }
256
+ /*
257
+ * What a rule that names lists the project does not have is told: when it
258
+ * is saved, and as its error should a list it reads be gone at a run.
259
+ */
260
+ function getMissingSecurityWatchlistsMessage(names) {
261
+ const list = names.join(", ");
262
+ return names.length > 1
263
+ ? `There are no watchlists named ${list} in this project. Create them under Security Events > Detections > Watchlists, or fix their names in the rule.`
264
+ : `There is no watchlist named ${list} in this project. Create it under Security Events > Detections > Watchlists, or fix its name in the rule.`;
265
+ }
266
+ // The event field the snippet for a list of this kind matches.
267
+ function getSecurityWatchlistSnippetField(entityType) {
268
+ return typeof entityType === "string" &&
269
+ Object.prototype.hasOwnProperty.call(exports.SECURITY_WATCHLIST_SNIPPET_FIELDS, entityType)
270
+ ? exports.SECURITY_WATCHLIST_SNIPPET_FIELDS[entityType]
271
+ : exports.SECURITY_WATCHLIST_DEFAULT_SNIPPET_FIELD;
272
+ }
273
+ /*
274
+ * A rule that reads the watchlist, to copy into Detection Rules: the
275
+ * selection matches the list's usual field, and the rule fires on it.
276
+ */
277
+ function getSecurityWatchlistRuleSnippet(data) {
278
+ const field = getSecurityWatchlistSnippetField(data.entityType);
279
+ return [
280
+ "detection:",
281
+ " selection:",
282
+ ` ${field}|${exports.SECURITY_WATCHLIST_MODIFIER}: '${getSecurityWatchlistPlaceholder(data.name)}'`,
283
+ " condition: selection",
284
+ ].join("\n");
285
+ }
286
+ // A value as stored: trimmed, with no run of wildcards.
287
+ function normalizeSecurityWatchlistValue(value) {
288
+ if (typeof value !== "string") {
289
+ return "";
290
+ }
291
+ let text = value.trim();
292
+ while (text.includes("**")) {
293
+ text = text.split("**").join("*");
294
+ }
295
+ return text;
296
+ }
297
+ // The key a value is told apart by in its list: whatever the case.
298
+ function getSecurityWatchlistValueKey(value) {
299
+ return normalizeSecurityWatchlistValue(value).toLowerCase();
300
+ }
301
+ // A note as stored: trimmed.
302
+ function normalizeSecurityWatchlistNote(value) {
303
+ return typeof value === "string" ? value.trim() : "";
304
+ }
305
+ /*
306
+ * How a value matches events: an address range in an IP address list, a
307
+ * pattern when it holds a *, or as written.
308
+ */
309
+ function getSecurityWatchlistValueMatch(data) {
310
+ const value = normalizeSecurityWatchlistValue(data.value);
311
+ if (data.entityType === SecurityEntity_1.SecurityEntityType.IpAddress &&
312
+ (0, DetectionRuleException_1.isDetectionRuleExceptionCidr)(value)) {
313
+ return SecurityWatchlistValueMatch.Range;
314
+ }
315
+ if (value.includes(exports.SECURITY_WATCHLIST_WILDCARD)) {
316
+ return SecurityWatchlistValueMatch.Pattern;
317
+ }
318
+ return SecurityWatchlistValueMatch.Exact;
319
+ }
320
+ // Whether the text holds a character no value carries: a tab, a line break, any control character.
321
+ function hasControlCharacter(text) {
322
+ for (let index = 0; index < text.length; index++) {
323
+ const code = text.charCodeAt(index);
324
+ if (code < 32 || code === 127) {
325
+ return true;
326
+ }
327
+ }
328
+ return false;
329
+ }
330
+ /*
331
+ * What is wrong with one value for a list of this kind, or null when it can
332
+ * be kept: missing, a lone * (which would match everything), too long, or
333
+ * not what the list holds - an IP address list holds addresses, ranges and
334
+ * patterns, and a file hash list hex digests.
335
+ */
336
+ function getSecurityWatchlistValueProblem(data) {
337
+ const value = normalizeSecurityWatchlistValue(data.value);
338
+ if (!value) {
339
+ return exports.SECURITY_WATCHLIST_MESSAGES.enterValue.message;
340
+ }
341
+ if (value === exports.SECURITY_WATCHLIST_WILDCARD) {
342
+ return exports.SECURITY_WATCHLIST_MESSAGES.loneWildcard.message;
343
+ }
344
+ if (value.length > exports.SECURITY_WATCHLIST_VALUE_MAX_LENGTH) {
345
+ return exports.SECURITY_WATCHLIST_MESSAGES.valueTooLong.message;
346
+ }
347
+ if (hasControlCharacter(value)) {
348
+ return exports.SECURITY_WATCHLIST_MESSAGES.valueNotOneLine.message;
349
+ }
350
+ if (data.entityType === SecurityEntity_1.SecurityEntityType.IpAddress) {
351
+ if (!(0, SecurityEntity_1.isIpAddress)(value) &&
352
+ !(0, DetectionRuleException_1.isDetectionRuleExceptionCidr)(value) &&
353
+ !value.includes(exports.SECURITY_WATCHLIST_WILDCARD)) {
354
+ return exports.SECURITY_WATCHLIST_MESSAGES.notAnAddress.message;
355
+ }
356
+ }
357
+ if (data.entityType === SecurityEntity_1.SecurityEntityType.FileHash &&
358
+ !FILE_HASH_REGEX.test(value)) {
359
+ return exports.SECURITY_WATCHLIST_MESSAGES.notAHash.message;
360
+ }
361
+ return null;
362
+ }
363
+ // What is wrong with a note, or null.
364
+ function getSecurityWatchlistNoteProblem(value) {
365
+ if (normalizeSecurityWatchlistNote(value).length >
366
+ exports.SECURITY_WATCHLIST_NOTE_MAX_LENGTH) {
367
+ return exports.SECURITY_WATCHLIST_MESSAGES.noteTooLong.message;
368
+ }
369
+ return null;
370
+ }
371
+ function getSecurityWatchlistNameProblem(value) {
372
+ const name = normalizeSecurityWatchlistName(value);
373
+ if (!name) {
374
+ return exports.SECURITY_WATCHLIST_MESSAGES.enterName.message;
375
+ }
376
+ if (name.length > exports.SECURITY_WATCHLIST_NAME_MAX_LENGTH) {
377
+ return exports.SECURITY_WATCHLIST_MESSAGES.nameTooLong.message;
378
+ }
379
+ if (!NAME_REGEX.test(name)) {
380
+ return exports.SECURITY_WATCHLIST_MESSAGES.nameCharacters.message;
381
+ }
382
+ return null;
383
+ }
384
+ function getSecurityWatchlistProblems(watchlist) {
385
+ const problems = [];
386
+ const nameProblem = getSecurityWatchlistNameProblem(watchlist.name);
387
+ if (nameProblem) {
388
+ problems.push({ field: "name", message: nameProblem });
389
+ }
390
+ if (!isSecurityWatchlistEntityType(watchlist.entityType)) {
391
+ problems.push({
392
+ field: "entityType",
393
+ message: "Choose what the watchlist holds.",
394
+ });
395
+ }
396
+ if (typeof watchlist.description === "string" &&
397
+ watchlist.description.trim().length >
398
+ exports.SECURITY_WATCHLIST_DESCRIPTION_MAX_LENGTH) {
399
+ problems.push({
400
+ field: "description",
401
+ message: "A description is at most 500 characters.",
402
+ });
403
+ }
404
+ // A list kept by hand unless it says otherwise.
405
+ const source = watchlist.source || SecurityWatchlistSource.Values;
406
+ if (!isSecurityWatchlistSource(source)) {
407
+ problems.push({
408
+ field: "source",
409
+ message: "Choose where the values come from.",
410
+ });
411
+ return problems;
412
+ }
413
+ if (source === SecurityWatchlistSource.ThreatIntelFeed) {
414
+ if (isSecurityWatchlistEntityType(watchlist.entityType) &&
415
+ !canSecurityWatchlistFollowFeed(watchlist.entityType)) {
416
+ problems.push({
417
+ field: "source",
418
+ message: "A threat intel feed carries IP addresses, file hashes, domains and URLs. Keep a list of anything else by hand.",
419
+ });
420
+ }
421
+ if (!watchlist.threatIntelFeedId) {
422
+ problems.push({
423
+ field: "threatIntelFeedId",
424
+ message: "Choose the threat intel feed to follow.",
425
+ });
426
+ }
427
+ }
428
+ return problems;
429
+ }
430
+ // The first problem, or null when the watchlist can be saved: what the API answers.
431
+ function getSecurityWatchlistProblem(watchlist) {
432
+ const problems = getSecurityWatchlistProblems(watchlist);
433
+ return problems.length > 0 ? problems[0].message : null;
434
+ }
435
+ var SecurityWatchlistImportMode;
436
+ (function (SecurityWatchlistImportMode) {
437
+ // Add the values the list does not hold yet.
438
+ SecurityWatchlistImportMode["Add"] = "add";
439
+ // Make the list exactly the imported values.
440
+ SecurityWatchlistImportMode["Replace"] = "replace";
441
+ })(SecurityWatchlistImportMode || (exports.SecurityWatchlistImportMode = SecurityWatchlistImportMode = {}));
442
+ function isSecurityWatchlistImportMode(value) {
443
+ return (value === SecurityWatchlistImportMode.Add ||
444
+ value === SecurityWatchlistImportMode.Replace);
445
+ }
446
+ // A CSV header's first column, and its second: skipped on the first line.
447
+ const HEADER_VALUE_NAMES = ["value", "values"];
448
+ const HEADER_NOTE_NAMES = ["", "note", "notes"];
449
+ // Whether a line read from the top of an import is a CSV header rather than a value.
450
+ function isImportHeader(read) {
451
+ return (HEADER_VALUE_NAMES.includes(read.value.trim().toLowerCase()) &&
452
+ HEADER_NOTE_NAMES.includes(read.note.trim().toLowerCase()));
453
+ }
454
+ /*
455
+ * One line's first two fields, CSV-style: split at the first comma or tab
456
+ * outside double quotes; a quoted field drops its quotes and reads "" as ".
457
+ * Read in one pass, never with a regular expression.
458
+ */
459
+ function readSecurityWatchlistImportLine(line) {
460
+ const fields = [];
461
+ let current = "";
462
+ let inQuotes = false;
463
+ let index = 0;
464
+ while (index < line.length && fields.length < 1) {
465
+ const char = line[index];
466
+ if (inQuotes) {
467
+ if (char === '"') {
468
+ if (line[index + 1] === '"') {
469
+ current += '"';
470
+ index += 2;
471
+ continue;
472
+ }
473
+ inQuotes = false;
474
+ index++;
475
+ continue;
476
+ }
477
+ current += char;
478
+ index++;
479
+ continue;
480
+ }
481
+ if (char === '"' && current.trim() === "") {
482
+ current = "";
483
+ inQuotes = true;
484
+ index++;
485
+ continue;
486
+ }
487
+ if (char === "," || char === "\t") {
488
+ fields.push(current);
489
+ current = "";
490
+ index++;
491
+ continue;
492
+ }
493
+ current += char;
494
+ index++;
495
+ }
496
+ if (fields.length === 0) {
497
+ return { value: current.trim(), note: "" };
498
+ }
499
+ // The rest of the line is the note, its quotes dropped as a CSV's are.
500
+ let note = line.slice(index).trim();
501
+ if (note.length >= 2 && note.startsWith('"') && note.endsWith('"')) {
502
+ note = note.slice(1, -1).split('""').join('"');
503
+ }
504
+ return { value: fields[0].trim(), note: note.trim() };
505
+ }
506
+ function parseSecurityWatchlistImport(data) {
507
+ const values = [];
508
+ const problems = [];
509
+ const seen = new Set();
510
+ let duplicates = 0;
511
+ let isFirstLine = true;
512
+ const lines = (data.text || "").split("\n");
513
+ lines.forEach((rawLine, index) => {
514
+ // A file written on Windows ends its lines with \r\n.
515
+ const line = rawLine.endsWith("\r")
516
+ ? rawLine.slice(0, -1)
517
+ : rawLine;
518
+ const trimmed = line.trim();
519
+ if (!trimmed || trimmed.startsWith("#")) {
520
+ return;
521
+ }
522
+ const read = readSecurityWatchlistImportLine(trimmed);
523
+ // A CSV's header ("value", or "value,note") is not a value.
524
+ if (isFirstLine) {
525
+ isFirstLine = false;
526
+ if (isImportHeader(read)) {
527
+ return;
528
+ }
529
+ }
530
+ const value = normalizeSecurityWatchlistValue(read.value);
531
+ const problem = getSecurityWatchlistValueProblem({
532
+ value,
533
+ entityType: data.entityType,
534
+ }) || getSecurityWatchlistNoteProblem(read.note);
535
+ if (problem) {
536
+ problems.push({
537
+ line: index + 1,
538
+ value: read.value,
539
+ message: problem,
540
+ });
541
+ return;
542
+ }
543
+ const key = getSecurityWatchlistValueKey(value);
544
+ if (seen.has(key)) {
545
+ duplicates++;
546
+ return;
547
+ }
548
+ seen.add(key);
549
+ values.push({ value, note: normalizeSecurityWatchlistNote(read.note) });
550
+ });
551
+ return { values, problems, duplicates };
552
+ }
553
+ function countSecurityWatchlistValues(data) {
554
+ const counts = {
555
+ total: 0,
556
+ patterns: 0,
557
+ ranges: 0,
558
+ };
559
+ for (const value of data.values) {
560
+ counts.total++;
561
+ const match = getSecurityWatchlistValueMatch({
562
+ value,
563
+ entityType: data.entityType,
564
+ });
565
+ if (match === SecurityWatchlistValueMatch.Pattern) {
566
+ counts.patterns++;
567
+ }
568
+ else if (match === SecurityWatchlistValueMatch.Range) {
569
+ counts.ranges++;
570
+ }
571
+ }
572
+ return counts;
573
+ }
574
+ function getSecurityWatchlistSizeProblem(counts) {
575
+ if (counts.total > exports.SECURITY_WATCHLIST_VALUES_MAX) {
576
+ return exports.SECURITY_WATCHLIST_MESSAGES.tooManyValues.message;
577
+ }
578
+ if (counts.patterns > exports.SECURITY_WATCHLIST_PATTERN_VALUES_MAX) {
579
+ return exports.SECURITY_WATCHLIST_MESSAGES.tooManyPatterns.message;
580
+ }
581
+ if (counts.ranges > exports.SECURITY_WATCHLIST_RANGE_VALUES_MAX) {
582
+ return exports.SECURITY_WATCHLIST_MESSAGES.tooManyRanges.message;
583
+ }
584
+ return null;
585
+ }
586
+ /*
587
+ * A list's values as a run reads them (SigmaWatchlist): split by how each
588
+ * matches, lowercased - a range as written - each once.
589
+ */
590
+ function splitSecurityWatchlistValues(data) {
591
+ const exactValues = [];
592
+ const patterns = [];
593
+ const ranges = [];
594
+ const seen = new Set();
595
+ for (const raw of data.values) {
596
+ const value = normalizeSecurityWatchlistValue(raw);
597
+ const key = value.toLowerCase();
598
+ if (!value || value === exports.SECURITY_WATCHLIST_WILDCARD || seen.has(key)) {
599
+ continue;
600
+ }
601
+ seen.add(key);
602
+ switch (getSecurityWatchlistValueMatch({ value, entityType: data.entityType })) {
603
+ case SecurityWatchlistValueMatch.Range:
604
+ ranges.push(value);
605
+ break;
606
+ case SecurityWatchlistValueMatch.Pattern:
607
+ patterns.push(key);
608
+ break;
609
+ default:
610
+ exactValues.push(key);
611
+ }
612
+ }
613
+ return { exactValues, patterns, ranges };
614
+ }
615
+ /*
616
+ * Whether a value is on a list, as a rule would match it: what the
617
+ * Dashboard's lookup answers. Patterns are matched piece by piece, never
618
+ * with a regular expression built from a value someone wrote.
619
+ */
620
+ function matchesSecurityWatchlistPattern(pattern, value) {
621
+ const wanted = normalizeSecurityWatchlistValue(pattern).toLowerCase();
622
+ const text = (value || "").trim().toLowerCase();
623
+ if (!wanted || !text) {
624
+ return false;
625
+ }
626
+ if (!wanted.includes(exports.SECURITY_WATCHLIST_WILDCARD)) {
627
+ return wanted === text;
628
+ }
629
+ const pieces = wanted.split(exports.SECURITY_WATCHLIST_WILDCARD);
630
+ const first = pieces[0] || "";
631
+ const last = pieces[pieces.length - 1] || "";
632
+ if (!text.startsWith(first)) {
633
+ return false;
634
+ }
635
+ let position = first.length;
636
+ for (let index = 1; index < pieces.length - 1; index++) {
637
+ const piece = pieces[index] || "";
638
+ if (!piece) {
639
+ continue;
640
+ }
641
+ const found = text.indexOf(piece, position);
642
+ if (found < 0) {
643
+ return false;
644
+ }
645
+ position = found + piece.length;
646
+ }
647
+ return text.length - last.length >= position && text.endsWith(last);
648
+ }