@push.rocks/smartmta 5.1.3 → 5.2.1
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/changelog.md +15 -0
- package/dist_ts/00_commitinfo_data.d.ts +8 -0
- package/dist_ts/00_commitinfo_data.js +9 -0
- package/dist_ts/index.d.ts +3 -0
- package/dist_ts/index.js +4 -0
- package/dist_ts/logger.d.ts +17 -0
- package/dist_ts/logger.js +76 -0
- package/dist_ts/mail/core/classes.bouncemanager.d.ts +185 -0
- package/dist_ts/mail/core/classes.bouncemanager.js +569 -0
- package/dist_ts/mail/core/classes.email.d.ts +291 -0
- package/dist_ts/mail/core/classes.email.js +802 -0
- package/dist_ts/mail/core/classes.emailvalidator.d.ts +61 -0
- package/dist_ts/mail/core/classes.emailvalidator.js +184 -0
- package/dist_ts/mail/core/classes.templatemanager.d.ts +95 -0
- package/dist_ts/mail/core/classes.templatemanager.js +240 -0
- package/dist_ts/mail/core/index.d.ts +4 -0
- package/dist_ts/mail/core/index.js +6 -0
- package/dist_ts/mail/delivery/classes.delivery.queue.d.ts +163 -0
- package/dist_ts/mail/delivery/classes.delivery.queue.js +488 -0
- package/dist_ts/mail/delivery/classes.delivery.system.d.ts +160 -0
- package/dist_ts/mail/delivery/classes.delivery.system.js +630 -0
- package/dist_ts/mail/delivery/classes.unified.rate.limiter.d.ts +200 -0
- package/dist_ts/mail/delivery/classes.unified.rate.limiter.js +820 -0
- package/dist_ts/mail/delivery/index.d.ts +4 -0
- package/dist_ts/mail/delivery/index.js +6 -0
- package/dist_ts/mail/delivery/interfaces.d.ts +140 -0
- package/dist_ts/mail/delivery/interfaces.js +17 -0
- package/dist_ts/mail/index.d.ts +7 -0
- package/dist_ts/mail/index.js +12 -0
- package/dist_ts/mail/routing/classes.dkim.manager.d.ts +25 -0
- package/dist_ts/mail/routing/classes.dkim.manager.js +127 -0
- package/dist_ts/mail/routing/classes.dns.manager.d.ts +79 -0
- package/dist_ts/mail/routing/classes.dns.manager.js +415 -0
- package/dist_ts/mail/routing/classes.domain.registry.d.ts +54 -0
- package/dist_ts/mail/routing/classes.domain.registry.js +119 -0
- package/dist_ts/mail/routing/classes.email.action.executor.d.ts +33 -0
- package/dist_ts/mail/routing/classes.email.action.executor.js +137 -0
- package/dist_ts/mail/routing/classes.email.router.d.ts +171 -0
- package/dist_ts/mail/routing/classes.email.router.js +494 -0
- package/dist_ts/mail/routing/classes.unified.email.server.d.ts +241 -0
- package/dist_ts/mail/routing/classes.unified.email.server.js +935 -0
- package/dist_ts/mail/routing/index.d.ts +7 -0
- package/dist_ts/mail/routing/index.js +9 -0
- package/dist_ts/mail/routing/interfaces.d.ts +187 -0
- package/dist_ts/mail/routing/interfaces.js +2 -0
- package/dist_ts/mail/security/classes.dkimcreator.d.ts +72 -0
- package/dist_ts/mail/security/classes.dkimcreator.js +360 -0
- package/dist_ts/mail/security/classes.spfverifier.d.ts +62 -0
- package/dist_ts/mail/security/classes.spfverifier.js +87 -0
- package/dist_ts/mail/security/index.d.ts +2 -0
- package/dist_ts/mail/security/index.js +4 -0
- package/dist_ts/paths.d.ts +14 -0
- package/dist_ts/paths.js +39 -0
- package/dist_ts/plugins.d.ts +24 -0
- package/dist_ts/plugins.js +28 -0
- package/dist_ts/security/classes.contentscanner.d.ts +130 -0
- package/dist_ts/security/classes.contentscanner.js +338 -0
- package/dist_ts/security/classes.ipreputationchecker.d.ts +73 -0
- package/dist_ts/security/classes.ipreputationchecker.js +263 -0
- package/dist_ts/security/classes.rustsecuritybridge.d.ts +403 -0
- package/dist_ts/security/classes.rustsecuritybridge.js +502 -0
- package/dist_ts/security/classes.securitylogger.d.ts +140 -0
- package/dist_ts/security/classes.securitylogger.js +235 -0
- package/dist_ts/security/index.d.ts +4 -0
- package/dist_ts/security/index.js +5 -0
- package/package.json +6 -1
- package/ts/00_commitinfo_data.ts +8 -0
- package/ts/index.ts +3 -0
- package/ts/logger.ts +91 -0
- package/ts/mail/core/classes.bouncemanager.ts +731 -0
- package/ts/mail/core/classes.email.ts +942 -0
- package/ts/mail/core/classes.emailvalidator.ts +239 -0
- package/ts/mail/core/classes.templatemanager.ts +320 -0
- package/ts/mail/core/index.ts +5 -0
- package/ts/mail/delivery/classes.delivery.queue.ts +645 -0
- package/ts/mail/delivery/classes.delivery.system.ts +816 -0
- package/ts/mail/delivery/classes.unified.rate.limiter.ts +1053 -0
- package/ts/mail/delivery/index.ts +5 -0
- package/ts/mail/delivery/interfaces.ts +167 -0
- package/ts/mail/index.ts +17 -0
- package/ts/mail/routing/classes.dkim.manager.ts +157 -0
- package/ts/mail/routing/classes.dns.manager.ts +573 -0
- package/ts/mail/routing/classes.domain.registry.ts +139 -0
- package/ts/mail/routing/classes.email.action.executor.ts +175 -0
- package/ts/mail/routing/classes.email.router.ts +575 -0
- package/ts/mail/routing/classes.unified.email.server.ts +1207 -0
- package/ts/mail/routing/index.ts +9 -0
- package/ts/mail/routing/interfaces.ts +202 -0
- package/ts/mail/security/classes.dkimcreator.ts +447 -0
- package/ts/mail/security/classes.spfverifier.ts +126 -0
- package/ts/mail/security/index.ts +3 -0
- package/ts/paths.ts +48 -0
- package/ts/plugins.ts +53 -0
- package/ts/security/classes.contentscanner.ts +400 -0
- package/ts/security/classes.ipreputationchecker.ts +315 -0
- package/ts/security/classes.rustsecuritybridge.ts +964 -0
- package/ts/security/classes.securitylogger.ts +299 -0
- package/ts/security/index.ts +40 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import * as plugins from '../plugins.js';
|
|
2
|
+
import { logger } from '../logger.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Log level for security events
|
|
6
|
+
*/
|
|
7
|
+
export enum SecurityLogLevel {
|
|
8
|
+
INFO = 'info',
|
|
9
|
+
WARN = 'warn',
|
|
10
|
+
ERROR = 'error',
|
|
11
|
+
CRITICAL = 'critical'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Security event types for categorization
|
|
16
|
+
*/
|
|
17
|
+
export enum SecurityEventType {
|
|
18
|
+
AUTHENTICATION = 'authentication',
|
|
19
|
+
ACCESS_CONTROL = 'access_control',
|
|
20
|
+
EMAIL_VALIDATION = 'email_validation',
|
|
21
|
+
EMAIL_PROCESSING = 'email_processing',
|
|
22
|
+
EMAIL_FORWARDING = 'email_forwarding',
|
|
23
|
+
EMAIL_DELIVERY = 'email_delivery',
|
|
24
|
+
DKIM = 'dkim',
|
|
25
|
+
SPF = 'spf',
|
|
26
|
+
DMARC = 'dmarc',
|
|
27
|
+
RATE_LIMIT = 'rate_limit',
|
|
28
|
+
RATE_LIMITING = 'rate_limiting',
|
|
29
|
+
SPAM = 'spam',
|
|
30
|
+
MALWARE = 'malware',
|
|
31
|
+
CONNECTION = 'connection',
|
|
32
|
+
DATA_EXPOSURE = 'data_exposure',
|
|
33
|
+
CONFIGURATION = 'configuration',
|
|
34
|
+
IP_REPUTATION = 'ip_reputation',
|
|
35
|
+
REJECTED_CONNECTION = 'rejected_connection'
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Security event interface
|
|
40
|
+
*/
|
|
41
|
+
export interface ISecurityEvent {
|
|
42
|
+
timestamp: number;
|
|
43
|
+
level: SecurityLogLevel;
|
|
44
|
+
type: SecurityEventType;
|
|
45
|
+
message: string;
|
|
46
|
+
details?: any;
|
|
47
|
+
ipAddress?: string;
|
|
48
|
+
userId?: string;
|
|
49
|
+
sessionId?: string;
|
|
50
|
+
emailId?: string;
|
|
51
|
+
domain?: string;
|
|
52
|
+
action?: string;
|
|
53
|
+
result?: string;
|
|
54
|
+
success?: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Security logger for enhanced security monitoring
|
|
59
|
+
*/
|
|
60
|
+
export class SecurityLogger {
|
|
61
|
+
private static instance: SecurityLogger;
|
|
62
|
+
private securityEvents: ISecurityEvent[] = [];
|
|
63
|
+
private maxEventHistory: number;
|
|
64
|
+
private enableNotifications: boolean;
|
|
65
|
+
|
|
66
|
+
private constructor(options?: {
|
|
67
|
+
maxEventHistory?: number;
|
|
68
|
+
enableNotifications?: boolean;
|
|
69
|
+
}) {
|
|
70
|
+
this.maxEventHistory = options?.maxEventHistory || 1000;
|
|
71
|
+
this.enableNotifications = options?.enableNotifications || false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Get singleton instance
|
|
76
|
+
*/
|
|
77
|
+
public static getInstance(options?: {
|
|
78
|
+
maxEventHistory?: number;
|
|
79
|
+
enableNotifications?: boolean;
|
|
80
|
+
}): SecurityLogger {
|
|
81
|
+
if (!SecurityLogger.instance) {
|
|
82
|
+
SecurityLogger.instance = new SecurityLogger(options);
|
|
83
|
+
}
|
|
84
|
+
return SecurityLogger.instance;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Log a security event
|
|
89
|
+
* @param event The security event to log
|
|
90
|
+
*/
|
|
91
|
+
public logEvent(event: Omit<ISecurityEvent, 'timestamp'>): void {
|
|
92
|
+
const fullEvent: ISecurityEvent = {
|
|
93
|
+
...event,
|
|
94
|
+
timestamp: Date.now()
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// Store in memory buffer
|
|
98
|
+
this.securityEvents.push(fullEvent);
|
|
99
|
+
|
|
100
|
+
// Trim history if needed
|
|
101
|
+
if (this.securityEvents.length > this.maxEventHistory) {
|
|
102
|
+
this.securityEvents.shift();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Log to regular logger with appropriate level
|
|
106
|
+
switch (event.level) {
|
|
107
|
+
case SecurityLogLevel.INFO:
|
|
108
|
+
logger.log('info', `[SECURITY:${event.type}] ${event.message}`, event.details);
|
|
109
|
+
break;
|
|
110
|
+
case SecurityLogLevel.WARN:
|
|
111
|
+
logger.log('warn', `[SECURITY:${event.type}] ${event.message}`, event.details);
|
|
112
|
+
break;
|
|
113
|
+
case SecurityLogLevel.ERROR:
|
|
114
|
+
case SecurityLogLevel.CRITICAL:
|
|
115
|
+
logger.log('error', `[SECURITY:${event.type}] ${event.message}`, event.details);
|
|
116
|
+
|
|
117
|
+
// Send notification for critical events if enabled
|
|
118
|
+
if (event.level === SecurityLogLevel.CRITICAL && this.enableNotifications) {
|
|
119
|
+
this.sendNotification(fullEvent);
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Get recent security events
|
|
127
|
+
* @param limit Maximum number of events to return
|
|
128
|
+
* @param filter Filter for specific event types
|
|
129
|
+
* @returns Recent security events
|
|
130
|
+
*/
|
|
131
|
+
public getRecentEvents(limit: number = 100, filter?: {
|
|
132
|
+
level?: SecurityLogLevel;
|
|
133
|
+
type?: SecurityEventType;
|
|
134
|
+
fromTimestamp?: number;
|
|
135
|
+
toTimestamp?: number;
|
|
136
|
+
}): ISecurityEvent[] {
|
|
137
|
+
let filteredEvents = this.securityEvents;
|
|
138
|
+
|
|
139
|
+
// Apply filters
|
|
140
|
+
if (filter) {
|
|
141
|
+
if (filter.level) {
|
|
142
|
+
filteredEvents = filteredEvents.filter(event => event.level === filter.level);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (filter.type) {
|
|
146
|
+
filteredEvents = filteredEvents.filter(event => event.type === filter.type);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (filter.fromTimestamp) {
|
|
150
|
+
filteredEvents = filteredEvents.filter(event => event.timestamp >= filter.fromTimestamp);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (filter.toTimestamp) {
|
|
154
|
+
filteredEvents = filteredEvents.filter(event => event.timestamp <= filter.toTimestamp);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Return most recent events up to limit
|
|
159
|
+
return filteredEvents
|
|
160
|
+
.sort((a, b) => b.timestamp - a.timestamp)
|
|
161
|
+
.slice(0, limit);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Get events by security level
|
|
166
|
+
* @param level The security level to filter by
|
|
167
|
+
* @param limit Maximum number of events to return
|
|
168
|
+
* @returns Security events matching the level
|
|
169
|
+
*/
|
|
170
|
+
public getEventsByLevel(level: SecurityLogLevel, limit: number = 100): ISecurityEvent[] {
|
|
171
|
+
return this.getRecentEvents(limit, { level });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Get events by security type
|
|
176
|
+
* @param type The event type to filter by
|
|
177
|
+
* @param limit Maximum number of events to return
|
|
178
|
+
* @returns Security events matching the type
|
|
179
|
+
*/
|
|
180
|
+
public getEventsByType(type: SecurityEventType, limit: number = 100): ISecurityEvent[] {
|
|
181
|
+
return this.getRecentEvents(limit, { type });
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Get security events for a specific IP address
|
|
186
|
+
* @param ipAddress The IP address to filter by
|
|
187
|
+
* @param limit Maximum number of events to return
|
|
188
|
+
* @returns Security events for the IP address
|
|
189
|
+
*/
|
|
190
|
+
public getEventsByIP(ipAddress: string, limit: number = 100): ISecurityEvent[] {
|
|
191
|
+
return this.securityEvents
|
|
192
|
+
.filter(event => event.ipAddress === ipAddress)
|
|
193
|
+
.sort((a, b) => b.timestamp - a.timestamp)
|
|
194
|
+
.slice(0, limit);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Get security events for a specific domain
|
|
199
|
+
* @param domain The domain to filter by
|
|
200
|
+
* @param limit Maximum number of events to return
|
|
201
|
+
* @returns Security events for the domain
|
|
202
|
+
*/
|
|
203
|
+
public getEventsByDomain(domain: string, limit: number = 100): ISecurityEvent[] {
|
|
204
|
+
return this.securityEvents
|
|
205
|
+
.filter(event => event.domain === domain)
|
|
206
|
+
.sort((a, b) => b.timestamp - a.timestamp)
|
|
207
|
+
.slice(0, limit);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Send a notification for critical security events
|
|
212
|
+
* @param event The security event to notify about
|
|
213
|
+
* @private
|
|
214
|
+
*/
|
|
215
|
+
private sendNotification(event: ISecurityEvent): void {
|
|
216
|
+
// In a production environment, this would integrate with a notification service
|
|
217
|
+
// For now, we'll just log that we would send a notification
|
|
218
|
+
logger.log('error', `[SECURITY NOTIFICATION] ${event.message}`, {
|
|
219
|
+
...event,
|
|
220
|
+
notificationSent: true
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// Future integration with alerting systems would go here
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Clear event history
|
|
228
|
+
*/
|
|
229
|
+
public clearEvents(): void {
|
|
230
|
+
this.securityEvents = [];
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Get statistical summary of security events
|
|
235
|
+
* @param timeWindow Optional time window in milliseconds
|
|
236
|
+
* @returns Summary of security events
|
|
237
|
+
*/
|
|
238
|
+
public getEventsSummary(timeWindow?: number): {
|
|
239
|
+
total: number;
|
|
240
|
+
byLevel: Record<SecurityLogLevel, number>;
|
|
241
|
+
byType: Record<SecurityEventType, number>;
|
|
242
|
+
topIPs: Array<{ ip: string; count: number }>;
|
|
243
|
+
topDomains: Array<{ domain: string; count: number }>;
|
|
244
|
+
} {
|
|
245
|
+
// Filter by time window if provided
|
|
246
|
+
let events = this.securityEvents;
|
|
247
|
+
if (timeWindow) {
|
|
248
|
+
const cutoff = Date.now() - timeWindow;
|
|
249
|
+
events = events.filter(e => e.timestamp >= cutoff);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Count by level
|
|
253
|
+
const byLevel = Object.values(SecurityLogLevel).reduce((acc, level) => {
|
|
254
|
+
acc[level] = events.filter(e => e.level === level).length;
|
|
255
|
+
return acc;
|
|
256
|
+
}, {} as Record<SecurityLogLevel, number>);
|
|
257
|
+
|
|
258
|
+
// Count by type
|
|
259
|
+
const byType = Object.values(SecurityEventType).reduce((acc, type) => {
|
|
260
|
+
acc[type] = events.filter(e => e.type === type).length;
|
|
261
|
+
return acc;
|
|
262
|
+
}, {} as Record<SecurityEventType, number>);
|
|
263
|
+
|
|
264
|
+
// Count by IP
|
|
265
|
+
const ipCounts = new Map<string, number>();
|
|
266
|
+
events.forEach(e => {
|
|
267
|
+
if (e.ipAddress) {
|
|
268
|
+
ipCounts.set(e.ipAddress, (ipCounts.get(e.ipAddress) || 0) + 1);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
// Count by domain
|
|
273
|
+
const domainCounts = new Map<string, number>();
|
|
274
|
+
events.forEach(e => {
|
|
275
|
+
if (e.domain) {
|
|
276
|
+
domainCounts.set(e.domain, (domainCounts.get(e.domain) || 0) + 1);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// Sort and limit top entries
|
|
281
|
+
const topIPs = Array.from(ipCounts.entries())
|
|
282
|
+
.map(([ip, count]) => ({ ip, count }))
|
|
283
|
+
.sort((a, b) => b.count - a.count)
|
|
284
|
+
.slice(0, 10);
|
|
285
|
+
|
|
286
|
+
const topDomains = Array.from(domainCounts.entries())
|
|
287
|
+
.map(([domain, count]) => ({ domain, count }))
|
|
288
|
+
.sort((a, b) => b.count - a.count)
|
|
289
|
+
.slice(0, 10);
|
|
290
|
+
|
|
291
|
+
return {
|
|
292
|
+
total: events.length,
|
|
293
|
+
byLevel,
|
|
294
|
+
byType,
|
|
295
|
+
topIPs,
|
|
296
|
+
topDomains
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export {
|
|
2
|
+
SecurityLogger,
|
|
3
|
+
SecurityLogLevel,
|
|
4
|
+
SecurityEventType,
|
|
5
|
+
type ISecurityEvent
|
|
6
|
+
} from './classes.securitylogger.js';
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
IPReputationChecker,
|
|
10
|
+
ReputationThreshold,
|
|
11
|
+
IPType,
|
|
12
|
+
type IReputationResult,
|
|
13
|
+
type IIPReputationOptions
|
|
14
|
+
} from './classes.ipreputationchecker.js';
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
ContentScanner,
|
|
18
|
+
ThreatCategory,
|
|
19
|
+
type IScanResult,
|
|
20
|
+
type IContentScannerOptions
|
|
21
|
+
} from './classes.contentscanner.js';
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
RustSecurityBridge,
|
|
25
|
+
BridgeState,
|
|
26
|
+
type IBridgeResilienceConfig,
|
|
27
|
+
type IDkimVerificationResult,
|
|
28
|
+
type ISpfResult,
|
|
29
|
+
type IDmarcResult,
|
|
30
|
+
type IEmailSecurityResult,
|
|
31
|
+
type IValidationResult,
|
|
32
|
+
type IBounceDetection,
|
|
33
|
+
type IRustReputationResult,
|
|
34
|
+
type IVersionInfo,
|
|
35
|
+
type IOutboundEmail,
|
|
36
|
+
type ISmtpSendResult,
|
|
37
|
+
type ISmtpSendOptions,
|
|
38
|
+
type ISmtpVerifyResult,
|
|
39
|
+
type ISmtpPoolStatus,
|
|
40
|
+
} from './classes.rustsecuritybridge.js';
|