@arcis/node 1.0.0 → 1.2.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/README.md +156 -222
- package/dist/core/index.d.mts +4 -4
- package/dist/core/index.d.ts +4 -4
- package/dist/core/index.js +13 -2
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +13 -2
- package/dist/core/index.mjs.map +1 -1
- package/dist/index-A-m-pPeW.d.mts +340 -0
- package/dist/index-CgK94hY_.d.mts +532 -0
- package/dist/index-Co5kPRZz.d.ts +340 -0
- package/dist/index-D_bdJcF0.d.ts +532 -0
- package/dist/index.d.mts +144 -108
- package/dist/index.d.ts +144 -108
- package/dist/index.js +1541 -211
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1515 -212
- package/dist/index.mjs.map +1 -1
- package/dist/logging/index.d.mts +1 -1
- package/dist/logging/index.d.ts +1 -1
- package/dist/logging/index.js +12 -1
- package/dist/logging/index.js.map +1 -1
- package/dist/logging/index.mjs +12 -1
- package/dist/logging/index.mjs.map +1 -1
- package/dist/middleware/index.d.mts +2 -2
- package/dist/middleware/index.d.ts +2 -2
- package/dist/middleware/index.js +524 -4
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/index.mjs +517 -5
- package/dist/middleware/index.mjs.map +1 -1
- package/dist/{headers-DBQedhrb.d.mts → pii-CXcHMlnX.d.mts} +156 -2
- package/dist/{headers-BJq2OA0i.d.ts → pii-DhNpl7M3.d.ts} +156 -2
- package/dist/sanitizers/index.d.mts +2 -2
- package/dist/sanitizers/index.d.ts +2 -2
- package/dist/sanitizers/index.js +331 -3
- package/dist/sanitizers/index.js.map +1 -1
- package/dist/sanitizers/index.mjs +321 -4
- package/dist/sanitizers/index.mjs.map +1 -1
- package/dist/stores/index.d.mts +1 -1
- package/dist/stores/index.d.ts +1 -1
- package/dist/stores/index.js.map +1 -1
- package/dist/stores/index.mjs.map +1 -1
- package/dist/{types-BOdL3ZWo.d.mts → types-CsOFHoD9.d.mts} +6 -1
- package/dist/{types-BOdL3ZWo.d.ts → types-CsOFHoD9.d.ts} +6 -1
- package/dist/validation/index.d.mts +2 -2
- package/dist/validation/index.d.ts +2 -2
- package/dist/validation/index.js +504 -2
- package/dist/validation/index.js.map +1 -1
- package/dist/validation/index.mjs +498 -3
- package/dist/validation/index.mjs.map +1 -1
- package/package.json +114 -109
- package/dist/index-BgHPM7LC.d.ts +0 -129
- package/dist/index-BpT7flAQ.d.ts +0 -255
- package/dist/index-JaFOUKyK.d.mts +0 -255
- package/dist/index-nAgXexwD.d.mts +0 -129
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
import { b as ArcisOptions, o as ArcisMiddlewareStack, A as ArcisFunction, e as RateLimitOptions, h as RateLimiterMiddleware, H as HeaderOptions, E as ErrorHandlerOptions } from './types-BOdL3ZWo.mjs';
|
|
2
|
-
import { RequestHandler, Request, Response, NextFunction } from 'express';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @module @arcis/node/middleware/main
|
|
6
|
-
* Main arcis() middleware factory
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Create Arcis middleware with all protections enabled.
|
|
11
|
-
*
|
|
12
|
-
* @param options - Configuration options
|
|
13
|
-
* @returns Array of Express middleware
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* // Full protection (recommended)
|
|
17
|
-
* app.use(arcis());
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* // Custom configuration
|
|
21
|
-
* app.use(arcis({
|
|
22
|
-
* rateLimit: { max: 50 },
|
|
23
|
-
* headers: { frameOptions: 'SAMEORIGIN' }
|
|
24
|
-
* }));
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* // Disable specific features
|
|
28
|
-
* app.use(arcis({
|
|
29
|
-
* rateLimit: false,
|
|
30
|
-
* sanitize: { sql: false }
|
|
31
|
-
* }));
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* // Cleanup on shutdown
|
|
35
|
-
* const middleware = arcis();
|
|
36
|
-
* app.use(middleware);
|
|
37
|
-
* process.on('SIGTERM', () => middleware.close());
|
|
38
|
-
*/
|
|
39
|
-
declare function arcis(options?: ArcisOptions): ArcisMiddlewareStack;
|
|
40
|
-
declare const arcisWithMethods: ArcisFunction;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @module @arcis/node/middleware/rate-limit
|
|
44
|
-
* Rate limiting middleware
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Create Express middleware for rate limiting.
|
|
49
|
-
*
|
|
50
|
-
* @param options - Rate limit configuration
|
|
51
|
-
* @returns Express middleware with cleanup method
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* app.use(createRateLimiter({ max: 100, windowMs: 60000 }));
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* // Skip rate limiting for certain routes
|
|
58
|
-
* app.use(createRateLimiter({
|
|
59
|
-
* max: 50,
|
|
60
|
-
* skip: (req) => req.path === '/health'
|
|
61
|
-
* }));
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* // Cleanup on shutdown
|
|
65
|
-
* const limiter = createRateLimiter();
|
|
66
|
-
* app.use(limiter);
|
|
67
|
-
* process.on('SIGTERM', () => limiter.close());
|
|
68
|
-
*/
|
|
69
|
-
declare function createRateLimiter(options?: RateLimitOptions): RateLimiterMiddleware;
|
|
70
|
-
/**
|
|
71
|
-
* Alias for createRateLimiter
|
|
72
|
-
* @see createRateLimiter
|
|
73
|
-
*/
|
|
74
|
-
declare const rateLimit: typeof createRateLimiter;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* @module @arcis/node/middleware/headers
|
|
78
|
-
* Security headers middleware
|
|
79
|
-
*/
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Create Express middleware for security headers.
|
|
83
|
-
* Sets CSP, HSTS, X-Frame-Options, and other security headers.
|
|
84
|
-
*
|
|
85
|
-
* @param options - Header configuration
|
|
86
|
-
* @returns Express middleware
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* app.use(createHeaders());
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* app.use(createHeaders({
|
|
93
|
-
* frameOptions: 'SAMEORIGIN',
|
|
94
|
-
* contentSecurityPolicy: "default-src 'self'"
|
|
95
|
-
* }));
|
|
96
|
-
*/
|
|
97
|
-
declare function createHeaders(options?: HeaderOptions): RequestHandler;
|
|
98
|
-
/**
|
|
99
|
-
* Alias for createHeaders
|
|
100
|
-
* @see createHeaders
|
|
101
|
-
*/
|
|
102
|
-
declare const securityHeaders: typeof createHeaders;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* @module @arcis/node/middleware/error-handler
|
|
106
|
-
* Production-safe error handler middleware
|
|
107
|
-
*/
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Create Express error handler that hides sensitive details in production.
|
|
111
|
-
*
|
|
112
|
-
* Prevents information leakage by:
|
|
113
|
-
* - Hiding stack traces in production
|
|
114
|
-
* - Hiding error messages unless explicitly exposed
|
|
115
|
-
* - Scrubbing database errors, connection strings, and internal IPs
|
|
116
|
-
*
|
|
117
|
-
* @param options - Error handler configuration (or boolean for isDev)
|
|
118
|
-
* @returns Express error handling middleware
|
|
119
|
-
*
|
|
120
|
-
* @example
|
|
121
|
-
* // Production mode (default) - hides error details
|
|
122
|
-
* app.use(errorHandler());
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* // Development mode - shows error details and stack traces
|
|
126
|
-
* app.use(errorHandler({ isDev: true }));
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* // With custom logger
|
|
130
|
-
* app.use(errorHandler({
|
|
131
|
-
* isDev: false,
|
|
132
|
-
* logger: arcis.logger()
|
|
133
|
-
* }));
|
|
134
|
-
*/
|
|
135
|
-
declare function errorHandler(options?: ErrorHandlerOptions | boolean): (err: Error, req: Request, res: Response, next: NextFunction) => void;
|
|
136
|
-
/**
|
|
137
|
-
* Alias for errorHandler
|
|
138
|
-
* @see errorHandler
|
|
139
|
-
*/
|
|
140
|
-
declare const createErrorHandler: typeof errorHandler;
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* @module @arcis/node/middleware/cors
|
|
144
|
-
* Safe CORS middleware with secure defaults
|
|
145
|
-
*/
|
|
146
|
-
|
|
147
|
-
/** CORS configuration options */
|
|
148
|
-
interface CorsOptions {
|
|
149
|
-
/**
|
|
150
|
-
* Allowed origins. Can be:
|
|
151
|
-
* - A string: exact match (e.g., 'https://example.com')
|
|
152
|
-
* - An array: whitelist of allowed origins
|
|
153
|
-
* - A RegExp: pattern match (use with care)
|
|
154
|
-
* - A function: custom validation `(origin) => boolean`
|
|
155
|
-
* - `true`: reflect the request origin (DANGEROUS — only for dev)
|
|
156
|
-
*
|
|
157
|
-
* Default: none (no origin allowed). You must explicitly set this.
|
|
158
|
-
*/
|
|
159
|
-
origin: string | string[] | RegExp | ((origin: string) => boolean) | true;
|
|
160
|
-
/** Allowed HTTP methods. Default: ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'] */
|
|
161
|
-
methods?: string[];
|
|
162
|
-
/** Allowed headers. Default: ['Content-Type', 'Authorization'] */
|
|
163
|
-
allowedHeaders?: string[];
|
|
164
|
-
/** Headers exposed to the browser. Default: [] */
|
|
165
|
-
exposedHeaders?: string[];
|
|
166
|
-
/** Allow credentials (cookies, authorization headers). Default: false */
|
|
167
|
-
credentials?: boolean;
|
|
168
|
-
/** Preflight cache duration in seconds. Default: 600 (10 minutes) */
|
|
169
|
-
maxAge?: number;
|
|
170
|
-
/** Respond to preflight with 204 (no content). Default: true */
|
|
171
|
-
preflightContinue?: boolean;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Create safe CORS middleware.
|
|
175
|
-
*
|
|
176
|
-
* Unlike permissive CORS libraries, this enforces secure defaults:
|
|
177
|
-
* - No wildcard `*` when credentials are enabled
|
|
178
|
-
* - `null` origin is always blocked
|
|
179
|
-
* - `Vary: Origin` is always set for proper caching
|
|
180
|
-
* - You must explicitly configure allowed origins
|
|
181
|
-
*
|
|
182
|
-
* @param options - CORS configuration
|
|
183
|
-
* @returns Express middleware
|
|
184
|
-
*
|
|
185
|
-
* @example
|
|
186
|
-
* // Allow a single origin
|
|
187
|
-
* app.use(safeCors({ origin: 'https://myapp.com' }));
|
|
188
|
-
*
|
|
189
|
-
* @example
|
|
190
|
-
* // Allow multiple origins with credentials
|
|
191
|
-
* app.use(safeCors({
|
|
192
|
-
* origin: ['https://myapp.com', 'https://admin.myapp.com'],
|
|
193
|
-
* credentials: true,
|
|
194
|
-
* }));
|
|
195
|
-
*
|
|
196
|
-
* @example
|
|
197
|
-
* // Development: allow all (NOT for production)
|
|
198
|
-
* app.use(safeCors({ origin: true }));
|
|
199
|
-
*/
|
|
200
|
-
declare function safeCors(options: CorsOptions): RequestHandler;
|
|
201
|
-
/**
|
|
202
|
-
* Alias for safeCors
|
|
203
|
-
* @see safeCors
|
|
204
|
-
*/
|
|
205
|
-
declare const createCors: typeof safeCors;
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* @module @arcis/node/middleware/cookies
|
|
209
|
-
* Secure cookie defaults middleware
|
|
210
|
-
*/
|
|
211
|
-
|
|
212
|
-
/** Cookie security configuration */
|
|
213
|
-
interface SecureCookieOptions {
|
|
214
|
-
/** Force HttpOnly on all cookies. Default: true */
|
|
215
|
-
httpOnly?: boolean;
|
|
216
|
-
/** Force Secure flag (HTTPS only). Default: true in production, false in dev */
|
|
217
|
-
secure?: boolean;
|
|
218
|
-
/** SameSite attribute. Default: 'Lax' */
|
|
219
|
-
sameSite?: 'Strict' | 'Lax' | 'None' | false;
|
|
220
|
-
/** Override Path attribute. Default: undefined (keep original) */
|
|
221
|
-
path?: string;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Enforce secure defaults on a Set-Cookie header value.
|
|
225
|
-
*/
|
|
226
|
-
declare function enforceSecureCookie(cookieStr: string, options: Required<Omit<SecureCookieOptions, 'path'>> & {
|
|
227
|
-
path?: string;
|
|
228
|
-
}): string;
|
|
229
|
-
/**
|
|
230
|
-
* Create middleware that enforces secure cookie defaults.
|
|
231
|
-
*
|
|
232
|
-
* Intercepts Set-Cookie headers and adds missing security attributes:
|
|
233
|
-
* - HttpOnly: prevents JavaScript access (XSS cookie theft)
|
|
234
|
-
* - Secure: cookies only sent over HTTPS
|
|
235
|
-
* - SameSite: CSRF protection
|
|
236
|
-
*
|
|
237
|
-
* @param options - Cookie security configuration
|
|
238
|
-
* @returns Express middleware
|
|
239
|
-
*
|
|
240
|
-
* @example
|
|
241
|
-
* // Enforce defaults on all cookies
|
|
242
|
-
* app.use(secureCookieDefaults());
|
|
243
|
-
*
|
|
244
|
-
* @example
|
|
245
|
-
* // Strict SameSite for sensitive apps
|
|
246
|
-
* app.use(secureCookieDefaults({ sameSite: 'Strict' }));
|
|
247
|
-
*/
|
|
248
|
-
declare function secureCookieDefaults(options?: SecureCookieOptions): RequestHandler;
|
|
249
|
-
/**
|
|
250
|
-
* Alias for secureCookieDefaults
|
|
251
|
-
* @see secureCookieDefaults
|
|
252
|
-
*/
|
|
253
|
-
declare const createSecureCookies: typeof secureCookieDefaults;
|
|
254
|
-
|
|
255
|
-
export { type CorsOptions as C, type SecureCookieOptions as S, arcis as a, arcisWithMethods as b, createCors as c, createErrorHandler as d, createHeaders as e, createRateLimiter as f, createSecureCookies as g, enforceSecureCookie as h, errorHandler as i, secureCookieDefaults as j, securityHeaders as k, rateLimit as r, safeCors as s };
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { RequestHandler } from 'express';
|
|
2
|
-
import { n as ValidationSchema } from './types-BOdL3ZWo.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @module @arcis/node/validation/schema
|
|
6
|
-
* Request validation middleware
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Create Express middleware for request validation.
|
|
11
|
-
* Prevents mass assignment by only allowing fields defined in the schema.
|
|
12
|
-
*
|
|
13
|
-
* @param schema - Validation schema defining expected fields
|
|
14
|
-
* @param source - Request property to validate ('body', 'query', or 'params')
|
|
15
|
-
* @returns Express middleware
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* app.post('/users', validate({
|
|
19
|
-
* email: { type: 'email', required: true },
|
|
20
|
-
* name: { type: 'string', min: 2, max: 50 },
|
|
21
|
-
* age: { type: 'number', min: 0, max: 150 },
|
|
22
|
-
* role: { type: 'string', enum: ['user', 'admin'] }
|
|
23
|
-
* }), handler);
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* // Validate query params
|
|
27
|
-
* app.get('/search', validate({
|
|
28
|
-
* q: { type: 'string', required: true, min: 1 },
|
|
29
|
-
* page: { type: 'number', min: 1 }
|
|
30
|
-
* }, 'query'), handler);
|
|
31
|
-
*/
|
|
32
|
-
declare function validate(schema: ValidationSchema, source?: 'body' | 'query' | 'params'): RequestHandler;
|
|
33
|
-
/**
|
|
34
|
-
* Alias for validate
|
|
35
|
-
* @see validate
|
|
36
|
-
*/
|
|
37
|
-
declare const createValidator: typeof validate;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @module @arcis/node/validation/file
|
|
41
|
-
* File upload validation and filename sanitization
|
|
42
|
-
*/
|
|
43
|
-
/** File upload validation options */
|
|
44
|
-
interface ValidateFileOptions {
|
|
45
|
-
/** Maximum file size in bytes. Default: 5MB */
|
|
46
|
-
maxSize?: number;
|
|
47
|
-
/** Allowed MIME types (e.g., ['image/jpeg', 'image/png']) */
|
|
48
|
-
allowedTypes?: string[];
|
|
49
|
-
/** Allowed file extensions (e.g., ['.jpg', '.png']). Includes dot. */
|
|
50
|
-
allowedExtensions?: string[];
|
|
51
|
-
/** Block dangerous/executable extensions. Default: true */
|
|
52
|
-
blockExecutables?: boolean;
|
|
53
|
-
/** Validate magic bytes match the claimed MIME type. Default: true */
|
|
54
|
-
validateMagicBytes?: boolean;
|
|
55
|
-
/** Block files with no extension. Default: true */
|
|
56
|
-
blockNoExtension?: boolean;
|
|
57
|
-
/** Block double extensions (e.g., file.php.jpg). Default: true */
|
|
58
|
-
blockDoubleExtensions?: boolean;
|
|
59
|
-
}
|
|
60
|
-
/** File metadata for validation */
|
|
61
|
-
interface FileInput {
|
|
62
|
-
/** Original filename */
|
|
63
|
-
filename: string;
|
|
64
|
-
/** MIME type (as claimed by client) */
|
|
65
|
-
mimetype: string;
|
|
66
|
-
/** File size in bytes */
|
|
67
|
-
size: number;
|
|
68
|
-
/** File content buffer (for magic byte validation) */
|
|
69
|
-
buffer?: Buffer;
|
|
70
|
-
}
|
|
71
|
-
/** File validation result */
|
|
72
|
-
interface ValidateFileResult {
|
|
73
|
-
/** Whether the file passed validation */
|
|
74
|
-
valid: boolean;
|
|
75
|
-
/** Validation errors (empty if valid) */
|
|
76
|
-
errors: string[];
|
|
77
|
-
/** Sanitized filename (safe for storage) */
|
|
78
|
-
sanitizedFilename: string;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Sanitize a filename for safe storage.
|
|
82
|
-
*
|
|
83
|
-
* Strips path traversal, null bytes, control characters, and special characters.
|
|
84
|
-
* Preserves the extension and converts to a filesystem-safe name.
|
|
85
|
-
*
|
|
86
|
-
* @param filename - The original filename
|
|
87
|
-
* @returns A sanitized filename safe for storage
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* sanitizeFilename('../../etc/passwd') // 'etc_passwd'
|
|
91
|
-
* sanitizeFilename('file<name>.jpg') // 'filename.jpg'
|
|
92
|
-
* sanitizeFilename('photo (1).jpg') // 'photo_1.jpg'
|
|
93
|
-
* sanitizeFilename('.htaccess') // 'htaccess'
|
|
94
|
-
*/
|
|
95
|
-
declare function sanitizeFilename(filename: string): string;
|
|
96
|
-
/**
|
|
97
|
-
* Validate a file upload for security.
|
|
98
|
-
*
|
|
99
|
-
* Checks file size, MIME type, extension, magic bytes, and dangerous patterns.
|
|
100
|
-
* Returns a result with validation errors and a sanitized filename.
|
|
101
|
-
*
|
|
102
|
-
* @param file - File metadata and optional content
|
|
103
|
-
* @param options - Validation options
|
|
104
|
-
* @returns Validation result
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* const result = validateFile(
|
|
108
|
-
* { filename: 'photo.jpg', mimetype: 'image/jpeg', size: 1024, buffer },
|
|
109
|
-
* { allowedTypes: ['image/jpeg', 'image/png'], maxSize: 2 * 1024 * 1024 }
|
|
110
|
-
* );
|
|
111
|
-
* if (!result.valid) {
|
|
112
|
-
* return res.status(400).json({ errors: result.errors });
|
|
113
|
-
* }
|
|
114
|
-
* // Use result.sanitizedFilename for storage
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
* // Block executables only (no whitelist)
|
|
118
|
-
* const result = validateFile(file, { blockExecutables: true });
|
|
119
|
-
*/
|
|
120
|
-
declare function validateFile(file: FileInput, options?: ValidateFileOptions): ValidateFileResult;
|
|
121
|
-
/**
|
|
122
|
-
* Check if a file extension is considered dangerous/executable.
|
|
123
|
-
*
|
|
124
|
-
* @param filename - Filename or extension to check
|
|
125
|
-
* @returns true if the extension is dangerous
|
|
126
|
-
*/
|
|
127
|
-
declare function isDangerousExtension(filename: string): boolean;
|
|
128
|
-
|
|
129
|
-
export { type FileInput as F, type ValidateFileOptions as V, type ValidateFileResult as a, validateFile as b, createValidator as c, isDangerousExtension as i, sanitizeFilename as s, validate as v };
|