@oneuptime/common 14.0.104 → 14.0.105

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 (88) hide show
  1. package/Models/DatabaseModels/CloudAccount.d.mts +1 -0
  2. package/Models/DatabaseModels/CloudAccount.d.ts +1 -0
  3. package/Models/DatabaseModels/CloudAccount.js +21 -0
  4. package/Models/DatabaseModels/CloudBudget.d.mts +1 -0
  5. package/Models/DatabaseModels/CloudBudget.d.ts +1 -0
  6. package/Models/DatabaseModels/CloudBudget.js +38 -3
  7. package/Models/DatabaseModels/CloudCostRecommendation.d.mts +2 -0
  8. package/Models/DatabaseModels/CloudCostRecommendation.d.ts +2 -0
  9. package/Models/DatabaseModels/CloudCostRecommendation.js +30 -2
  10. package/Models/DatabaseModels/DetectionRule.js +8 -7
  11. package/Types/AI/ResourceAiAccessApi.d.mts +1 -0
  12. package/Types/AI/ResourceAiAccessApi.d.ts +1 -0
  13. package/Types/AI/ResourceAiAccessApi.js +6 -1
  14. package/Types/AI/ResourceAiAccessApi.mjs +1 -0
  15. package/Types/AI/ResourceAiAccessPermissions.d.mts +2 -0
  16. package/Types/AI/ResourceAiAccessPermissions.d.ts +2 -0
  17. package/Types/AI/ResourceAiAccessPermissions.js +13 -0
  18. package/Types/AI/ResourceAiAccessPermissions.mjs +2 -0
  19. package/Types/Cloud/CloudCost.d.mts +8 -0
  20. package/Types/Cloud/CloudCost.d.ts +8 -0
  21. package/Types/Cloud/CloudCost.js +37 -0
  22. package/Types/Cloud/CloudCost.mjs +1 -0
  23. package/Types/Cloud/CloudCostAnomaly.d.mts +34 -0
  24. package/Types/Cloud/CloudCostAnomaly.d.ts +34 -0
  25. package/Types/Cloud/CloudCostAnomaly.js +236 -0
  26. package/Types/Cloud/CloudCostAnomaly.mjs +18 -0
  27. package/Types/Cloud/CloudLogGroups.d.mts +6 -1
  28. package/Types/Cloud/CloudLogGroups.d.ts +6 -1
  29. package/Types/Cloud/CloudLogGroups.js +59 -3
  30. package/Types/Cloud/CloudLogGroups.mjs +1 -0
  31. package/Types/Cloud/CloudPlatform.js +9 -8
  32. package/Types/Cloud/CloudRightSizing.d.mts +140 -0
  33. package/Types/Cloud/CloudRightSizing.d.ts +140 -0
  34. package/Types/Cloud/CloudRightSizing.js +867 -0
  35. package/Types/Cloud/CloudRightSizing.mjs +53 -0
  36. package/Types/CloudConnection/CloudAiAgentKey.d.mts +65 -0
  37. package/Types/CloudConnection/CloudAiAgentKey.d.ts +65 -0
  38. package/Types/CloudConnection/CloudAiAgentKey.js +289 -0
  39. package/Types/CloudConnection/CloudAiAgentKey.mjs +18 -0
  40. package/Types/CloudConnection/CloudAiAgentSetupCommands.d.mts +5 -2
  41. package/Types/CloudConnection/CloudAiAgentSetupCommands.d.ts +5 -2
  42. package/Types/CloudConnection/CloudAiAgentSetupCommands.js +114 -43
  43. package/Types/CloudConnection/CloudAiAgentSetupCommands.mjs +4 -1
  44. package/Types/CloudConnection/CloudStream.d.mts +4 -0
  45. package/Types/CloudConnection/CloudStream.d.ts +4 -0
  46. package/Types/CloudConnection/CloudStream.js +18 -1
  47. package/Types/CloudConnection/CloudStream.mjs +4 -0
  48. package/Types/CloudConnection/CloudStreamTemplate.d.mts +2 -0
  49. package/Types/CloudConnection/CloudStreamTemplate.d.ts +2 -0
  50. package/Types/CloudConnection/CloudStreamTemplate.js +89 -6
  51. package/Types/CloudConnection/CloudStreamTemplate.mjs +2 -0
  52. package/Types/InstallScripts/InstallScripts.js +1 -1
  53. package/Types/ResourceAiAgent/CloudAiAgentNames.d.mts +6 -0
  54. package/Types/ResourceAiAgent/CloudAiAgentNames.d.ts +6 -0
  55. package/Types/ResourceAiAgent/CloudAiAgentNames.js +11 -1
  56. package/Types/ResourceAiAgent/CloudAiAgentNames.mjs +3 -0
  57. package/Types/ResourceAiAgent/ResourceAiAccess.d.mts +3 -1
  58. package/Types/ResourceAiAgent/ResourceAiAccess.d.ts +3 -1
  59. package/Types/ResourceAiAgent/ResourceAiAccess.js +13 -2
  60. package/Types/ResourceAiAgent/ResourceAiAccess.mjs +2 -0
  61. package/Types/SecurityCase/SecurityCaseContext.d.mts +2 -1
  62. package/Types/SecurityCase/SecurityCaseContext.d.ts +2 -1
  63. package/Types/SecurityCase/SecurityConnection.d.mts +2 -1
  64. package/Types/SecurityCase/SecurityConnection.d.ts +2 -1
  65. package/Types/SecurityEvent/RealTimeDetection.d.mts +14 -5
  66. package/Types/SecurityEvent/RealTimeDetection.d.ts +14 -5
  67. package/Types/SecurityEvent/RealTimeDetection.js +75 -25
  68. package/Types/SecurityEvent/RealTimeDetection.mjs +3 -3
  69. package/Types/SecurityPlaybook/SecurityPlaybookAction.d.mts +4 -2
  70. package/Types/SecurityPlaybook/SecurityPlaybookAction.d.ts +4 -2
  71. package/Types/SecurityPlaybook/SecurityPlaybookAction.js +22 -3
  72. package/Types/SecurityPlaybook/SecurityPlaybookStep.d.mts +7 -2
  73. package/Types/SecurityPlaybook/SecurityPlaybookStep.d.ts +7 -2
  74. package/Types/SecurityPlaybook/SecurityPlaybookStep.js +96 -39
  75. package/Types/SecurityPlaybook/SecurityPlaybookStep.mjs +2 -0
  76. package/Types/SecurityPlaybook/SecurityPlaybookStepCondition.d.mts +17 -2
  77. package/Types/SecurityPlaybook/SecurityPlaybookStepCondition.d.ts +17 -2
  78. package/Types/SecurityPlaybook/SecurityPlaybookStepCondition.js +174 -33
  79. package/Types/SecurityPlaybook/SecurityPlaybookStepCondition.mjs +7 -0
  80. package/Utils/SecurityCase/SecurityCaseMarkdown.d.mts +5 -0
  81. package/Utils/SecurityCase/SecurityCaseMarkdown.d.ts +5 -0
  82. package/Utils/SecurityCase/SecurityCaseMarkdown.js +10 -0
  83. package/Utils/SecurityCase/SecurityCaseMarkdown.mjs +1 -0
  84. package/Utils/Telemetry/CloudChangeTitle.d.mts +37 -0
  85. package/Utils/Telemetry/CloudChangeTitle.d.ts +37 -0
  86. package/Utils/Telemetry/CloudChangeTitle.js +315 -3
  87. package/Utils/Telemetry/CloudChangeTitle.mjs +13 -0
  88. package/package.json +1 -1
