webarmor 1.0.0
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/dist/index.cjs +2199 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +281 -0
- package/dist/index.d.ts +281 -0
- package/dist/index.js +2162 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
type Framework = 'express' | 'fastify' | 'koa' | 'generic';
|
|
2
|
+
interface DDoSConfig {
|
|
3
|
+
enabled: boolean;
|
|
4
|
+
maxRequests: number;
|
|
5
|
+
windowMs: number;
|
|
6
|
+
blockDurationMs: number;
|
|
7
|
+
scoreThreshold: number;
|
|
8
|
+
}
|
|
9
|
+
interface RateLimitConfig {
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
windowMs: number;
|
|
12
|
+
max: number;
|
|
13
|
+
message?: string;
|
|
14
|
+
statusCode?: number;
|
|
15
|
+
skipSuccessfulRequests?: boolean;
|
|
16
|
+
keyGenerator?: (req: any) => string;
|
|
17
|
+
}
|
|
18
|
+
interface SecurityHeadersConfig {
|
|
19
|
+
enabled: boolean;
|
|
20
|
+
contentSecurityPolicy?: {
|
|
21
|
+
defaultSrc?: string[];
|
|
22
|
+
scriptSrc?: string[];
|
|
23
|
+
styleSrc?: string[];
|
|
24
|
+
imgSrc?: string[];
|
|
25
|
+
connectSrc?: string[];
|
|
26
|
+
fontSrc?: string[];
|
|
27
|
+
objectSrc?: string[];
|
|
28
|
+
mediaSrc?: string[];
|
|
29
|
+
frameSrc?: string[];
|
|
30
|
+
};
|
|
31
|
+
hsts?: {
|
|
32
|
+
enabled: boolean;
|
|
33
|
+
maxAge?: number;
|
|
34
|
+
includeSubDomains?: boolean;
|
|
35
|
+
preload?: boolean;
|
|
36
|
+
};
|
|
37
|
+
xFrameOptions?: 'DENY' | 'SAMEORIGIN' | string;
|
|
38
|
+
xContentTypeOptions?: 'nosniff';
|
|
39
|
+
xssProtection?: string;
|
|
40
|
+
referrerPolicy?: string;
|
|
41
|
+
permissionsPolicy?: Record<string, string[]>;
|
|
42
|
+
}
|
|
43
|
+
interface CORSConfig {
|
|
44
|
+
enabled: boolean;
|
|
45
|
+
origins: string[];
|
|
46
|
+
methods?: string[];
|
|
47
|
+
allowedHeaders?: string[];
|
|
48
|
+
exposedHeaders?: string[];
|
|
49
|
+
credentials?: boolean;
|
|
50
|
+
maxAge?: number;
|
|
51
|
+
preflightContinue?: boolean;
|
|
52
|
+
}
|
|
53
|
+
interface XSSConfig {
|
|
54
|
+
enabled: boolean;
|
|
55
|
+
level: 'low' | 'medium' | 'strict';
|
|
56
|
+
blockOnDetect: boolean;
|
|
57
|
+
customRules?: Record<string, string>;
|
|
58
|
+
}
|
|
59
|
+
interface CSRFConfig {
|
|
60
|
+
enabled: boolean;
|
|
61
|
+
cookie?: {
|
|
62
|
+
name?: string;
|
|
63
|
+
httpOnly?: boolean;
|
|
64
|
+
secure?: boolean;
|
|
65
|
+
sameSite?: 'strict' | 'lax' | 'none';
|
|
66
|
+
};
|
|
67
|
+
tokenLength?: number;
|
|
68
|
+
}
|
|
69
|
+
interface SQLInjectionConfig {
|
|
70
|
+
enabled: boolean;
|
|
71
|
+
blockOnDetect: boolean;
|
|
72
|
+
logOnly: boolean;
|
|
73
|
+
customPatterns?: string[];
|
|
74
|
+
}
|
|
75
|
+
interface BotProtectionConfig {
|
|
76
|
+
enabled: boolean;
|
|
77
|
+
challengeEnabled: boolean;
|
|
78
|
+
challengeExpiryMs: number;
|
|
79
|
+
challengeCookieName?: string;
|
|
80
|
+
allowUserAgents?: string[];
|
|
81
|
+
blockUserAgents?: string[];
|
|
82
|
+
}
|
|
83
|
+
interface IPFilterConfig {
|
|
84
|
+
enabled: boolean;
|
|
85
|
+
whitelist: string[];
|
|
86
|
+
blacklist: string[];
|
|
87
|
+
logBlocked: boolean;
|
|
88
|
+
useXForwardedFor: boolean;
|
|
89
|
+
}
|
|
90
|
+
interface FileBlockConfig {
|
|
91
|
+
enabled: boolean;
|
|
92
|
+
blockedPaths: string[];
|
|
93
|
+
blockedExtensions: string[];
|
|
94
|
+
protectSensitive: string[];
|
|
95
|
+
customRules?: Array<{
|
|
96
|
+
pattern: string;
|
|
97
|
+
action: 'block' | 'allow';
|
|
98
|
+
}>;
|
|
99
|
+
}
|
|
100
|
+
interface EncryptionConfig {
|
|
101
|
+
enabled: boolean;
|
|
102
|
+
algorithm: 'aes-256-gcm' | 'aes-256-cbc';
|
|
103
|
+
defaultKey?: string;
|
|
104
|
+
encryptEnv?: boolean;
|
|
105
|
+
encryptDatabase?: boolean;
|
|
106
|
+
encryptConfig?: boolean;
|
|
107
|
+
keyEnvVariable?: string;
|
|
108
|
+
}
|
|
109
|
+
interface WebArmorConfig {
|
|
110
|
+
framework: Framework;
|
|
111
|
+
debug?: boolean;
|
|
112
|
+
logLevel?: 'error' | 'warn' | 'info' | 'debug';
|
|
113
|
+
ddos?: Partial<DDoSConfig>;
|
|
114
|
+
rateLimit?: Partial<RateLimitConfig>;
|
|
115
|
+
securityHeaders?: Partial<SecurityHeadersConfig> | boolean;
|
|
116
|
+
cors?: Partial<CORSConfig>;
|
|
117
|
+
xss?: Partial<XSSConfig>;
|
|
118
|
+
csrf?: Partial<CSRFConfig>;
|
|
119
|
+
sqlInjection?: Partial<SQLInjectionConfig>;
|
|
120
|
+
botProtection?: Partial<BotProtectionConfig>;
|
|
121
|
+
ipFilter?: Partial<IPFilterConfig>;
|
|
122
|
+
fileBlock?: Partial<FileBlockConfig>;
|
|
123
|
+
encryption?: Partial<EncryptionConfig>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
type LogLevel = 'error' | 'warn' | 'info' | 'debug';
|
|
127
|
+
interface LogEntry {
|
|
128
|
+
level: LogLevel;
|
|
129
|
+
message: string;
|
|
130
|
+
timestamp: Date;
|
|
131
|
+
data?: any;
|
|
132
|
+
}
|
|
133
|
+
declare class Logger {
|
|
134
|
+
private level;
|
|
135
|
+
private logs;
|
|
136
|
+
private maxLogs;
|
|
137
|
+
private debugMode;
|
|
138
|
+
private levels;
|
|
139
|
+
constructor(options?: {
|
|
140
|
+
level?: LogLevel;
|
|
141
|
+
debug?: boolean;
|
|
142
|
+
});
|
|
143
|
+
private shouldLog;
|
|
144
|
+
private formatMessage;
|
|
145
|
+
error(message: string, data?: any): void;
|
|
146
|
+
warn(message: string, data?: any): void;
|
|
147
|
+
info(message: string, data?: any): void;
|
|
148
|
+
debug(message: string, data?: any): void;
|
|
149
|
+
private addLog;
|
|
150
|
+
getLogs(level?: LogLevel): LogEntry[];
|
|
151
|
+
clearLogs(): void;
|
|
152
|
+
setLevel(level: LogLevel): void;
|
|
153
|
+
setDebug(debug: boolean): void;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
interface RequestData {
|
|
157
|
+
ip: string;
|
|
158
|
+
method: string;
|
|
159
|
+
url: string;
|
|
160
|
+
headers: any;
|
|
161
|
+
body?: any;
|
|
162
|
+
userAgent?: string;
|
|
163
|
+
}
|
|
164
|
+
declare class Shield {
|
|
165
|
+
private config;
|
|
166
|
+
private logger;
|
|
167
|
+
private stats;
|
|
168
|
+
private modules;
|
|
169
|
+
private enabledModules;
|
|
170
|
+
constructor(userConfig: WebArmorConfig);
|
|
171
|
+
initialize(): Promise<void>;
|
|
172
|
+
private initializeModules;
|
|
173
|
+
apply(app: any): void;
|
|
174
|
+
protect(data: RequestData): Promise<{
|
|
175
|
+
allowed: boolean;
|
|
176
|
+
reason?: string;
|
|
177
|
+
}>;
|
|
178
|
+
getStats(): any;
|
|
179
|
+
updateConfig(config: Partial<WebArmorConfig>): void;
|
|
180
|
+
enableModule(moduleName: string): void;
|
|
181
|
+
disableModule(moduleName: string): void;
|
|
182
|
+
getLogger(): Logger;
|
|
183
|
+
getConfig(): Required<WebArmorConfig>;
|
|
184
|
+
getModule(name: string): any;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
declare class FileEncryptor {
|
|
188
|
+
private algorithm;
|
|
189
|
+
private keyLength;
|
|
190
|
+
private ivLength;
|
|
191
|
+
private authTagLength;
|
|
192
|
+
private deriveKey;
|
|
193
|
+
encryptFile(inputPath: string, outputPath: string, password: string): Promise<void>;
|
|
194
|
+
decryptFile(inputPath: string, outputPath: string, password: string): Promise<void>;
|
|
195
|
+
encryptString(data: string, password: string): string;
|
|
196
|
+
decryptString(encryptedData: string, password: string): string;
|
|
197
|
+
encryptJSON(data: object, password: string): string;
|
|
198
|
+
decryptJSON<T>(encryptedData: string, password: string): T;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
declare class ConfigEncryptor {
|
|
202
|
+
private encryptor;
|
|
203
|
+
private configDir;
|
|
204
|
+
private backupDir;
|
|
205
|
+
constructor(configDir?: string);
|
|
206
|
+
encryptConfigFile(filename: string, password: string): void;
|
|
207
|
+
decryptConfigFile(filename: string, password: string): void;
|
|
208
|
+
encryptEnvFile(password: string): void;
|
|
209
|
+
decryptEnvFile(password: string): void;
|
|
210
|
+
getEncryptedEnv(password: string): Record<string, string>;
|
|
211
|
+
private createBackup;
|
|
212
|
+
restoreBackup(filename: string): void;
|
|
213
|
+
listBackups(): string[];
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
declare class DatabaseEncryptor {
|
|
217
|
+
private encryptor;
|
|
218
|
+
private dbDir;
|
|
219
|
+
constructor(dbDir?: string);
|
|
220
|
+
encryptDatabase(dbPath: string, password: string, outputPath?: string): void;
|
|
221
|
+
decryptDatabase(encryptedPath: string, password: string, outputPath?: string): void;
|
|
222
|
+
encryptJSONDatabase(dbPath: string, password: string): void;
|
|
223
|
+
decryptJSONDatabase<T>(dbPath: string, password: string): T;
|
|
224
|
+
encryptSQLite(dbPath: string, password: string): void;
|
|
225
|
+
decryptSQLite(encryptedPath: string, password: string): void;
|
|
226
|
+
autoEncryptDatabases(password: string, extensions?: string[]): void;
|
|
227
|
+
autoDecryptDatabases(password: string): void;
|
|
228
|
+
createEncryptedBackup(dbPath: string, backupDir: string, password: string): string;
|
|
229
|
+
listEncryptedBackups(backupDir: string): string[];
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
interface SessionData {
|
|
233
|
+
[key: string]: any;
|
|
234
|
+
}
|
|
235
|
+
declare class SessionEncryptor {
|
|
236
|
+
private encryptor;
|
|
237
|
+
private key;
|
|
238
|
+
constructor(key?: string);
|
|
239
|
+
setKey(key: string): void;
|
|
240
|
+
private ensureKey;
|
|
241
|
+
encryptSession(sessionData: SessionData): string;
|
|
242
|
+
decryptSession<T extends SessionData>(encryptedData: string): T;
|
|
243
|
+
encryptValue(value: any): string;
|
|
244
|
+
decryptValue<T>(encryptedValue: string): T;
|
|
245
|
+
createSignedSession(sessionData: SessionData, secret: string): string;
|
|
246
|
+
verifySignedSession(signedSession: string, secret: string): {
|
|
247
|
+
valid: boolean;
|
|
248
|
+
data?: SessionData;
|
|
249
|
+
};
|
|
250
|
+
encryptCookie(sessionData: SessionData, password: string): string;
|
|
251
|
+
decryptCookie<T>(encryptedCookie: string, password: string): T;
|
|
252
|
+
generateSecureToken(length?: number): string;
|
|
253
|
+
hashData(data: string): string;
|
|
254
|
+
verifyHash(data: string, hash: string): boolean;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
type ShieldInstance = InstanceType<typeof Shield>;
|
|
258
|
+
interface WebArmorOptions {
|
|
259
|
+
config?: WebArmorConfig;
|
|
260
|
+
shield?: Shield;
|
|
261
|
+
}
|
|
262
|
+
declare function createWebArmor(config: WebArmorConfig): Promise<ShieldInstance>;
|
|
263
|
+
declare const _default: {
|
|
264
|
+
create: typeof createWebArmor;
|
|
265
|
+
Shield: typeof Shield;
|
|
266
|
+
FileEncryptor: typeof FileEncryptor;
|
|
267
|
+
ConfigEncryptor: typeof ConfigEncryptor;
|
|
268
|
+
DatabaseEncryptor: typeof DatabaseEncryptor;
|
|
269
|
+
SessionEncryptor: typeof SessionEncryptor;
|
|
270
|
+
Logger: typeof Logger;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
declare const security: {
|
|
274
|
+
encrypt: (data: string, password: string) => string;
|
|
275
|
+
decrypt: (encryptedData: string, password: string) => string;
|
|
276
|
+
encryptFile: (inputPath: string, outputPath: string, password: string) => Promise<void>;
|
|
277
|
+
decryptFile: (inputPath: string, outputPath: string, password: string) => Promise<void>;
|
|
278
|
+
};
|
|
279
|
+
declare const createShield: typeof createWebArmor;
|
|
280
|
+
|
|
281
|
+
export { ConfigEncryptor, DatabaseEncryptor, FileEncryptor, type Framework, Logger, SessionEncryptor, Shield, type ShieldInstance, type WebArmorConfig, type WebArmorOptions, createShield, _default as default, security };
|