@revealui/security 0.2.3 → 0.2.5
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 +96 -0
- package/dist/audit-UF7PIYBU.js +21 -0
- package/dist/audit-UF7PIYBU.js.map +1 -0
- package/dist/chunk-Q5KAPSST.js +429 -0
- package/dist/chunk-Q5KAPSST.js.map +1 -0
- package/dist/index.d.ts +149 -1
- package/dist/index.js +199 -370
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -54,6 +54,11 @@ declare class AuditSystem {
|
|
|
54
54
|
private storage;
|
|
55
55
|
private filters;
|
|
56
56
|
constructor(storage: AuditStorage);
|
|
57
|
+
/**
|
|
58
|
+
* Replace the backing storage (e.g. swap InMemory for Postgres at startup).
|
|
59
|
+
* Events already written to the old storage are NOT migrated.
|
|
60
|
+
*/
|
|
61
|
+
setStorage(storage: AuditStorage): void;
|
|
57
62
|
/**
|
|
58
63
|
* Log audit event
|
|
59
64
|
*/
|
|
@@ -181,11 +186,154 @@ declare class AuditReportGenerator {
|
|
|
181
186
|
*/
|
|
182
187
|
private checkAuditTrailContinuity;
|
|
183
188
|
}
|
|
189
|
+
/** Fields included in the HMAC signature for tamper detection. */
|
|
190
|
+
interface SignableFields {
|
|
191
|
+
timestamp: string;
|
|
192
|
+
eventType: string;
|
|
193
|
+
severity: string;
|
|
194
|
+
agentId: string;
|
|
195
|
+
payload: unknown;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Compute an HMAC-SHA256 signature over the canonical fields of an audit entry.
|
|
199
|
+
*
|
|
200
|
+
* The signature covers `timestamp`, `eventType`, `severity`, `agentId`, and
|
|
201
|
+
* `payload` — the immutable core of every audit record. Changing any of
|
|
202
|
+
* these fields after signing will cause verification to fail.
|
|
203
|
+
*
|
|
204
|
+
* @param entry - The audit entry fields to sign
|
|
205
|
+
* @param secret - The HMAC secret key
|
|
206
|
+
* @returns Hex-encoded HMAC-SHA256 signature
|
|
207
|
+
*/
|
|
208
|
+
declare function signAuditEntry(entry: SignableFields, secret: string): Promise<string>;
|
|
209
|
+
/**
|
|
210
|
+
* Verify an HMAC-SHA256 signature against the canonical fields of an audit entry.
|
|
211
|
+
*
|
|
212
|
+
* Uses timing-safe comparison to prevent timing attacks.
|
|
213
|
+
*
|
|
214
|
+
* @param entry - The audit entry fields to verify
|
|
215
|
+
* @param signature - The hex-encoded HMAC-SHA256 signature to verify
|
|
216
|
+
* @param secret - The HMAC secret key
|
|
217
|
+
* @returns True if the signature is valid
|
|
218
|
+
*/
|
|
219
|
+
declare function verifyAuditEntry(entry: SignableFields, signature: string, secret: string): Promise<boolean>;
|
|
184
220
|
/**
|
|
185
221
|
* Global audit system
|
|
186
222
|
*/
|
|
187
223
|
declare const audit: AuditSystem;
|
|
188
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Security Alerting Service
|
|
227
|
+
*
|
|
228
|
+
* Evaluates audit events against configurable threshold rules and
|
|
229
|
+
* dispatches alerts through pluggable handlers (logging, audit trail,
|
|
230
|
+
* webhook / SIEM integration).
|
|
231
|
+
*/
|
|
232
|
+
|
|
233
|
+
/** A security alert produced when a threshold is breached. */
|
|
234
|
+
interface SecurityAlert {
|
|
235
|
+
/** Alert rule that triggered (e.g. 'failedLogins', 'accountLockout'). */
|
|
236
|
+
type: string;
|
|
237
|
+
/** Severity of the alert. */
|
|
238
|
+
severity: AuditSeverity;
|
|
239
|
+
/** Human-readable description. */
|
|
240
|
+
message: string;
|
|
241
|
+
/** Contextual data attached to the alert. */
|
|
242
|
+
context: Record<string, unknown>;
|
|
243
|
+
/** When the alert was raised (ISO-8601). */
|
|
244
|
+
timestamp: string;
|
|
245
|
+
}
|
|
246
|
+
/** Handler that receives dispatched security alerts. */
|
|
247
|
+
interface AlertHandler {
|
|
248
|
+
/** Process a single alert. */
|
|
249
|
+
handle(alert: SecurityAlert): Promise<void>;
|
|
250
|
+
}
|
|
251
|
+
/** Configuration for a single threshold rule. */
|
|
252
|
+
interface ThresholdRule {
|
|
253
|
+
/** Maximum event count before an alert fires. */
|
|
254
|
+
maxCount: number;
|
|
255
|
+
/** Sliding window duration in milliseconds. */
|
|
256
|
+
windowMs: number;
|
|
257
|
+
/** Severity assigned to alerts from this rule. */
|
|
258
|
+
severity: AuditSeverity;
|
|
259
|
+
/** Human-readable message template — `{count}` is replaced at runtime. */
|
|
260
|
+
messageTemplate: string;
|
|
261
|
+
}
|
|
262
|
+
/** Top-level configuration for the alerting service. */
|
|
263
|
+
interface AlertingConfig {
|
|
264
|
+
/** Threshold rules keyed by rule name. */
|
|
265
|
+
thresholds: Record<string, ThresholdRule>;
|
|
266
|
+
/** Handlers that receive dispatched alerts. */
|
|
267
|
+
handlers: AlertHandler[];
|
|
268
|
+
}
|
|
269
|
+
/** Default threshold rules aligned with SOC2 6.2 requirements. */
|
|
270
|
+
declare const DEFAULT_THRESHOLDS: Record<string, ThresholdRule>;
|
|
271
|
+
/**
|
|
272
|
+
* Logs alerts to the structured security logger.
|
|
273
|
+
*/
|
|
274
|
+
declare class LogAlertHandler implements AlertHandler {
|
|
275
|
+
/** Write alert details to the configured security logger. */
|
|
276
|
+
handle(alert: SecurityAlert): Promise<void>;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Writes alerts as critical audit events into the audit log.
|
|
280
|
+
*/
|
|
281
|
+
declare class AuditAlertHandler implements AlertHandler {
|
|
282
|
+
/** Record the alert in the audit trail with severity 'critical'. */
|
|
283
|
+
handle(alert: SecurityAlert): Promise<void>;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* POSTs alerts to a configurable webhook URL for SIEM integration.
|
|
287
|
+
*/
|
|
288
|
+
declare class WebhookAlertHandler implements AlertHandler {
|
|
289
|
+
private url;
|
|
290
|
+
private headers;
|
|
291
|
+
/**
|
|
292
|
+
* Create a webhook alert handler.
|
|
293
|
+
*
|
|
294
|
+
* @param url - The webhook endpoint URL
|
|
295
|
+
* @param headers - Additional HTTP headers (e.g. authorization)
|
|
296
|
+
*/
|
|
297
|
+
constructor(url: string, headers?: Record<string, string>);
|
|
298
|
+
/** POST the alert payload to the configured webhook URL. */
|
|
299
|
+
handle(alert: SecurityAlert): Promise<void>;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Evaluates audit events against threshold rules and dispatches alerts.
|
|
303
|
+
*
|
|
304
|
+
* Maintains an in-memory sliding window per rule/group key. When the
|
|
305
|
+
* event count within the window exceeds the threshold, an alert is
|
|
306
|
+
* dispatched to all configured handlers.
|
|
307
|
+
*/
|
|
308
|
+
declare class SecurityAlertService {
|
|
309
|
+
private config;
|
|
310
|
+
private windows;
|
|
311
|
+
/**
|
|
312
|
+
* Create a new SecurityAlertService.
|
|
313
|
+
*
|
|
314
|
+
* @param config - Alerting configuration with thresholds and handlers
|
|
315
|
+
*/
|
|
316
|
+
constructor(config: AlertingConfig);
|
|
317
|
+
/**
|
|
318
|
+
* Evaluate a single audit event against all threshold rules.
|
|
319
|
+
* If a threshold is breached, dispatches alerts to all handlers.
|
|
320
|
+
*
|
|
321
|
+
* @param event - The audit event to evaluate
|
|
322
|
+
* @returns The alert that was dispatched, or null if no threshold was breached
|
|
323
|
+
*/
|
|
324
|
+
evaluateEvent(event: AuditEvent): Promise<SecurityAlert | null>;
|
|
325
|
+
/**
|
|
326
|
+
* Clear all sliding window state. Useful for testing.
|
|
327
|
+
*/
|
|
328
|
+
reset(): void;
|
|
329
|
+
/**
|
|
330
|
+
* Dispatch an alert to all configured handlers.
|
|
331
|
+
* Errors in individual handlers are logged but do not prevent
|
|
332
|
+
* other handlers from receiving the alert.
|
|
333
|
+
*/
|
|
334
|
+
private dispatchAlert;
|
|
335
|
+
}
|
|
336
|
+
|
|
189
337
|
/**
|
|
190
338
|
* Authentication Utilities
|
|
191
339
|
*
|
|
@@ -1356,4 +1504,4 @@ interface SecurityLogger {
|
|
|
1356
1504
|
*/
|
|
1357
1505
|
declare function configureSecurityLogger(logger: SecurityLogger): void;
|
|
1358
1506
|
|
|
1359
|
-
export { type AuditEvent, type AuditEventType, type AuditQuery, AuditReportGenerator, type AuditSeverity, type AuditStorage, AuditSystem, AuditTrail, type AuthorizationContext, AuthorizationSystem, type BreachStorage, type CORSConfig, CORSManager, CORSPresets, CommonRoles, ConsentManager, type ConsentRecord, type ConsentType, type ContentSecurityPolicyConfig, type CookieConsentConfig, CookieConsentManager, DataAnonymization, type DataBreach, DataBreachManager, type DataCategory, type DataDeletionRequest, DataDeletionSystem, DataExportSystem, DataMasking, type DataProcessingPurpose, type EncryptedData, type EncryptionConfig, EncryptionSystem, EnvelopeEncryption, FieldEncryption, type GDPRStorage, type HSTSConfig, InMemoryAuditStorage, InMemoryBreachStorage, InMemoryGDPRStorage, KeyRotationManager, OAuthClient, type OAuthConfig, OAuthProviders, PasswordHasher, type Permission, PermissionBuilder, PermissionCache, type PermissionsPolicyConfig, type PersonalDataExport, type Policy, PolicyBuilder, type PolicyCondition, PrivacyPolicyManager, type ReferrerPolicyValue, RequirePermission, RequireRole, type Role, SecurityHeaders, type SecurityHeadersConfig, type SecurityLogger, SecurityPresets, TokenGenerator, TwoFactorAuth, type User, audit, authorization, canAccessResource, checkAttributeAccess, configureSecurityLogger, cookieConsentManager, createAuditMiddleware, createAuthorizationMiddleware, createConsentManager, createDataBreachManager, createDataDeletionSystem, createSecurityMiddleware, dataExportSystem, encryption, permissionCache, privacyPolicyManager, setRateLimitHeaders };
|
|
1507
|
+
export { type AlertHandler, type AlertingConfig, AuditAlertHandler, type AuditEvent, type AuditEventType, type AuditQuery, AuditReportGenerator, type AuditSeverity, type AuditStorage, AuditSystem, AuditTrail, type AuthorizationContext, AuthorizationSystem, type BreachStorage, type CORSConfig, CORSManager, CORSPresets, CommonRoles, ConsentManager, type ConsentRecord, type ConsentType, type ContentSecurityPolicyConfig, type CookieConsentConfig, CookieConsentManager, DEFAULT_THRESHOLDS, DataAnonymization, type DataBreach, DataBreachManager, type DataCategory, type DataDeletionRequest, DataDeletionSystem, DataExportSystem, DataMasking, type DataProcessingPurpose, type EncryptedData, type EncryptionConfig, EncryptionSystem, EnvelopeEncryption, FieldEncryption, type GDPRStorage, type HSTSConfig, InMemoryAuditStorage, InMemoryBreachStorage, InMemoryGDPRStorage, KeyRotationManager, LogAlertHandler, OAuthClient, type OAuthConfig, OAuthProviders, PasswordHasher, type Permission, PermissionBuilder, PermissionCache, type PermissionsPolicyConfig, type PersonalDataExport, type Policy, PolicyBuilder, type PolicyCondition, PrivacyPolicyManager, type ReferrerPolicyValue, RequirePermission, RequireRole, type Role, type SecurityAlert, SecurityAlertService, SecurityHeaders, type SecurityHeadersConfig, type SecurityLogger, SecurityPresets, type ThresholdRule, TokenGenerator, TwoFactorAuth, type User, WebhookAlertHandler, audit, authorization, canAccessResource, checkAttributeAccess, configureSecurityLogger, cookieConsentManager, createAuditMiddleware, createAuthorizationMiddleware, createConsentManager, createDataBreachManager, createDataDeletionSystem, createSecurityMiddleware, dataExportSystem, encryption, permissionCache, privacyPolicyManager, setRateLimitHeaders, signAuditEntry, verifyAuditEntry };
|