@@ -36,7 +36,8 @@ export declare enum SecurityPlaybookActionType {
36
36
  SendWebhook = "Send Webhook",
37
37
  RunWorkflow = "Run Workflow",
38
38
  RunRunbook = "Run Runbook",
39
- FixWithAi = "Fix With AI"
39
+ FixWithAi = "Fix With AI",
40
+ StopRun = "Stop Run"
40
41
  }
41
42
  export declare enum SecurityPlaybookActionCategory {
42
43
  Case = "Case",
@@ -44,7 +45,8 @@ export declare enum SecurityPlaybookActionCategory {
44
45
  Notify = "Notify",
45
46
  Escalate = "Escalate",
46
47
  Contain = "Contain",
47
- Automate = "Automate"
48
+ Automate = "Automate",
49
+ FlowControl = "Flow control"
48
50
  }
49
51
  export declare const SECURITY_PLAYBOOK_ACTION_CATEGORIES: ReadonlyArray<SecurityPlaybookActionCategory>;
50
52
  export interface SecurityPlaybookActionDefinition {
@@ -17,7 +17,7 @@ const SecurityEntity_1 = require("../SecurityCase/SecurityEntity");
17
17
  * What a playbook step can do. Each action is one verb an analyst would
18
18
  * otherwise do by hand on a case: change the case, look something up, tell
19
19
  * somebody, escalate it, contain a threat through a connected product, or
20
- * hand the case to something else.
20
+ * hand the case to something else - or, for the run itself, stop it there.
21
21
  */
22
22
  var SecurityPlaybookActionType;
23
23
  (function (SecurityPlaybookActionType) {
@@ -62,6 +62,8 @@ var SecurityPlaybookActionType;
62
62
  SecurityPlaybookActionType["RunWorkflow"] = "Run Workflow";
63
63
  SecurityPlaybookActionType["RunRunbook"] = "Run Runbook";
64
64
  SecurityPlaybookActionType["FixWithAi"] = "Fix With AI";
65
+ // Flow control
66
+ SecurityPlaybookActionType["StopRun"] = "Stop Run";
65
67
  })(SecurityPlaybookActionType || (exports.SecurityPlaybookActionType = SecurityPlaybookActionType = {}));
66
68
  var SecurityPlaybookActionCategory;
67
69
  (function (SecurityPlaybookActionCategory) {
@@ -71,8 +73,10 @@ var SecurityPlaybookActionCategory;
71
73
  SecurityPlaybookActionCategory["Escalate"] = "Escalate";
72
74
  SecurityPlaybookActionCategory["Contain"] = "Contain";
73
75
  SecurityPlaybookActionCategory["Automate"] = "Automate";
76
+ // What the run itself does next: stop there.
77
+ SecurityPlaybookActionCategory["FlowControl"] = "Flow control";
74
78
  })(SecurityPlaybookActionCategory || (exports.SecurityPlaybookActionCategory = SecurityPlaybookActionCategory = {}));
75
- // The order the step picker shows the categories in: the order of a response.
79
+ // The order the step picker shows the categories in: the order of a response, then the run's own.
76
80
  exports.SECURITY_PLAYBOOK_ACTION_CATEGORIES = [
77
81
  SecurityPlaybookActionCategory.Case,
78
82
  SecurityPlaybookActionCategory.Investigate,
@@ -80,6 +84,7 @@ exports.SECURITY_PLAYBOOK_ACTION_CATEGORIES = [
80
84
  SecurityPlaybookActionCategory.Escalate,
81
85
  SecurityPlaybookActionCategory.Contain,
82
86
  SecurityPlaybookActionCategory.Automate,
87
+ SecurityPlaybookActionCategory.FlowControl,
83
88
  ];
84
89
  exports.SECURITY_PLAYBOOK_ACTIONS = [
85
90
  {
@@ -405,6 +410,18 @@ exports.SECURITY_PLAYBOOK_ACTIONS = [
405
410
  icon: IconProp_1.default.Sparkles,
406
411
  isDisruptive: false,
407
412
  },
413
+ /*
414
+ * The run's own: end it there, as done - with Run This Step, only after
415
+ * a result, such as when threat intel found nothing to contain.
416
+ */
417
+ {
418
+ type: SecurityPlaybookActionType.StopRun,
419
+ title: "Stop the run",
420
+ description: "End the run here, as done: the steps after it do not run. With Run This Step, stop only after a result, such as when threat intel found nothing.",
421
+ category: SecurityPlaybookActionCategory.FlowControl,
422
+ icon: IconProp_1.default.StopCircle,
423
+ isDisruptive: false,
424
+ },
408
425
  ];
409
426
  function getSecurityPlaybookAction(type) {
410
427
  return exports.SECURITY_PLAYBOOK_ACTIONS.find((action) => {
@@ -436,11 +453,13 @@ function getSecurityPlaybookUndoAction(type) {
436
453
  }
437
454
  /*
438
455
  * The categories whose steps only read and write the case inside OneUptime:
439
- * nobody is told, paged or escalated to, and nothing outside is changed.
456
+ * nobody is told, paged or escalated to, and nothing outside is changed. A
457
+ * step that stops the run does neither.
440
458
  */
441
459
  exports.SECURITY_PLAYBOOK_INSIDE_CATEGORIES = [
442
460
  SecurityPlaybookActionCategory.Case,
443
461
  SecurityPlaybookActionCategory.Investigate,
462
+ SecurityPlaybookActionCategory.FlowControl,
444
463
  ];
445
464
  /*
446
465
  * Whether every step of a playbook's stored steps stays inside OneUptime. A
@@ -2,7 +2,7 @@ import { JSONObject, JSONValue } from "../JSON.mjs";
2
2
  import Permission from "../Permission.mjs";
3
3
  import SecurityCaseVerdict from "../SecurityCase/SecurityCaseVerdict.mjs";
4
4
  import { SecurityPlaybookActionType } from "./SecurityPlaybookAction.mjs";
5
- import { SecurityPlaybookStepCondition } from "./SecurityPlaybookStepCondition.mjs";
5
+ import { SecurityPlaybookStepRunIf } from "./SecurityPlaybookStepCondition.mjs";
6
6
  export interface SecurityPlaybookStep {
7
7
  id: string;
8
8
  action: SecurityPlaybookActionType;
@@ -10,7 +10,7 @@ export interface SecurityPlaybookStep {
10
10
  requiresApproval: boolean;
11
11
  continueOnFailure: boolean;
12
12
  onlyIfThreatIntelMatched: boolean;
13
- runIf?: SecurityPlaybookStepCondition | undefined;
13
+ runIf?: SecurityPlaybookStepRunIf | undefined;
14
14
  approvalTurnedOff?: SecurityPlaybookApprovalTurnedOff | undefined;
15
15
  }
16
16
  export interface SecurityPlaybookApprovalTurnedOff {
@@ -82,6 +82,9 @@ export interface RunWorkflowConfig {
82
82
  export interface RunRunbookConfig {
83
83
  runbookId: string;
84
84
  }
85
+ export interface StopRunConfig {
86
+ reason?: string | undefined;
87
+ }
85
88
  export interface PostStatusPageAnnouncementConfig {
86
89
  statusPageIds: Array<string>;
87
90
  announcementTitle: string;
@@ -97,10 +100,12 @@ export declare const ENTITY_ACTIVITY_LOOKBACK_MIN_HOURS: number;
97
100
  export declare const ENTITY_ACTIVITY_LOOKBACK_MAX_HOURS: number;
98
101
  export declare const ENTITY_ACTIVITY_LOOKBACK_DEFAULT_HOURS: number;
99
102
  export declare const ANNOUNCEMENT_TITLE_MAX_LENGTH: number;
103
+ export declare const SECURITY_PLAYBOOK_STOP_REASON_MAX_LENGTH: number;
100
104
  export declare function normalizeSecurityPlaybookStepConfig(action: SecurityPlaybookActionType, rawConfig: JSONObject, label: string): JSONObject;
101
105
  export declare function readTaskLines(value: JSONValue | undefined): Array<string>;
102
106
  export declare function doesStepNeedApproval(step: SecurityPlaybookStep): boolean;
103
107
  export declare function parseSecurityPlaybookSteps(value: unknown): Array<SecurityPlaybookStep>;
108
+ export declare function doesStepWaitOn(step: Pick<SecurityPlaybookStep, "runIf">, stepId: string): boolean;
104
109
  export declare function getStepsWaitingOn(steps: ReadonlyArray<SecurityPlaybookStep>, stepId: string): Array<{
105
110
  index: number;
106
111
  step: SecurityPlaybookStep;
@@ -2,7 +2,7 @@ import { JSONObject, JSONValue } from "../JSON";
2
2
  import Permission from "../Permission";
3
3
  import SecurityCaseVerdict from "../SecurityCase/SecurityCaseVerdict";
4
4
  import { SecurityPlaybookActionType } from "./SecurityPlaybookAction";
5
- import { SecurityPlaybookStepCondition } from "./SecurityPlaybookStepCondition";
5
+ import { SecurityPlaybookStepRunIf } from "./SecurityPlaybookStepCondition";
6
6
  export interface SecurityPlaybookStep {
7
7
  id: string;
8
8
  action: SecurityPlaybookActionType;
@@ -10,7 +10,7 @@ export interface SecurityPlaybookStep {
10
10
  requiresApproval: boolean;
11
11
  continueOnFailure: boolean;
12
12
  onlyIfThreatIntelMatched: boolean;
13
- runIf?: SecurityPlaybookStepCondition | undefined;
13
+ runIf?: SecurityPlaybookStepRunIf | undefined;
14
14
  approvalTurnedOff?: SecurityPlaybookApprovalTurnedOff | undefined;
15
15
  }
16
16
  export interface SecurityPlaybookApprovalTurnedOff {
@@ -82,6 +82,9 @@ export interface RunWorkflowConfig {
82
82
  export interface RunRunbookConfig {
83
83
  runbookId: string;
84
84
  }
85
+ export interface StopRunConfig {
86
+ reason?: string | undefined;
87
+ }
85
88
  export interface PostStatusPageAnnouncementConfig {
86
89
  statusPageIds: Array<string>;
87
90
  announcementTitle: string;
@@ -97,10 +100,12 @@ export declare const ENTITY_ACTIVITY_LOOKBACK_MIN_HOURS: number;
97
100
  export declare const ENTITY_ACTIVITY_LOOKBACK_MAX_HOURS: number;
98
101
  export declare const ENTITY_ACTIVITY_LOOKBACK_DEFAULT_HOURS: number;
99
102
  export declare const ANNOUNCEMENT_TITLE_MAX_LENGTH: number;
103
+ export declare const SECURITY_PLAYBOOK_STOP_REASON_MAX_LENGTH: number;
100
104
  export declare function normalizeSecurityPlaybookStepConfig(action: SecurityPlaybookActionType, rawConfig: JSONObject, label: string): JSONObject;
101
105
  export declare function readTaskLines(value: JSONValue | undefined): Array<string>;
102
106
  export declare function doesStepNeedApproval(step: SecurityPlaybookStep): boolean;
103
107
  export declare function parseSecurityPlaybookSteps(value: unknown): Array<SecurityPlaybookStep>;
108
+ export declare function doesStepWaitOn(step: Pick<SecurityPlaybookStep, "runIf">, stepId: string): boolean;
104
109
  export declare function getStepsWaitingOn(steps: ReadonlyArray<SecurityPlaybookStep>, stepId: string): Array<{
105
110
  index: number;
106
111
  step: SecurityPlaybookStep;
@@ -3,11 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ANNOUNCEMENT_TITLE_MAX_LENGTH = exports.ENTITY_ACTIVITY_LOOKBACK_DEFAULT_HOURS = exports.ENTITY_ACTIVITY_LOOKBACK_MAX_HOURS = exports.ENTITY_ACTIVITY_LOOKBACK_MIN_HOURS = exports.SECURITY_PLAYBOOK_TASK_MAX_LENGTH = exports.SECURITY_PLAYBOOK_MAX_TASKS_PER_STEP = exports.SECURITY_PLAYBOOK_NOTE_MAX_LENGTH = exports.SECURITY_PLAYBOOK_MAX_STEPS = exports.TURN_OFF_CONTAINMENT_APPROVAL_PERMISSIONS = exports.DefenderIsolationType = void 0;
6
+ exports.SECURITY_PLAYBOOK_STOP_REASON_MAX_LENGTH = exports.ANNOUNCEMENT_TITLE_MAX_LENGTH = exports.ENTITY_ACTIVITY_LOOKBACK_DEFAULT_HOURS = exports.ENTITY_ACTIVITY_LOOKBACK_MAX_HOURS = exports.ENTITY_ACTIVITY_LOOKBACK_MIN_HOURS = exports.SECURITY_PLAYBOOK_TASK_MAX_LENGTH = exports.SECURITY_PLAYBOOK_MAX_TASKS_PER_STEP = exports.SECURITY_PLAYBOOK_NOTE_MAX_LENGTH = exports.SECURITY_PLAYBOOK_MAX_STEPS = exports.TURN_OFF_CONTAINMENT_APPROVAL_PERMISSIONS = exports.DefenderIsolationType = void 0;
7
7
  exports.normalizeSecurityPlaybookStepConfig = normalizeSecurityPlaybookStepConfig;
8
8
  exports.readTaskLines = readTaskLines;
9
9
  exports.doesStepNeedApproval = doesStepNeedApproval;
10
10
  exports.parseSecurityPlaybookSteps = parseSecurityPlaybookSteps;
11
+ exports.doesStepWaitOn = doesStepWaitOn;
11
12
  exports.getStepsWaitingOn = getStepsWaitingOn;
12
13
  exports.assertSecurityPlaybookStepConditions = assertSecurityPlaybookStepConditions;
13
14
  const ColumnLength_1 = __importDefault(require("../Database/ColumnLength"));
@@ -34,6 +35,8 @@ exports.ENTITY_ACTIVITY_LOOKBACK_MAX_HOURS = 720;
34
35
  exports.ENTITY_ACTIVITY_LOOKBACK_DEFAULT_HOURS = 24;
35
36
  // A status page announcement's title is a short text column.
36
37
  exports.ANNOUNCEMENT_TITLE_MAX_LENGTH = 100;
38
+ // What a Stop step says on the case when the run stops there: a sentence.
39
+ exports.SECURITY_PLAYBOOK_STOP_REASON_MAX_LENGTH = 500;
37
40
  // An http(s) URL with a host: what a webhook step can post to.
38
41
  const WEBHOOK_URL = /^https?:\/\/[^\s/?#]+[^\s]*$/i;
39
42
  function stepLabel(index, action) {
@@ -282,6 +285,13 @@ function normalizeSecurityPlaybookStepConfig(action, rawConfig, label) {
282
285
  notifySubscribers: rawConfig["notifySubscribers"] === true,
283
286
  };
284
287
  }
288
+ case SecurityPlaybookAction_1.SecurityPlaybookActionType.StopRun: {
289
+ const reason = readText(rawConfig, "reason");
290
+ if (reason.length > exports.SECURITY_PLAYBOOK_STOP_REASON_MAX_LENGTH) {
291
+ throw new BadDataException_1.default(`${label}: say why it stops in at most ${exports.SECURITY_PLAYBOOK_STOP_REASON_MAX_LENGTH} characters.`);
292
+ }
293
+ return reason ? { reason } : {};
294
+ }
285
295
  // Nothing to set: each reads what it acts on from the case.
286
296
  case SecurityPlaybookAction_1.SecurityPlaybookActionType.PreserveEvidence:
287
297
  case SecurityPlaybookAction_1.SecurityPlaybookActionType.FixWithAi:
@@ -379,27 +389,36 @@ function parseSecurityPlaybookSteps(value) {
379
389
  }
380
390
  seenIds.add(id);
381
391
  const isDisruptive = Boolean((_a = (0, SecurityPlaybookAction_1.getSecurityPlaybookAction)(action)) === null || _a === void 0 ? void 0 : _a.isDisruptive);
382
- const requiresApproval = isDisruptive
383
- ? step["requiresApproval"] !== false
384
- : step["requiresApproval"] === true;
392
+ // A step that stops the run does nothing to approve, and cannot fail.
393
+ const stopsTheRun = action === SecurityPlaybookAction_1.SecurityPlaybookActionType.StopRun;
394
+ const requiresApproval = stopsTheRun
395
+ ? false
396
+ : isDisruptive
397
+ ? step["requiresApproval"] !== false
398
+ : step["requiresApproval"] === true;
385
399
  const approvalTurnedOff = isDisruptive && !requiresApproval
386
400
  ? readApprovalTurnedOff(step["approvalTurnedOff"])
387
401
  : undefined;
388
402
  const runIf = (0, SecurityPlaybookStepCondition_1.readSecurityPlaybookStepCondition)(step["runIf"], label);
389
403
  return Object.assign(Object.assign({ id,
390
- action, config: normalizeSecurityPlaybookStepConfig(action, readObject(step["config"]), label), requiresApproval, continueOnFailure: step["continueOnFailure"] === true, onlyIfThreatIntelMatched: step["onlyIfThreatIntelMatched"] === true }, (runIf ? { runIf } : {})), (approvalTurnedOff ? { approvalTurnedOff } : {}));
404
+ action, config: normalizeSecurityPlaybookStepConfig(action, readObject(step["config"]), label), requiresApproval, continueOnFailure: !stopsTheRun && step["continueOnFailure"] === true, onlyIfThreatIntelMatched: step["onlyIfThreatIntelMatched"] === true }, (runIf ? { runIf } : {})), (approvalTurnedOff ? { approvalTurnedOff } : {}));
405
+ });
406
+ }
407
+ // Whether a step waits on this step's result, among any it waits on.
408
+ function doesStepWaitOn(step, stepId) {
409
+ return (0, SecurityPlaybookStepCondition_1.getSecurityPlaybookStepConditions)(step.runIf).some((condition) => {
410
+ return condition.stepId === stepId;
391
411
  });
392
412
  }
393
413
  /*
394
- * The steps a step's own result is waited on by: every later step whose
395
- * condition names it. What keeps it from being deleted, or moved below one
396
- * of them.
414
+ * The steps a step's own result is waited on by: every later step with a
415
+ * condition that names it. What keeps it from being deleted, or moved
416
+ * below one of them.
397
417
  */
398
418
  function getStepsWaitingOn(steps, stepId) {
399
419
  const waiting = [];
400
420
  steps.forEach((step, index) => {
401
- var _a;
402
- if (((_a = step.runIf) === null || _a === void 0 ? void 0 : _a.stepId) === stepId) {
421
+ if (doesStepWaitOn(step, stepId)) {
403
422
  waiting.push({ index, step });
404
423
  }
405
424
  });
@@ -407,42 +426,80 @@ function getStepsWaitingOn(steps, stepId) {
407
426
  }
408
427
  /*
409
428
  * THE BRANCHING RULE, checked across the whole list when a playbook is
410
- * saved: a step waits only on a step before it, on a result that step can
411
- * have - found or found nothing for one that looks something up, succeeded
412
- * otherwise - and on its failure only when that step carries on past one.
413
- * Throws a message that names the step and says what to change. Runs
429
+ * saved, for every result a step waits on: a step waits only on a step
430
+ * before it, on a result that step can have - found or found nothing for
431
+ * one that looks something up, succeeded otherwise - on its failure only
432
+ * when that step carries on past one, and never on a step that stops the
433
+ * run, after which nothing runs. A step waiting on all of its results never
434
+ * waits on two results of one step, and a Stop step that always runs is the
435
+ * last. Throws a message that names the step and says what to change. Runs
414
436
  * already under way keep the steps they started with, which the engine
415
437
  * reads as they are (evaluateSecurityPlaybookStepCondition).
416
438
  */
417
439
  function assertSecurityPlaybookStepConditions(steps) {
418
440
  steps.forEach((step, index) => {
419
- var _a;
420
- const condition = step.runIf;
421
- if (!condition) {
422
- return;
423
- }
424
- const label = stepLabel(index, step.action);
425
- const waitedOn = steps.findIndex((candidate) => {
426
- return candidate.id === condition.stepId;
427
- });
428
- if (waitedOn < 0) {
429
- throw new BadDataException_1.default(`${label}: the step it runs after is no longer in the playbook. Choose again when it runs.`);
441
+ const conditions = (0, SecurityPlaybookStepCondition_1.getSecurityPlaybookStepConditions)(step.runIf);
442
+ for (const condition of conditions) {
443
+ assertStepCondition({ steps, step, index, condition });
430
444
  }
431
- if (waitedOn >= index) {
432
- throw new BadDataException_1.default(waitedOn === index
433
- ? `${label}: a step cannot run after its own result. Choose an earlier step.`
434
- : `${label}: it runs after step ${waitedOn + 1}, which comes after it. Move it below step ${waitedOn + 1}, or choose again when it runs.`);
445
+ /*
446
+ * A Stop step that always runs ends every run where it is: a step after
447
+ * it would never run.
448
+ */
449
+ if (step.action === SecurityPlaybookAction_1.SecurityPlaybookActionType.StopRun &&
450
+ conditions.length === 0 &&
451
+ !step.onlyIfThreatIntelMatched &&
452
+ index < steps.length - 1) {
453
+ throw new BadDataException_1.default(`${stepLabel(index, step.action)}: it always stops the run, so the steps after it would never run. Make it run only after an earlier step's result, or move it to the end.`);
435
454
  }
436
- const earlier = steps[waitedOn];
437
- const earlierTitle = ((_a = (0, SecurityPlaybookAction_1.getSecurityPlaybookAction)(earlier.action)) === null || _a === void 0 ? void 0 : _a.title) || earlier.action;
438
- if (condition.outcome === SecurityPlaybookStepCondition_1.SecurityPlaybookStepOutcome.Failed &&
439
- !earlier.continueOnFailure) {
440
- throw new BadDataException_1.default(`${label}: it runs only if step ${waitedOn + 1} (${earlierTitle}) fails, but a failed step ${waitedOn + 1} stops the run. Turn on Carry On If It Fails for step ${waitedOn + 1}, or choose again when this step runs.`);
441
- }
442
- if (!(0, SecurityPlaybookStepCondition_1.getSecurityPlaybookStepOutcomes)(earlier).includes(condition.outcome)) {
443
- throw new BadDataException_1.default((0, SecurityPlaybookStepCondition_1.getSecurityPlaybookFinds)(earlier.action)
444
- ? `${label}: step ${waitedOn + 1} (${earlierTitle}) looks something up, so it finds something or finds nothing. Choose one of those.`
445
- : `${label}: step ${waitedOn + 1} (${earlierTitle}) does not look anything up, so it can only succeed or fail. Choose one of those.`);
455
+ /*
456
+ * Waiting on all of two results of one step - it found something and
457
+ * found nothing - is waiting on what never happens.
458
+ */
459
+ if ((0, SecurityPlaybookStepCondition_1.getSecurityPlaybookConditionMatch)(step.runIf) ===
460
+ SecurityPlaybookStepCondition_1.SecurityPlaybookConditionMatch.All) {
461
+ const firstClash = conditions.find((condition) => {
462
+ return conditions.some((other) => {
463
+ return (other.stepId === condition.stepId &&
464
+ other.outcome !== condition.outcome);
465
+ });
466
+ });
467
+ if (firstClash) {
468
+ const waitedOn = steps.findIndex((candidate) => {
469
+ return candidate.id === firstClash.stepId;
470
+ });
471
+ throw new BadDataException_1.default(`${stepLabel(index, step.action)}: it waits on two results of step ${waitedOn + 1}, which one run never has together. Choose one of them, or run it when any of its results happened.`);
472
+ }
446
473
  }
447
474
  });
448
475
  }
476
+ function assertStepCondition(data) {
477
+ var _a;
478
+ const { steps, step, index, condition } = data;
479
+ const label = stepLabel(index, step.action);
480
+ const waitedOn = steps.findIndex((candidate) => {
481
+ return candidate.id === condition.stepId;
482
+ });
483
+ if (waitedOn < 0) {
484
+ throw new BadDataException_1.default(`${label}: the step it runs after is no longer in the playbook. Choose again when it runs.`);
485
+ }
486
+ if (waitedOn >= index) {
487
+ throw new BadDataException_1.default(waitedOn === index
488
+ ? `${label}: a step cannot run after its own result. Choose an earlier step.`
489
+ : `${label}: it runs after step ${waitedOn + 1}, which comes after it. Move it below step ${waitedOn + 1}, or choose again when it runs.`);
490
+ }
491
+ const earlier = steps[waitedOn];
492
+ const earlierTitle = ((_a = (0, SecurityPlaybookAction_1.getSecurityPlaybookAction)(earlier.action)) === null || _a === void 0 ? void 0 : _a.title) || earlier.action;
493
+ if (earlier.action === SecurityPlaybookAction_1.SecurityPlaybookActionType.StopRun) {
494
+ throw new BadDataException_1.default(`${label}: step ${waitedOn + 1} (${earlierTitle}) ends the run when it runs, so no step after it can wait on it. Choose another step.`);
495
+ }
496
+ if (condition.outcome === SecurityPlaybookStepCondition_1.SecurityPlaybookStepOutcome.Failed &&
497
+ !earlier.continueOnFailure) {
498
+ throw new BadDataException_1.default(`${label}: it runs only if step ${waitedOn + 1} (${earlierTitle}) fails, but a failed step ${waitedOn + 1} stops the run. Turn on Carry On If It Fails for step ${waitedOn + 1}, or choose again when this step runs.`);
499
+ }
500
+ if (!(0, SecurityPlaybookStepCondition_1.getSecurityPlaybookStepOutcomes)(earlier).includes(condition.outcome)) {
501
+ throw new BadDataException_1.default((0, SecurityPlaybookStepCondition_1.getSecurityPlaybookFinds)(earlier.action)
502
+ ? `${label}: step ${waitedOn + 1} (${earlierTitle}) looks something up, so it finds something or finds nothing. Choose one of those.`
503
+ : `${label}: step ${waitedOn + 1} (${earlierTitle}) does not look anything up, so it can only succeed or fail. Choose one of those.`);
504
+ }
505
+ }
@@ -7,10 +7,12 @@ export const ENTITY_ACTIVITY_LOOKBACK_MIN_HOURS = commonJsModule.ENTITY_ACTIVITY
7
7
  export const SECURITY_PLAYBOOK_MAX_STEPS = commonJsModule.SECURITY_PLAYBOOK_MAX_STEPS;
8
8
  export const SECURITY_PLAYBOOK_MAX_TASKS_PER_STEP = commonJsModule.SECURITY_PLAYBOOK_MAX_TASKS_PER_STEP;
9
9
  export const SECURITY_PLAYBOOK_NOTE_MAX_LENGTH = commonJsModule.SECURITY_PLAYBOOK_NOTE_MAX_LENGTH;
10
+ export const SECURITY_PLAYBOOK_STOP_REASON_MAX_LENGTH = commonJsModule.SECURITY_PLAYBOOK_STOP_REASON_MAX_LENGTH;
10
11
  export const SECURITY_PLAYBOOK_TASK_MAX_LENGTH = commonJsModule.SECURITY_PLAYBOOK_TASK_MAX_LENGTH;
11
12
  export const TURN_OFF_CONTAINMENT_APPROVAL_PERMISSIONS = commonJsModule.TURN_OFF_CONTAINMENT_APPROVAL_PERMISSIONS;
12
13
  export const assertSecurityPlaybookStepConditions = commonJsModule.assertSecurityPlaybookStepConditions;
13
14
  export const doesStepNeedApproval = commonJsModule.doesStepNeedApproval;
15
+ export const doesStepWaitOn = commonJsModule.doesStepWaitOn;
14
16
  export const getStepsWaitingOn = commonJsModule.getStepsWaitingOn;
15
17
  export const normalizeSecurityPlaybookStepConfig = commonJsModule.normalizeSecurityPlaybookStepConfig;
16
18
  export const parseSecurityPlaybookSteps = commonJsModule.parseSecurityPlaybookSteps;
@@ -11,24 +11,39 @@ export interface SecurityPlaybookStepCondition {
11
11
  stepId: string;
12
12
  outcome: SecurityPlaybookStepOutcome;
13
13
  }
14
+ export declare enum SecurityPlaybookConditionMatch {
15
+ All = "All",
16
+ Any = "Any"
17
+ }
18
+ export interface SecurityPlaybookStepConditionGroup {
19
+ match: SecurityPlaybookConditionMatch;
20
+ conditions: Array<SecurityPlaybookStepCondition>;
21
+ }
22
+ export type SecurityPlaybookStepRunIf = SecurityPlaybookStepCondition | SecurityPlaybookStepConditionGroup;
23
+ export declare const SECURITY_PLAYBOOK_MAX_CONDITIONS_PER_STEP: number;
14
24
  export interface SecurityPlaybookFinds {
15
25
  found: string;
16
26
  foundNothing: string;
17
27
  }
18
28
  export declare function getSecurityPlaybookFinds(action: SecurityPlaybookActionType | string | undefined | null): SecurityPlaybookFinds | undefined;
19
29
  export declare function isSecurityPlaybookStepOutcome(value: unknown): value is SecurityPlaybookStepOutcome;
30
+ export declare function isSecurityPlaybookConditionMatch(value: unknown): value is SecurityPlaybookConditionMatch;
31
+ export declare function isSecurityPlaybookStepConditionGroup(runIf: SecurityPlaybookStepRunIf | undefined | null): runIf is SecurityPlaybookStepConditionGroup;
32
+ export declare function getSecurityPlaybookStepConditions(runIf: SecurityPlaybookStepRunIf | undefined | null): Array<SecurityPlaybookStepCondition>;
33
+ export declare function getSecurityPlaybookConditionMatch(runIf: SecurityPlaybookStepRunIf | undefined | null): SecurityPlaybookConditionMatch;
34
+ export declare function buildSecurityPlaybookStepRunIf(conditions: ReadonlyArray<SecurityPlaybookStepCondition>, match?: SecurityPlaybookConditionMatch): SecurityPlaybookStepRunIf | undefined;
20
35
  export declare function getSecurityPlaybookStepOutcomes(step: {
21
36
  action: SecurityPlaybookActionType | string;
22
37
  continueOnFailure: boolean;
23
38
  }): Array<SecurityPlaybookStepOutcome>;
24
39
  export declare function describeSecurityPlaybookStepOutcome(action: SecurityPlaybookActionType | string, outcome: SecurityPlaybookStepOutcome): string;
25
- export declare function readSecurityPlaybookStepCondition(value: JSONValue | undefined, label: string): SecurityPlaybookStepCondition | undefined;
40
+ export declare function readSecurityPlaybookStepCondition(value: JSONValue | undefined, label: string): SecurityPlaybookStepRunIf | undefined;
26
41
  export declare function doesStepResultMeetOutcome(result: {
27
42
  status: SecurityPlaybookStepStatus | string | undefined;
28
43
  found?: boolean | undefined;
29
44
  }, outcome: SecurityPlaybookStepOutcome): boolean;
30
45
  export declare function evaluateSecurityPlaybookStepCondition(data: {
31
- condition: SecurityPlaybookStepCondition | undefined;
46
+ condition: SecurityPlaybookStepRunIf | undefined;
32
47
  index: number;
33
48
  steps: ReadonlyArray<{
34
49
  id: string;
@@ -11,24 +11,39 @@ export interface SecurityPlaybookStepCondition {
11
11
  stepId: string;
12
12
  outcome: SecurityPlaybookStepOutcome;
13
13
  }
14
+ export declare enum SecurityPlaybookConditionMatch {
15
+ All = "All",
16
+ Any = "Any"
17
+ }
18
+ export interface SecurityPlaybookStepConditionGroup {
19
+ match: SecurityPlaybookConditionMatch;
20
+ conditions: Array<SecurityPlaybookStepCondition>;
21
+ }
22
+ export type SecurityPlaybookStepRunIf = SecurityPlaybookStepCondition | SecurityPlaybookStepConditionGroup;
23
+ export declare const SECURITY_PLAYBOOK_MAX_CONDITIONS_PER_STEP: number;
14
24
  export interface SecurityPlaybookFinds {
15
25
  found: string;
16
26
  foundNothing: string;
17
27
  }
18
28
  export declare function getSecurityPlaybookFinds(action: SecurityPlaybookActionType | string | undefined | null): SecurityPlaybookFinds | undefined;
19
29
  export declare function isSecurityPlaybookStepOutcome(value: unknown): value is SecurityPlaybookStepOutcome;
30
+ export declare function isSecurityPlaybookConditionMatch(value: unknown): value is SecurityPlaybookConditionMatch;
31
+ export declare function isSecurityPlaybookStepConditionGroup(runIf: SecurityPlaybookStepRunIf | undefined | null): runIf is SecurityPlaybookStepConditionGroup;
32
+ export declare function getSecurityPlaybookStepConditions(runIf: SecurityPlaybookStepRunIf | undefined | null): Array<SecurityPlaybookStepCondition>;
33
+ export declare function getSecurityPlaybookConditionMatch(runIf: SecurityPlaybookStepRunIf | undefined | null): SecurityPlaybookConditionMatch;
34
+ export declare function buildSecurityPlaybookStepRunIf(conditions: ReadonlyArray<SecurityPlaybookStepCondition>, match?: SecurityPlaybookConditionMatch): SecurityPlaybookStepRunIf | undefined;
20
35
  export declare function getSecurityPlaybookStepOutcomes(step: {
21
36
  action: SecurityPlaybookActionType | string;
22
37
  continueOnFailure: boolean;
23
38
  }): Array<SecurityPlaybookStepOutcome>;
24
39
  export declare function describeSecurityPlaybookStepOutcome(action: SecurityPlaybookActionType | string, outcome: SecurityPlaybookStepOutcome): string;
25
- export declare function readSecurityPlaybookStepCondition(value: JSONValue | undefined, label: string): SecurityPlaybookStepCondition | undefined;
40
+ export declare function readSecurityPlaybookStepCondition(value: JSONValue | undefined, label: string): SecurityPlaybookStepRunIf | undefined;
26
41
  export declare function doesStepResultMeetOutcome(result: {
27
42
  status: SecurityPlaybookStepStatus | string | undefined;
28
43
  found?: boolean | undefined;
29
44
  }, outcome: SecurityPlaybookStepOutcome): boolean;
30
45
  export declare function evaluateSecurityPlaybookStepCondition(data: {
31
- condition: SecurityPlaybookStepCondition | undefined;
46
+ condition: SecurityPlaybookStepRunIf | undefined;
32
47
  index: number;
33
48
  steps: ReadonlyArray<{
34
49
  id: string;