-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathincident-response.zod.ts
More file actions
368 lines (319 loc) · 11.1 KB
/
Copy pathincident-response.zod.ts
File metadata and controls
368 lines (319 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { z } from 'zod';
import { DataClassificationSchema } from './security-context.zod';
/**
* Incident Response Protocol — ISO 27001:2022 (A.5.24–A.5.28)
*
* Defines schemas for information security event management including
* incident classification, severity grading, response procedures,
* and notification matrices.
*
* @see https://www.iso.org/standard/27001
* @category Security
*/
/**
* Incident Severity Schema
*
* Severity grading for security incidents following ISO 27001 guidelines.
* Determines response urgency and escalation requirements.
*/
import { lazySchema } from '../shared/lazy-schema';
export const IncidentSeveritySchema = lazySchema(() => z.enum([
'critical', // Immediate threat to business operations or data integrity
'high', // Significant impact requiring urgent response
'medium', // Moderate impact with controlled response timeline
'low', // Minor impact with standard response procedures
]));
/**
* Incident Category Schema
*
* Classification of security incidents by type (A.5.25).
* Used for routing, reporting, and trend analysis.
*/
export const IncidentCategorySchema = lazySchema(() => z.enum([
'data_breach', // Unauthorized access or disclosure of data
'malware', // Malicious software detection
'unauthorized_access', // Unauthorized system or data access
'denial_of_service', // Service availability attack
'social_engineering', // Phishing, pretexting, or manipulation
'insider_threat', // Threat originating from internal actors
'physical_security', // Physical security breach
'configuration_error', // Security misconfiguration
'vulnerability_exploit', // Exploitation of known vulnerability
'policy_violation', // Violation of security policies
'other', // Other security incidents
]));
/**
* Incident Status Schema
*
* Current status of a security incident in its lifecycle.
*/
export const IncidentStatusSchema = lazySchema(() => z.enum([
'reported', // Initial report received
'triaged', // Severity and category assessed
'investigating', // Active investigation in progress
'containing', // Containment measures being applied
'eradicating', // Root cause being removed
'recovering', // Systems being restored to normal
'resolved', // Incident resolved
'closed', // Post-incident review complete
]));
/**
* Incident Response Phase Schema
*
* Defines structured response phases per NIST SP 800-61 / ISO 27001 (A.5.26).
*/
export const IncidentResponsePhaseSchema = lazySchema(() => z.object({
/**
* Phase name identifier
*/
phase: z.enum([
'identification',
'containment',
'eradication',
'recovery',
'lessons_learned',
]).describe('Response phase name'),
/**
* Phase description and objectives
*/
description: z.string().describe('Phase description and objectives'),
/**
* Responsible team or role for this phase
*/
assignedTo: z.string().describe('Responsible team or role'),
/**
* Target completion time in hours from incident start
*/
targetHours: z.number().min(0).describe('Target completion time in hours'),
/**
* Actual completion timestamp (Unix milliseconds)
*/
completedAt: z.number().optional().describe('Actual completion timestamp'),
/**
* Notes and findings during this phase
*/
notes: z.string().optional().describe('Phase notes and findings'),
}).describe('Incident response phase with timing and assignment'));
export type IncidentResponsePhase = z.infer<typeof IncidentResponsePhaseSchema>;
/**
* Notification Rule Schema
*
* Defines who must be notified and when, based on severity (A.5.27).
*/
export const IncidentNotificationRuleSchema = lazySchema(() => z.object({
/**
* Minimum severity level that triggers this notification
*/
severity: IncidentSeveritySchema.describe('Minimum severity to trigger notification'),
/**
* Notification channels to use
*/
channels: z.array(z.enum([
'email',
'sms',
'slack',
'pagerduty',
'webhook',
])).describe('Notification channels'),
/**
* Roles or teams to notify
*/
recipients: z.array(z.string()).describe('Roles or teams to notify'),
/**
* Maximum time in minutes to send notification after incident detection
*/
withinMinutes: z.number().min(1).describe('Notification deadline in minutes from detection'),
/**
* Whether to notify external regulators (for data breaches)
*/
notifyRegulators: z.boolean().default(false)
.describe('Whether to notify regulatory authorities'),
/**
* Regulatory notification deadline in hours (e.g., GDPR 72h)
*/
regulatorDeadlineHours: z.number().optional()
.describe('Regulatory notification deadline in hours'),
}).describe('Incident notification rule per severity level'));
export type IncidentNotificationRule = z.infer<typeof IncidentNotificationRuleSchema>;
/**
* Notification Matrix Schema
*
* Complete notification matrix mapping severity levels to stakeholder groups (A.5.27).
*/
export const IncidentNotificationMatrixSchema = lazySchema(() => z.object({
/**
* Notification rules ordered by severity
*/
rules: z.array(IncidentNotificationRuleSchema)
.describe('Notification rules by severity level'),
/**
* Default escalation timeout in minutes before auto-escalation
*/
escalationTimeoutMinutes: z.number().default(30)
.describe('Auto-escalation timeout in minutes'),
/**
* Escalation chain: ordered list of roles to escalate to
*/
escalationChain: z.array(z.string()).default([])
.describe('Ordered escalation chain of roles'),
}).describe('Incident notification matrix with escalation policies'));
export type IncidentNotificationMatrix = z.infer<typeof IncidentNotificationMatrixSchema>;
/**
* Incident Schema
*
* Comprehensive security incident record following ISO 27001:2022 (A.5.24–A.5.28).
* Tracks the full incident lifecycle from detection through post-incident review.
*
* @example
* ```json
* {
* "id": "INC-2024-001",
* "title": "Unauthorized API Access Detected",
* "description": "Multiple failed authentication attempts from unknown IP range",
* "severity": "high",
* "category": "unauthorized_access",
* "status": "investigating",
* "reportedBy": "monitoring_system",
* "reportedAt": 1704067200000,
* "affectedSystems": ["api-gateway", "auth-service"],
* "affectedDataClassifications": ["pii", "confidential"],
* "responsePhases": [
* {
* "phase": "identification",
* "description": "Identify scope of unauthorized access",
* "assignedTo": "security_team",
* "targetHours": 2
* }
* ]
* }
* ```
*/
export const IncidentSchema = lazySchema(() => z.object({
/**
* Unique incident identifier
*/
id: z.string().describe('Unique incident identifier'),
/**
* Short descriptive title of the incident
*/
title: z.string().describe('Incident title'),
/**
* Detailed description of the security event
*/
description: z.string().describe('Detailed incident description'),
/**
* Severity classification
*/
severity: IncidentSeveritySchema.describe('Incident severity level'),
/**
* Incident category / type
*/
category: IncidentCategorySchema.describe('Incident category'),
/**
* Current status in the incident lifecycle
*/
status: IncidentStatusSchema.describe('Current incident status'),
/**
* User or system that reported the incident
*/
reportedBy: z.string().describe('Reporter user ID or system name'),
/**
* Timestamp when the incident was reported (Unix milliseconds)
*/
reportedAt: z.number().describe('Report timestamp'),
/**
* Timestamp when the incident was detected (may differ from reported)
*/
detectedAt: z.number().optional().describe('Detection timestamp'),
/**
* Timestamp when the incident was resolved
*/
resolvedAt: z.number().optional().describe('Resolution timestamp'),
/**
* Systems affected by the incident
*/
affectedSystems: z.array(z.string()).describe('Affected systems'),
/**
* Data classifications affected (for data breach assessment)
*/
affectedDataClassifications: z.array(DataClassificationSchema)
.optional().describe('Affected data classifications'),
/**
* Structured response phases tracking
*/
responsePhases: z.array(IncidentResponsePhaseSchema).optional()
.describe('Incident response phases'),
/**
* Root cause analysis (completed post-incident)
*/
rootCause: z.string().optional().describe('Root cause analysis'),
/**
* Corrective actions taken or planned
*/
correctiveActions: z.array(z.string()).optional()
.describe('Corrective actions taken or planned'),
/**
* Lessons learned from the incident (A.5.28)
*/
lessonsLearned: z.string().optional()
.describe('Lessons learned from the incident'),
/**
* Related change request IDs (if changes resulted from incident)
*/
relatedChangeRequestIds: z.array(z.string()).optional()
.describe('Related change request IDs'),
/**
* Custom metadata for extensibility
*/
metadata: z.record(z.string(), z.unknown()).optional()
.describe('Custom metadata key-value pairs'),
}).describe('Security incident record per ISO 27001:2022 A.5.24–A.5.28'));
/**
* Incident Response Policy Schema
*
* Organization-level incident response policy configuration (A.5.24).
*/
export const IncidentResponsePolicySchema = lazySchema(() => z.object({
/**
* Whether incident response is enabled
*/
enabled: z.boolean().default(true)
.describe('Enable incident response management'),
/**
* Notification matrix configuration
*/
notificationMatrix: IncidentNotificationMatrixSchema
.describe('Notification and escalation matrix'),
/**
* Default response team or role
*/
defaultResponseTeam: z.string()
.describe('Default incident response team or role'),
/**
* Maximum time in hours to begin initial triage
*/
triageDeadlineHours: z.number().default(1)
.describe('Maximum hours to begin triage after detection'),
/**
* Whether to require post-incident review for all incidents
*/
requirePostIncidentReview: z.boolean().default(true)
.describe('Require post-incident review for all incidents'),
/**
* Minimum severity level that requires regulatory notification
*/
regulatoryNotificationThreshold: IncidentSeveritySchema.default('high')
.describe('Minimum severity requiring regulatory notification'),
/**
* Retention period for incident records in days
*/
retentionDays: z.number().default(2555)
.describe('Incident record retention period in days (default ~7 years)'),
}).describe('Organization-level incident response policy per ISO 27001:2022'));
// Type exports
export type IncidentSeverity = z.infer<typeof IncidentSeveritySchema>;
export type IncidentCategory = z.infer<typeof IncidentCategorySchema>;
export type IncidentStatus = z.infer<typeof IncidentStatusSchema>;
export type Incident = z.infer<typeof IncidentSchema>;
export type IncidentResponsePolicy = z.infer<typeof IncidentResponsePolicySchema>;