@adaptivestone/framework 5.6.1 → 5.7.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/CHANGELOG.md +48 -0
- package/README.md +75 -0
- package/dist/clusterRunner.js +2 -1
- package/dist/clusterRunner.js.map +1 -1
- package/dist/codegen/astEmit.js +7 -0
- package/dist/codegen/astEmit.js.map +1 -1
- package/dist/codegen/astExtract.d.ts +3 -0
- package/dist/codegen/astExtract.js +1 -0
- package/dist/codegen/astExtract.js.map +1 -1
- package/dist/codegen/astResolve.d.ts +2 -0
- package/dist/codegen/astResolve.js +1 -0
- package/dist/codegen/astResolve.js.map +1 -1
- package/dist/codegen/emit.js +1 -1
- package/dist/codegen/index.js +1 -1
- package/dist/codegen/index.js.map +1 -1
- package/dist/config/http.js +5 -2
- package/dist/config/http.js.map +1 -1
- package/dist/controllers/Auth.d.ts +22 -14
- package/dist/controllers/Auth.js +38 -72
- package/dist/controllers/Auth.js.map +1 -1
- package/dist/controllers/Auth.routes.gen.d.ts +1 -1
- package/dist/controllers/Auth.routes.gen.js +1 -1
- package/dist/controllers/Health.d.ts +8 -5
- package/dist/controllers/Health.js +11 -6
- package/dist/controllers/Health.js.map +1 -1
- package/dist/controllers/Health.routes.gen.d.ts +1 -1
- package/dist/controllers/Health.routes.gen.js +1 -1
- package/dist/controllers/Home.d.ts +3 -2
- package/dist/controllers/Home.js +6 -2
- package/dist/controllers/Home.js.map +1 -1
- package/dist/controllers/Home.routes.gen.d.ts +1 -1
- package/dist/controllers/Home.routes.gen.js +1 -1
- package/dist/controllers/index.js +39 -29
- package/dist/controllers/index.js.map +1 -1
- package/dist/helpers/crypto.d.ts +6 -0
- package/dist/helpers/crypto.js +18 -4
- package/dist/helpers/crypto.js.map +1 -1
- package/dist/helpers/logger.d.ts +3 -1
- package/dist/helpers/logger.js +11 -1
- package/dist/helpers/logger.js.map +1 -1
- package/dist/helpers/passwordPolicy.d.ts +23 -0
- package/dist/helpers/passwordPolicy.js +62 -0
- package/dist/helpers/passwordPolicy.js.map +1 -0
- package/dist/helpers/redis/redisConnection.d.ts +1 -0
- package/dist/helpers/redis/redisConnection.js +1 -0
- package/dist/helpers/redis/redisConnection.js.map +1 -1
- package/dist/helpers/yup.d.ts +11 -5
- package/dist/helpers/yup.js +12 -6
- package/dist/helpers/yup.js.map +1 -1
- package/dist/locales/ru/translation.json +31 -0
- package/dist/models/User.d.ts +5 -4
- package/dist/models/User.js +0 -3
- package/dist/models/User.js.map +1 -1
- package/dist/models/UserOld.d.ts +2 -0
- package/dist/models/UserOld.js +9 -3
- package/dist/models/UserOld.js.map +1 -1
- package/dist/server.d.ts +22 -2
- package/dist/server.js +83 -14
- package/dist/server.js.map +1 -1
- package/dist/services/http/ExpressResponseWriter.d.ts +30 -0
- package/dist/services/http/ExpressResponseWriter.js +447 -0
- package/dist/services/http/ExpressResponseWriter.js.map +1 -0
- package/dist/services/http/HttpServer.d.ts +16 -10
- package/dist/services/http/HttpServer.js +71 -23
- package/dist/services/http/HttpServer.js.map +1 -1
- package/dist/services/http/ResponseWriter.d.ts +11 -0
- package/dist/services/http/ResponseWriter.js +2 -0
- package/dist/services/http/ResponseWriter.js.map +1 -0
- package/dist/services/http/builtInResponse.d.ts +26 -0
- package/dist/services/http/builtInResponse.js +70 -0
- package/dist/services/http/builtInResponse.js.map +1 -0
- package/dist/services/http/builtinErrorHandlers.d.ts +52 -5
- package/dist/services/http/builtinErrorHandlers.js +86 -5
- package/dist/services/http/builtinErrorHandlers.js.map +1 -1
- package/dist/services/http/files.d.ts +21 -8
- package/dist/services/http/files.js +2 -18
- package/dist/services/http/files.js.map +1 -1
- package/dist/services/http/httpErrors.d.ts +40 -2
- package/dist/services/http/httpErrors.js +50 -2
- package/dist/services/http/httpErrors.js.map +1 -1
- package/dist/services/http/middleware/RateLimiter.d.ts +1 -0
- package/dist/services/http/middleware/RateLimiter.js +36 -13
- package/dist/services/http/middleware/RateLimiter.js.map +1 -1
- package/dist/services/http/middleware/RequestParser.d.ts +5 -2
- package/dist/services/http/middleware/RequestParser.js +43 -25
- package/dist/services/http/middleware/RequestParser.js.map +1 -1
- package/dist/services/http/responses.d.ts +114 -0
- package/dist/services/http/responses.js +191 -0
- package/dist/services/http/responses.js.map +1 -0
- package/dist/services/http/routing/ExpressAdapter.d.ts +4 -1
- package/dist/services/http/routing/ExpressAdapter.js +82 -9
- package/dist/services/http/routing/ExpressAdapter.js.map +1 -1
- package/dist/services/validate/drivers/YupDriver.js +44 -6
- package/dist/services/validate/drivers/YupDriver.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,18 +1,31 @@
|
|
|
1
|
+
import { type File as ParsedFile, PersistentFile } from 'formidable';
|
|
1
2
|
/**
|
|
2
3
|
* Uploaded-file type. Today it aliases formidable's `PersistentFile`; the
|
|
3
4
|
* future transport-neutral parser swap (P3) re-points it at the web-standard
|
|
4
5
|
* `File`. Import this instead of the concrete parser class so your file
|
|
5
6
|
* validation survives that swap untouched.
|
|
6
7
|
*
|
|
7
|
-
* Validate uploads with
|
|
8
|
+
* Validate uploads with an `instanceof` check. A file field always arrives as
|
|
9
|
+
* an array; check the array as a whole, so an error stays under the field name
|
|
10
|
+
* (a per-element check reports `avatar[0]`, not `avatar`):
|
|
8
11
|
*
|
|
9
12
|
* import { File } from '@adaptivestone/framework/types.js';
|
|
10
|
-
*
|
|
11
|
-
* //
|
|
12
|
-
* //
|
|
13
|
-
* //
|
|
13
|
+
* const files = (v: unknown) => Array.isArray(v) && v.every((f) => f instanceof File);
|
|
14
|
+
* // zod: z.custom<File[]>(files, 'not a file')
|
|
15
|
+
* // valibot: v.custom<File[]>(files, 'not a file')
|
|
16
|
+
* // arktype: type('unknown').narrow((v, ctx) => files(v) || ctx.mustBe('an array of files'))
|
|
17
|
+
* // yup: mixed<File[]>().test('file', 'not a file', files)
|
|
14
18
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
19
|
+
* A missing field fails these checks; for an optional one, let `files` also
|
|
20
|
+
* accept `undefined`.
|
|
21
|
+
*
|
|
22
|
+
* `File` is both a value (the parser's class, for `instanceof`) and a type
|
|
23
|
+
* (an upload with `filepath`, `mimetype`, `originalFilename`, `size`, …).
|
|
17
24
|
*/
|
|
18
|
-
export
|
|
25
|
+
export type File = InstanceType<typeof PersistentFile> & ParsedFile;
|
|
26
|
+
interface FileClass {
|
|
27
|
+
new (...args: ConstructorParameters<typeof PersistentFile>): File;
|
|
28
|
+
readonly prototype: File;
|
|
29
|
+
}
|
|
30
|
+
export declare const File: FileClass;
|
|
31
|
+
export {};
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* future transport-neutral parser swap (P3) re-points it at the web-standard
|
|
4
|
-
* `File`. Import this instead of the concrete parser class so your file
|
|
5
|
-
* validation survives that swap untouched.
|
|
6
|
-
*
|
|
7
|
-
* Validate uploads with your validator's idiomatic `instanceof` check:
|
|
8
|
-
*
|
|
9
|
-
* import { File } from '@adaptivestone/framework/types.js';
|
|
10
|
-
* // zod: z.instanceof(File)
|
|
11
|
-
* // valibot: v.instance(File)
|
|
12
|
-
* // arktype: type.instanceOf(File)
|
|
13
|
-
* // yup: mixed().test('file', 'not a file', (v) => v instanceof File)
|
|
14
|
-
*
|
|
15
|
-
* `File` is both a value (for `instanceof`) and a type (for annotations),
|
|
16
|
-
* because it is a class.
|
|
17
|
-
*/
|
|
18
|
-
export { PersistentFile as File } from 'formidable';
|
|
1
|
+
import { PersistentFile } from 'formidable';
|
|
2
|
+
export const File = PersistentFile;
|
|
19
3
|
//# sourceMappingURL=files.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../../src/services/http/files.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../../src/services/http/files.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,cAAc,EAAE,MAAM,YAAY,CAAC;AAgCrE,MAAM,CAAC,MAAM,IAAI,GAAG,cAAsC,CAAC"}
|
|
@@ -31,6 +31,29 @@ export interface HttpErrorBodyDetails {
|
|
|
31
31
|
errors?: never;
|
|
32
32
|
}
|
|
33
33
|
export type HttpErrorDetails = HttpErrorContractDetails | HttpErrorBodyDetails;
|
|
34
|
+
/**
|
|
35
|
+
* The `error` codes of the framework's validation, routing, body-parsing and
|
|
36
|
+
* server error responses, so a client can tell them apart without parsing the
|
|
37
|
+
* translated `message`.
|
|
38
|
+
*/
|
|
39
|
+
export declare const FRAMEWORK_ERROR_CODES: {
|
|
40
|
+
/** 400: a `params:`/`request:`/`query:` schema rejected the input (also the Mongoose safety nets). */
|
|
41
|
+
readonly validationFailed: 'VALIDATION_FAILED';
|
|
42
|
+
/** 400: the URL path could not be decoded. */
|
|
43
|
+
readonly malformedUrl: 'MALFORMED_URL';
|
|
44
|
+
/** 400: the request body could not be parsed. */
|
|
45
|
+
readonly malformedBody: 'MALFORMED_BODY';
|
|
46
|
+
/** 404: no route matches the path. */
|
|
47
|
+
readonly notFound: 'NOT_FOUND';
|
|
48
|
+
/** 405: a route matches the path, but not the method. */
|
|
49
|
+
readonly methodNotAllowed: 'METHOD_NOT_ALLOWED';
|
|
50
|
+
/** 413: the request body exceeds the configured limits. */
|
|
51
|
+
readonly payloadTooLarge: 'PAYLOAD_TOO_LARGE';
|
|
52
|
+
/** 415: the route accepts none of the request's content type. */
|
|
53
|
+
readonly unsupportedContentType: 'UNSUPPORTED_CONTENT_TYPE';
|
|
54
|
+
/** 500: an error nothing in the error-handler registry resolved. */
|
|
55
|
+
readonly serverError: 'SERVER_ERROR';
|
|
56
|
+
};
|
|
34
57
|
/**
|
|
35
58
|
* Throwable HTTP errors — the deliberate way to produce a status from deep
|
|
36
59
|
* business logic without threading `res`. Thrown from a route handler or a
|
|
@@ -38,9 +61,9 @@ export type HttpErrorDetails = HttpErrorContractDetails | HttpErrorBodyDetails;
|
|
|
38
61
|
* (`HttpServer.registerErrorHandler`) via a built-in mapper:
|
|
39
62
|
* `status` + `{ error?: code, message, errors? }` (message translated via
|
|
40
63
|
* `i18nKey`, field errors like request validation) or a custom `body`, logged
|
|
41
|
-
* at `verbose` (control flow, not a defect).
|
|
64
|
+
* at `verbose` (control flow, not a defect), or `error` for a 5xx.
|
|
42
65
|
* Subclass for other statuses, or construct the base directly:
|
|
43
|
-
* `new HttpError(
|
|
66
|
+
* `new HttpError(402, 'Payment required')`.
|
|
44
67
|
*/
|
|
45
68
|
export declare class HttpError extends Error {
|
|
46
69
|
readonly status: number;
|
|
@@ -81,3 +104,18 @@ export declare class ConflictError extends HttpError {
|
|
|
81
104
|
/** @deprecated Use `{ message, errors }` for field errors, or `{ message, body }` for a custom body. Removed in v6. */
|
|
82
105
|
constructor(message: string | HttpErrorDetails | undefined, body: unknown);
|
|
83
106
|
}
|
|
107
|
+
export declare class UnprocessableEntityError extends HttpError {
|
|
108
|
+
constructor(message?: string | HttpErrorDetails);
|
|
109
|
+
}
|
|
110
|
+
export declare class TooManyRequestsError extends HttpError {
|
|
111
|
+
constructor(message?: string | HttpErrorDetails);
|
|
112
|
+
}
|
|
113
|
+
export declare class InternalServerError extends HttpError {
|
|
114
|
+
constructor(message?: string | HttpErrorDetails);
|
|
115
|
+
}
|
|
116
|
+
export declare class BadGatewayError extends HttpError {
|
|
117
|
+
constructor(message?: string | HttpErrorDetails);
|
|
118
|
+
}
|
|
119
|
+
export declare class ServiceUnavailableError extends HttpError {
|
|
120
|
+
constructor(message?: string | HttpErrorDetails);
|
|
121
|
+
}
|
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
import { makeOncePerClassWarner } from '../../helpers/deprecation.js';
|
|
2
2
|
import { ValidationError, } from '../validate/ValidationError.js';
|
|
3
|
+
/**
|
|
4
|
+
* The `error` codes of the framework's validation, routing, body-parsing and
|
|
5
|
+
* server error responses, so a client can tell them apart without parsing the
|
|
6
|
+
* translated `message`.
|
|
7
|
+
*/
|
|
8
|
+
export const FRAMEWORK_ERROR_CODES = {
|
|
9
|
+
/** 400: a `params:`/`request:`/`query:` schema rejected the input (also the Mongoose safety nets). */
|
|
10
|
+
validationFailed: 'VALIDATION_FAILED',
|
|
11
|
+
/** 400: the URL path could not be decoded. */
|
|
12
|
+
malformedUrl: 'MALFORMED_URL',
|
|
13
|
+
/** 400: the request body could not be parsed. */
|
|
14
|
+
malformedBody: 'MALFORMED_BODY',
|
|
15
|
+
/** 404: no route matches the path. */
|
|
16
|
+
notFound: 'NOT_FOUND',
|
|
17
|
+
/** 405: a route matches the path, but not the method. */
|
|
18
|
+
methodNotAllowed: 'METHOD_NOT_ALLOWED',
|
|
19
|
+
/** 413: the request body exceeds the configured limits. */
|
|
20
|
+
payloadTooLarge: 'PAYLOAD_TOO_LARGE',
|
|
21
|
+
/** 415: the route accepts none of the request's content type. */
|
|
22
|
+
unsupportedContentType: 'UNSUPPORTED_CONTENT_TYPE',
|
|
23
|
+
/** 500: an error nothing in the error-handler registry resolved. */
|
|
24
|
+
serverError: 'SERVER_ERROR',
|
|
25
|
+
};
|
|
3
26
|
const CONTRACT_FIELDS = ['code', 'i18nKey', 'errors'];
|
|
4
27
|
const warnBodyMixed = makeOncePerClassWarner('ASF_HTTP_ERROR_BODY_MIXED', (name, ignored) => `${name} received body together with ${String(ignored)}. body replaces the whole response, so those are ignored. Pass body alone, or drop it to answer { error?, message, errors? }.`, 'Warning');
|
|
5
28
|
const warnBodyArgument = makeOncePerClassWarner('ASF_DEP_HTTP_ERROR_BODY', (name) => `${name} received the positional body argument, which is deprecated. Use the details object instead: { message, errors } for field errors, or { message, body } for a custom body. The argument will be removed in v6.`);
|
|
@@ -10,9 +33,9 @@ const warnBodyArgument = makeOncePerClassWarner('ASF_DEP_HTTP_ERROR_BODY', (name
|
|
|
10
33
|
* (`HttpServer.registerErrorHandler`) via a built-in mapper:
|
|
11
34
|
* `status` + `{ error?: code, message, errors? }` (message translated via
|
|
12
35
|
* `i18nKey`, field errors like request validation) or a custom `body`, logged
|
|
13
|
-
* at `verbose` (control flow, not a defect).
|
|
36
|
+
* at `verbose` (control flow, not a defect), or `error` for a 5xx.
|
|
14
37
|
* Subclass for other statuses, or construct the base directly:
|
|
15
|
-
* `new HttpError(
|
|
38
|
+
* `new HttpError(402, 'Payment required')`.
|
|
16
39
|
*/
|
|
17
40
|
export class HttpError extends Error {
|
|
18
41
|
status;
|
|
@@ -79,4 +102,29 @@ export class ConflictError extends HttpError {
|
|
|
79
102
|
super(409, message, body);
|
|
80
103
|
}
|
|
81
104
|
}
|
|
105
|
+
export class UnprocessableEntityError extends HttpError {
|
|
106
|
+
constructor(message = 'Unprocessable entity') {
|
|
107
|
+
super(422, message);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export class TooManyRequestsError extends HttpError {
|
|
111
|
+
constructor(message = 'Too many requests') {
|
|
112
|
+
super(429, message);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export class InternalServerError extends HttpError {
|
|
116
|
+
constructor(message = 'Internal server error') {
|
|
117
|
+
super(500, message);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export class BadGatewayError extends HttpError {
|
|
121
|
+
constructor(message = 'Bad gateway') {
|
|
122
|
+
super(502, message);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
export class ServiceUnavailableError extends HttpError {
|
|
126
|
+
constructor(message = 'Service unavailable') {
|
|
127
|
+
super(503, message);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
82
130
|
//# sourceMappingURL=httpErrors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpErrors.js","sourceRoot":"","sources":["../../../src/services/http/httpErrors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAEtE,OAAO,EACL,eAAe,GAEhB,MAAM,gCAAgC,CAAC;AAoCxC,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAU,CAAC;AAE/D,MAA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AAO,GAA8B,uBAAuB;QACtE,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACtB,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,YAAY,OAAO,GAA8B,aAAa;QAC5D,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACtB,CAAC;CACF;AAED,MAAM,OAAO,uBAAwB,SAAQ,SAAS;IACpD,YAAY,OAAO,GAA8B,qBAAqB;QACpE,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -6,6 +6,7 @@ import type { FrameworkRequest } from '../HttpServer.ts';
|
|
|
6
6
|
import AbstractMiddleware from './AbstractMiddleware.ts';
|
|
7
7
|
import type { GetUserByTokenAppInfo } from './GetUserByToken.ts';
|
|
8
8
|
declare class RateLimiter extends AbstractMiddleware {
|
|
9
|
+
#private;
|
|
9
10
|
static get description(): string;
|
|
10
11
|
finalOptions: typeof rateLimiterConfig;
|
|
11
12
|
limiter: RateLimiterAbstract;
|
|
@@ -3,7 +3,7 @@ import merge from 'deepmerge';
|
|
|
3
3
|
import mongoose from 'mongoose';
|
|
4
4
|
import { RateLimiterMemory, RateLimiterMongo, RateLimiterRedis, } from 'rate-limiter-flexible';
|
|
5
5
|
import { makeOncePerClassWarner } from '../../../helpers/deprecation.js';
|
|
6
|
-
import { HttpError } from '../httpErrors.js';
|
|
6
|
+
import { FRAMEWORK_ERROR_CODES, HttpError } from '../httpErrors.js';
|
|
7
7
|
import AbstractMiddleware from './AbstractMiddleware.js';
|
|
8
8
|
const warnMisspelledKeyOverride = makeOncePerClassWarner('ASF_DEP_RATE_LIMITER_KEY_METHOD', (name) => `Middleware "${name}" overrides RateLimiter.gerenateConsumeKey, which is renamed to generateConsumeKey. Rename the override — the old name will be removed in v6.`);
|
|
9
9
|
class RateLimiter extends AbstractMiddleware {
|
|
@@ -19,6 +19,8 @@ class RateLimiter extends AbstractMiddleware {
|
|
|
19
19
|
* first request.
|
|
20
20
|
*/
|
|
21
21
|
whenReady = Promise.resolve();
|
|
22
|
+
/** The shared-bucket warning is logged once per limiter. */
|
|
23
|
+
#warnedSharedBucket = false;
|
|
22
24
|
constructor(app, params) {
|
|
23
25
|
super(app, params);
|
|
24
26
|
const limiterOptions = this.app.getConfig('rateLimiter');
|
|
@@ -75,12 +77,22 @@ class RateLimiter extends AbstractMiddleware {
|
|
|
75
77
|
}
|
|
76
78
|
catch (e) {
|
|
77
79
|
// Leave `this.limiter` undefined so `middleware()` returns 500 (same as an
|
|
78
|
-
// unknown driver) rather than crashing — e.g. `@redis/client` not
|
|
79
|
-
|
|
80
|
+
// unknown driver) rather than crashing — e.g. `@redis/client` not
|
|
81
|
+
// installed, or a malformed `redis.url` the client cannot parse.
|
|
82
|
+
this.logger?.error(`RateLimiter redis init failed, so its routes answer 500: ${e}. Check that redis.url (REDIS_URI) is a valid redis:// or rediss:// URL and that '@redis/client' is installed.`);
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
generateConsumeKey(req) {
|
|
83
86
|
const { ip, route, user, request } = this.finalOptions.consumeKeyComponents;
|
|
87
|
+
// Concrete URLs are attacker-controlled: aliases and different IDs
|
|
88
|
+
// must consume the registered route's budget. A global/unmatched limiter
|
|
89
|
+
// uses one fixed bucket until routing has established a template.
|
|
90
|
+
const method = req.method === 'HEAD' &&
|
|
91
|
+
req.route?.methods?.get &&
|
|
92
|
+
!req.route?.methods?.head
|
|
93
|
+
? 'GET'
|
|
94
|
+
: (req.method ?? 'ALL');
|
|
95
|
+
const routePath = req.route?.path ?? 'unmatched';
|
|
84
96
|
const key = [];
|
|
85
97
|
if (ip) {
|
|
86
98
|
if (!req.appInfo.ip) {
|
|
@@ -91,18 +103,14 @@ class RateLimiter extends AbstractMiddleware {
|
|
|
91
103
|
}
|
|
92
104
|
}
|
|
93
105
|
if (route) {
|
|
94
|
-
|
|
95
|
-
// must consume the registered route's budget. A global/unmatched limiter
|
|
96
|
-
// uses one fixed bucket until routing has established a template.
|
|
97
|
-
const method = req.method === 'HEAD' &&
|
|
98
|
-
req.route?.methods?.get &&
|
|
99
|
-
!req.route?.methods?.head
|
|
100
|
-
? 'GET'
|
|
101
|
-
: (req.method ?? 'ALL');
|
|
102
|
-
key.push(`${method}:${req.route?.path ?? 'unmatched'}`);
|
|
106
|
+
key.push(`${method}:${routePath}`);
|
|
103
107
|
}
|
|
108
|
+
// Only a truthy id identifies a user (a model with `id: false` has none);
|
|
109
|
+
// the key keeps the empty part as before.
|
|
110
|
+
let identified = false;
|
|
104
111
|
if (user && req.appInfo?.user) {
|
|
105
112
|
key.push(req.appInfo?.user.id);
|
|
113
|
+
identified = Boolean(req.appInfo.user.id);
|
|
106
114
|
}
|
|
107
115
|
if (request?.length) {
|
|
108
116
|
// Raw body, before validation: fold the spellings a normalizing lookup
|
|
@@ -123,8 +131,20 @@ class RateLimiter extends AbstractMiddleware {
|
|
|
123
131
|
// out of stored keys and the 429 log line.
|
|
124
132
|
if (fields.length) {
|
|
125
133
|
key.push(createHash('sha256').update(JSON.stringify(fields)).digest('hex'));
|
|
134
|
+
identified = true;
|
|
126
135
|
}
|
|
127
136
|
}
|
|
137
|
+
// Without ip, all requests lacking every enabled identity share one
|
|
138
|
+
// bucket per route. With every identity disabled, that shared bucket is
|
|
139
|
+
// the intended per-route budget.
|
|
140
|
+
if (!ip &&
|
|
141
|
+
(user || request?.length) &&
|
|
142
|
+
!identified &&
|
|
143
|
+
!this.#warnedSharedBucket) {
|
|
144
|
+
this.#warnedSharedBucket = true;
|
|
145
|
+
const missing = [...(user ? ['user'] : []), ...(request ?? [])];
|
|
146
|
+
this.logger?.warn(`RateLimiter on ${method} ${routePath}: ip is disabled and this request has no ${missing.join(' or ')}, so such requests share one rate-limit bucket. Enable ip in consumeKeyComponents, or limit only routes where the identity is always present.`);
|
|
147
|
+
}
|
|
128
148
|
return key.join('_');
|
|
129
149
|
}
|
|
130
150
|
/** @deprecated Misspelled; use {@link generateConsumeKey}. Removed in v6. */
|
|
@@ -159,7 +179,10 @@ class RateLimiter extends AbstractMiddleware {
|
|
|
159
179
|
await this.whenReady;
|
|
160
180
|
if (!this.limiter) {
|
|
161
181
|
this.logger?.info(`RateLimiter not inited correclty! Please check init logs `);
|
|
162
|
-
return res.status(500).json({
|
|
182
|
+
return res.status(500).json({
|
|
183
|
+
error: FRAMEWORK_ERROR_CODES.serverError,
|
|
184
|
+
message: 'RateLimiter error',
|
|
185
|
+
});
|
|
163
186
|
}
|
|
164
187
|
// The redis `namespace` prefixes the consume key regardless of driver
|
|
165
188
|
// (memory/mongo too) — intentional, so keys stay stable across a driver
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RateLimiter.js","sourceRoot":"","sources":["../../../../src/services/http/middleware/RateLimiter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,MAAM,WAAW,CAAC;AAE9B,OAAO,QAAQ,MAAM,UAAU,CAAC;AAKhC,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAGzE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"RateLimiter.js","sourceRoot":"","sources":["../../../../src/services/http/middleware/RateLimiter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,MAAM,WAAW,CAAC;AAE9B,OAAO,QAAQ,MAAM,UAAU,CAAC;AAKhC,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAGzE,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,kBAA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E,EAAE,aAAa,EAAE,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE;SAC7D,CAAC,CAAC;IACL,CAAC;CACF;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -9,10 +9,13 @@ export type RequestBodyFormat = 'json' | 'urlencoded';
|
|
|
9
9
|
* (explicit per-mount params override them), and so do extra media types to
|
|
10
10
|
* parse as JSON or urlencoded (`mediaTypes`). Spooled upload temp files are
|
|
11
11
|
* unlinked once the response finishes — a handler that needs to keep an upload
|
|
12
|
-
* MUST move or copy it (e.g. `fs.rename`) before responding.
|
|
12
|
+
* MUST move or copy it (e.g. `fs.rename`) before responding. An oversized body
|
|
13
|
+
* (413) or an unparsable one (400) is passed on as an `HttpError`, so the
|
|
14
|
+
* error-handler registry answers it.
|
|
13
15
|
*/
|
|
14
16
|
declare class RequestParser extends AbstractMiddleware {
|
|
17
|
+
#private;
|
|
15
18
|
static get description(): string;
|
|
16
|
-
middleware(req: FrameworkRequest, res: Response, next: NextFunction): Promise<void | Response
|
|
19
|
+
middleware(req: FrameworkRequest, res: Response, next: NextFunction): Promise<void | Response>;
|
|
17
20
|
}
|
|
18
21
|
export default RequestParser;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { unlink } from 'node:fs/promises';
|
|
2
2
|
import formidable, { json, multipart, octetstream, querystring, } from 'formidable';
|
|
3
3
|
import { normalizeContentType } from '../../validate/contentType.js';
|
|
4
|
+
import { FRAMEWORK_ERROR_CODES, HttpError } from '../httpErrors.js';
|
|
4
5
|
import AbstractMiddleware from './AbstractMiddleware.js';
|
|
5
6
|
const bodyFormats = {
|
|
6
7
|
json: { plugin: json, mediaType: 'application/json' },
|
|
@@ -50,7 +51,9 @@ function asMediaType(plugin, mediaType) {
|
|
|
50
51
|
* (explicit per-mount params override them), and so do extra media types to
|
|
51
52
|
* parse as JSON or urlencoded (`mediaTypes`). Spooled upload temp files are
|
|
52
53
|
* unlinked once the response finishes — a handler that needs to keep an upload
|
|
53
|
-
* MUST move or copy it (e.g. `fs.rename`) before responding.
|
|
54
|
+
* MUST move or copy it (e.g. `fs.rename`) before responding. An oversized body
|
|
55
|
+
* (413) or an unparsable one (400) is passed on as an `HttpError`, so the
|
|
56
|
+
* error-handler registry answers it.
|
|
54
57
|
*/
|
|
55
58
|
class RequestParser extends AbstractMiddleware {
|
|
56
59
|
static get description() {
|
|
@@ -88,26 +91,28 @@ class RequestParser extends AbstractMiddleware {
|
|
|
88
91
|
...parserOptions,
|
|
89
92
|
...(plugin ? { enabledPlugins: [plugin] } : {}),
|
|
90
93
|
});
|
|
91
|
-
// JSON/urlencoded parsing buffers the body
|
|
92
|
-
//
|
|
93
|
-
//
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
// JSON/urlencoded parsing buffers the body, bounded by maxFieldsSize, and
|
|
95
|
+
// unknown media types retain the v5 fallback. Multipart uses Formidable's
|
|
96
|
+
// file limits. An octet-stream body is one file, but Formidable checks
|
|
97
|
+
// those limits only on multipart parts, so it is bounded here by them.
|
|
98
|
+
const { maxFileSize, maxTotalFileSize } = form.options;
|
|
99
|
+
const limitName = isOctetStream ? 'maxFileSize' : 'maxFieldsSize';
|
|
100
|
+
const maxBodySize = isOctetStream
|
|
101
|
+
? Math.min(maxFileSize, maxTotalFileSize)
|
|
102
|
+
: typeof parserOptions.maxFieldsSize === 'number'
|
|
103
|
+
? parserOptions.maxFieldsSize
|
|
104
|
+
: 2 * 1024 * 1024;
|
|
97
105
|
let bodyTooLarge = false;
|
|
98
|
-
if (!isMultipart
|
|
106
|
+
if (!isMultipart) {
|
|
99
107
|
const declaredLength = Number(req.headers?.['content-length']);
|
|
100
108
|
if (Number.isFinite(declaredLength) && declaredLength > maxBodySize) {
|
|
101
|
-
this.logger?.error(`Request body ${declaredLength}B exceeds
|
|
109
|
+
this.logger?.error(`Request body ${declaredLength}B exceeds ${limitName} ${maxBodySize}B`);
|
|
102
110
|
// Close after the 413 instead of draining the unread body.
|
|
103
111
|
res.setHeader('Connection', 'close');
|
|
104
|
-
return
|
|
105
|
-
message: this.translate(req, 'middleware.requestParser.entityTooLarge', 'Request entity too large. Your upload exceeds the allowed size or count limits.'),
|
|
106
|
-
});
|
|
112
|
+
return next(this.#entityTooLarge(req));
|
|
107
113
|
}
|
|
108
114
|
}
|
|
109
|
-
// Also guard chunked
|
|
110
|
-
// limits. Pausing (not destroying) the request keeps the socket writable,
|
|
115
|
+
// Also guard chunked bodies. Multipart enforces its own file limits. Pausing (not destroying) the request keeps the socket writable,
|
|
111
116
|
// so the client receives the 413; its `Connection: close` then ends the
|
|
112
117
|
// connection.
|
|
113
118
|
let rejectOversized = () => { };
|
|
@@ -115,13 +120,10 @@ class RequestParser extends AbstractMiddleware {
|
|
|
115
120
|
rejectOversized = reject;
|
|
116
121
|
});
|
|
117
122
|
form.on('progress', (bytesReceived) => {
|
|
118
|
-
if (!bodyTooLarge &&
|
|
119
|
-
!isMultipart &&
|
|
120
|
-
!isOctetStream &&
|
|
121
|
-
bytesReceived > maxBodySize) {
|
|
123
|
+
if (!bodyTooLarge && !isMultipart && bytesReceived > maxBodySize) {
|
|
122
124
|
bodyTooLarge = true;
|
|
123
125
|
req.pause();
|
|
124
|
-
rejectOversized(new Error(
|
|
126
|
+
rejectOversized(new Error(`Request body exceeds ${limitName}`));
|
|
125
127
|
}
|
|
126
128
|
});
|
|
127
129
|
// Track every temp file formidable opens (via fileBegin, so a file that
|
|
@@ -131,6 +133,12 @@ class RequestParser extends AbstractMiddleware {
|
|
|
131
133
|
const openedFiles = [];
|
|
132
134
|
form.on('fileBegin', (_name, file) => {
|
|
133
135
|
openedFiles.push(file);
|
|
136
|
+
// Formidable handles a temp-file write error (disk full, missing
|
|
137
|
+
// uploadDir) for multipart parts only; for an octet-stream body it was
|
|
138
|
+
// an uncaught error that crashed the process. Fail the parse instead.
|
|
139
|
+
if (isOctetStream) {
|
|
140
|
+
file.on('error', (err) => form.emit('error', err));
|
|
141
|
+
}
|
|
134
142
|
});
|
|
135
143
|
let cleaned = false;
|
|
136
144
|
const cleanup = () => {
|
|
@@ -151,7 +159,7 @@ class RequestParser extends AbstractMiddleware {
|
|
|
151
159
|
// Pausing the stream cannot cancel a chunk already inside the parser.
|
|
152
160
|
// Even if that chunk completes parsing, an oversized body must not advance.
|
|
153
161
|
if (bodyTooLarge) {
|
|
154
|
-
throw new Error(
|
|
162
|
+
throw new Error(`Request body exceeds ${limitName}`);
|
|
155
163
|
}
|
|
156
164
|
}
|
|
157
165
|
catch (err) {
|
|
@@ -164,13 +172,12 @@ class RequestParser extends AbstractMiddleware {
|
|
|
164
172
|
// The rest of the body stays unread; close rather than drain it.
|
|
165
173
|
res.setHeader('Connection', 'close');
|
|
166
174
|
}
|
|
167
|
-
return
|
|
168
|
-
message: this.translate(req, 'middleware.requestParser.entityTooLarge', 'Request entity too large. Your upload exceeds the allowed size or count limits.'),
|
|
169
|
-
});
|
|
175
|
+
return next(this.#entityTooLarge(req));
|
|
170
176
|
}
|
|
171
|
-
return
|
|
177
|
+
return next(new HttpError(400, {
|
|
178
|
+
code: FRAMEWORK_ERROR_CODES.malformedBody,
|
|
172
179
|
message: this.translate(req, 'middleware.requestParser.parseError', `Error to parse your request. You provided invalid content type or content-length. Please check your request headers and content type.`),
|
|
173
|
-
});
|
|
180
|
+
}));
|
|
174
181
|
}
|
|
175
182
|
this.logger?.verbose(`Parsing multipart/formdata request DONE ${Date.now() - time}ms`);
|
|
176
183
|
// formidable wraps multipart/urlencoded fields in arrays (one entry per
|
|
@@ -186,6 +193,11 @@ class RequestParser extends AbstractMiddleware {
|
|
|
186
193
|
? [key, value[0]]
|
|
187
194
|
: [key, value]))
|
|
188
195
|
: fields;
|
|
196
|
+
// Formidable lists a field's files as their writes finish; keep the order
|
|
197
|
+
// they were sent, which is the order they began.
|
|
198
|
+
for (const list of Object.values(files)) {
|
|
199
|
+
list?.sort((a, b) => openedFiles.indexOf(a) - openedFiles.indexOf(b));
|
|
200
|
+
}
|
|
189
201
|
req.body = {
|
|
190
202
|
// todo avoid body in next versions
|
|
191
203
|
...(req.body || {}),
|
|
@@ -194,6 +206,12 @@ class RequestParser extends AbstractMiddleware {
|
|
|
194
206
|
};
|
|
195
207
|
return next();
|
|
196
208
|
}
|
|
209
|
+
#entityTooLarge(req) {
|
|
210
|
+
return new HttpError(413, {
|
|
211
|
+
code: FRAMEWORK_ERROR_CODES.payloadTooLarge,
|
|
212
|
+
message: this.translate(req, 'middleware.requestParser.entityTooLarge', 'Request entity too large. Your upload exceeds the allowed size or count limits.'),
|
|
213
|
+
});
|
|
214
|
+
}
|
|
197
215
|
}
|
|
198
216
|
export default RequestParser;
|
|
199
217
|
//# sourceMappingURL=RequestParser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestParser.js","sourceRoot":"","sources":["../../../../src/services/http/middleware/RequestParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,OAAO,UAAU,EAAE,EACjB,IAAI,EACJ,SAAS,EACT,WAAW,EACX,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErE,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AAKzD,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,kBAAkB,EAAE;IACrD,UAAU,EAAE;QACV,MAAM,EAAE,WAAW;QACnB,SAAS,EAAE,mCAAmC;KAC/C;CACO,CAAC;AAEX;;;GAGG;AACH,SAAS,cAAc,CACrB,SAAwB,EACxB,UAAmB;IAEnB,IAAI,CAAC,SAAS,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QACxE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,MAAe,CAAC;IACpB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACtD,IAAI,GAAG,CAAC,WAAW,EAAE,KAAK,SAAS,EAAE,CAAC;YACpC,MAAM,GAAG,KAAK,CAAC;QACjB,CAAC;IACH,CAAC;IACD,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC;QACrE,CAAC,CAAC,WAAW,CAAC,MAA2B,CAAC;QAC1C,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,SAAS,WAAW,CAClB,MAAiC,EACjC,SAAiB;IAEjB,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE;QACvB,MAAM,MAAM,GAAG,IAAmD,CAAC;QACnE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;QAC3B,MAAM,CAAC,OAAO,GAAG,EAAE,GAAG,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC;QAC3D,IAAI,CAAC;YACH,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACxB,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;QAC3B,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"RequestParser.js","sourceRoot":"","sources":["../../../../src/services/http/middleware/RequestParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,OAAO,UAAU,EAAE,EACjB,IAAI,EACJ,SAAS,EACT,WAAW,EACX,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErE,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AAKzD,MAAM,WAAW,GAAG;IAClB,IAAI,EAA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