alado 3.2.3 → 3.5.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 +15 -6
- package/dist/alado-server/alado-server.js +4 -1
- package/dist/alado-server/alado-server.js.map +1 -1
- package/dist/constants/http-server.d.ts +1 -0
- package/dist/constants/http-server.js +2 -1
- package/dist/constants/http-server.js.map +1 -1
- package/dist/dto/property-definition.d.ts +1 -0
- package/dist/helpers/parser/access-control-checker.js +11 -3
- package/dist/helpers/parser/access-control-checker.js.map +1 -1
- package/dist/helpers/parser/body-parser.d.ts +14 -0
- package/dist/helpers/parser/body-parser.js +76 -17
- package/dist/helpers/parser/body-parser.js.map +1 -1
- package/dist/helpers/validate/alado-options/validate-alado-options.js +15 -0
- package/dist/helpers/validate/alado-options/validate-alado-options.js.map +1 -1
- package/dist/helpers/validate/built-in/validator.js +4 -1
- package/dist/helpers/validate/built-in/validator.js.map +1 -1
- package/dist/helpers/validate/context/file-signature.d.ts +5 -0
- package/dist/helpers/validate/context/file-signature.js +57 -0
- package/dist/helpers/validate/context/file-signature.js.map +1 -0
- package/dist/helpers/validate/context/validate-context.js +4 -1
- package/dist/helpers/validate/context/validate-context.js.map +1 -1
- package/dist/helpers/validate/context/validate-request-files.js +6 -1
- package/dist/helpers/validate/context/validate-request-files.js.map +1 -1
- package/dist/helpers/validate/context/validate-request-part.js +126 -49
- package/dist/helpers/validate/context/validate-request-part.js.map +1 -1
- package/dist/options/alado-server-options.d.ts +2 -0
- package/dist/options/request-processor-options.d.ts +1 -0
- package/dist/options/router-options.d.ts +1 -0
- package/dist/request-processor/request-processor.d.ts +14 -4
- package/dist/request-processor/request-processor.js +240 -88
- package/dist/request-processor/request-processor.js.map +1 -1
- package/dist/router/router.d.ts +14 -0
- package/dist/router/router.js +86 -13
- package/dist/router/router.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateRequestFiles = validateRequestFiles;
|
|
4
|
+
const file_signature_1 = require("./file-signature");
|
|
4
5
|
function validateRequestFiles(context, request) {
|
|
5
6
|
const { files } = context.request;
|
|
6
7
|
if (files) {
|
|
7
8
|
for (const file in files) {
|
|
8
|
-
const { required, mimetypes, maxSize, requiredError, maxSizeError, mimetypeError } = files[file];
|
|
9
|
+
const { required, mimetypes, maxSize, requiredError, maxSizeError, mimetypeError, verifyContent } = files[file];
|
|
9
10
|
if (required && (!request.files || !request.files[file])) {
|
|
10
11
|
return requiredError;
|
|
11
12
|
}
|
|
@@ -23,6 +24,10 @@ function validateRequestFiles(context, request) {
|
|
|
23
24
|
if (size > maxSize) {
|
|
24
25
|
return maxSizeError;
|
|
25
26
|
}
|
|
27
|
+
// the declared type is the client's word; the first bytes have to agree with it
|
|
28
|
+
if (verifyContent !== false && !(0, file_signature_1.matchesFileSignature)(mimetype, file_signature_1.uploadedFileHeads.get(uploaded))) {
|
|
29
|
+
return mimetypeError;
|
|
30
|
+
}
|
|
26
31
|
}
|
|
27
32
|
if (!context.options?.allowUnknownFields) {
|
|
28
33
|
for (const f in request.files) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-request-files.js","sourceRoot":"","sources":["../../../../src/helpers/validate/context/validate-request-files.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"validate-request-files.js","sourceRoot":"","sources":["../../../../src/helpers/validate/context/validate-request-files.ts"],"names":[],"mappings":";;AAGA,oDAqCC;AAvCD,qDAA2E;AAE3E,SAAgB,oBAAoB,CAAC,OAAqB,EAAE,OAAY;IACtE,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAClC,IAAI,KAAK,EAAE,CAAC;QACV,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,EA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
|
|
@@ -1,76 +1,153 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateRequestPart = validateRequestPart;
|
|
4
|
-
const nonProcessingRequestParts = [
|
|
4
|
+
const nonProcessingRequestParts = new Set([
|
|
5
5
|
'files',
|
|
6
6
|
'auth',
|
|
7
|
-
];
|
|
7
|
+
]);
|
|
8
|
+
// parts that keep undeclared fields even when allowUnknownFields is off
|
|
9
|
+
const openRequestParts = new Set([
|
|
10
|
+
'headers',
|
|
11
|
+
'rawBody',
|
|
12
|
+
]);
|
|
13
|
+
const hasOwn = (target, property) => target !== null && target !== undefined && Object.prototype.hasOwnProperty.call(target, property);
|
|
14
|
+
function isThenable(value) {
|
|
15
|
+
return value !== null && typeof value === 'object' && typeof value.then === 'function';
|
|
16
|
+
}
|
|
8
17
|
function validateRequestPart(key, context, request) {
|
|
9
|
-
if (nonProcessingRequestParts.
|
|
18
|
+
if (nonProcessingRequestParts.has(key)) {
|
|
10
19
|
return;
|
|
11
20
|
}
|
|
12
|
-
const definitions = context?.request[key]
|
|
13
|
-
if (!Object.keys(definitions).length &&
|
|
14
|
-
!context.options?.allowUnknownFields &&
|
|
15
|
-
![
|
|
16
|
-
'headers',
|
|
17
|
-
'rawBody',
|
|
18
|
-
].includes(key)) {
|
|
19
|
-
request[key] = {};
|
|
20
|
-
}
|
|
21
|
+
const definitions = context?.request[key];
|
|
21
22
|
let hasDefinitions = false;
|
|
22
|
-
for (const _ in
|
|
23
|
+
for (const _ in definitions) {
|
|
23
24
|
hasDefinitions = true;
|
|
24
25
|
break;
|
|
25
26
|
}
|
|
26
27
|
if (!hasDefinitions) {
|
|
28
|
+
if (!context.options?.allowUnknownFields && !openRequestParts.has(key)) {
|
|
29
|
+
request[key] = {};
|
|
30
|
+
}
|
|
27
31
|
return;
|
|
28
32
|
}
|
|
29
33
|
return validateDeclaredProperties(key, context, request);
|
|
30
34
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Validates one declared property. Runs synchronously and only returns a Promise
|
|
37
|
+
* when the validation handler or the transform does, so plain validators cost no microtasks.
|
|
38
|
+
*/
|
|
39
|
+
function validateProperty(key, property, definition, request) {
|
|
40
|
+
const { validation, transform, isJSON } = definition;
|
|
41
|
+
const { required, handler, error } = validation;
|
|
42
|
+
const part = request[key];
|
|
43
|
+
const present = hasOwn(part, property);
|
|
44
|
+
if (required && !present) {
|
|
45
|
+
return error;
|
|
46
|
+
}
|
|
47
|
+
if (!handler || !present) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
let value = part[property];
|
|
51
|
+
if (isJSON && typeof value === 'string') {
|
|
52
|
+
try {
|
|
53
|
+
value = JSON.parse(value);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// keep the raw string
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// the configured error, never the exception text (it may describe internals)
|
|
60
|
+
const fail = () => error;
|
|
61
|
+
const applyTransform = () => {
|
|
62
|
+
if (!transform) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const transformed = transform.apply(request, [value]);
|
|
66
|
+
if (isThenable(transformed)) {
|
|
67
|
+
return Promise.resolve(transformed).then((v) => {
|
|
68
|
+
request[key][property] = v;
|
|
69
|
+
return undefined;
|
|
70
|
+
}, fail);
|
|
71
|
+
}
|
|
72
|
+
request[key][property] = transformed;
|
|
73
|
+
};
|
|
74
|
+
try {
|
|
75
|
+
const isValid = handler.apply(request, [value]);
|
|
76
|
+
if (isThenable(isValid)) {
|
|
77
|
+
// a rejection or a throwing transform both end up as the configured error
|
|
78
|
+
return Promise.resolve(isValid)
|
|
79
|
+
.then((ok) => (ok ? applyTransform() : error))
|
|
80
|
+
.then(undefined, fail);
|
|
81
|
+
}
|
|
82
|
+
if (!isValid) {
|
|
36
83
|
return error;
|
|
37
84
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
85
|
+
return applyTransform();
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function stripUnknownFields(key, context, request) {
|
|
92
|
+
if (context.options?.allowUnknownFields || openRequestParts.has(key)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const definitions = context.request[key];
|
|
96
|
+
const part = request[key];
|
|
97
|
+
if (part !== null && typeof part === 'object' && !Array.isArray(part) && definitions) {
|
|
98
|
+
// copy instead of `delete`: deleting keys turns the object into a slow dictionary-mode
|
|
99
|
+
// object, which the handler and JSON.stringify then pay for
|
|
100
|
+
let unknown = false;
|
|
101
|
+
for (const prop in part) {
|
|
102
|
+
if (!Object.prototype.hasOwnProperty.call(definitions, prop)) {
|
|
103
|
+
unknown = true;
|
|
104
|
+
break;
|
|
57
105
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
106
|
+
}
|
|
107
|
+
if (unknown) {
|
|
108
|
+
const known = {};
|
|
109
|
+
for (const prop in part) {
|
|
110
|
+
if (Object.prototype.hasOwnProperty.call(definitions, prop)) {
|
|
111
|
+
known[prop] = part[prop];
|
|
112
|
+
}
|
|
61
113
|
}
|
|
114
|
+
request[key] = known;
|
|
62
115
|
}
|
|
116
|
+
return;
|
|
63
117
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
118
|
+
for (const prop in request[key]) {
|
|
119
|
+
if (!definitions || !Object.prototype.hasOwnProperty.call(definitions, prop)) {
|
|
120
|
+
delete request[key][prop];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async function finishAsync(key, context, request, properties, index, pending) {
|
|
125
|
+
let error = await pending;
|
|
126
|
+
if (error) {
|
|
127
|
+
return error;
|
|
128
|
+
}
|
|
129
|
+
for (let i = index + 1; i < properties.length; i++) {
|
|
130
|
+
const property = properties[i];
|
|
131
|
+
error = await validateProperty(key, property, context.request[key][property], request);
|
|
132
|
+
if (error) {
|
|
133
|
+
return error;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
stripUnknownFields(key, context, request);
|
|
137
|
+
}
|
|
138
|
+
function validateDeclaredProperties(key, context, request) {
|
|
139
|
+
const definitions = context.request[key];
|
|
140
|
+
const properties = Object.keys(definitions);
|
|
141
|
+
for (let i = 0; i < properties.length; i++) {
|
|
142
|
+
const property = properties[i];
|
|
143
|
+
const result = validateProperty(key, property, definitions[property], request);
|
|
144
|
+
if (isThenable(result)) {
|
|
145
|
+
return finishAsync(key, context, request, properties, i, result);
|
|
146
|
+
}
|
|
147
|
+
if (result) {
|
|
148
|
+
return result;
|
|
73
149
|
}
|
|
74
150
|
}
|
|
151
|
+
stripUnknownFields(key, context, request);
|
|
75
152
|
}
|
|
76
153
|
//# sourceMappingURL=validate-request-part.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-request-part.js","sourceRoot":"","sources":["../../../../src/helpers/validate/context/validate-request-part.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"validate-request-part.js","sourceRoot":"","sources":["../../../../src/helpers/validate/context/validate-request-part.ts"],"names":[],"mappings":";;AAqBA,kDAqBC;AAxCD,MAAM,yBAAyB,GAAgB,IAAI,GAAG,CAAC;IACrD,OAAO;IACP,MAAM;CACP,CAAC,CAAC;AACH,wEAAwE;AACxE,MAAM,gBAAgB,GAAgB,IAAI,GAAG,CAAC;IAC5C,SAAS;IACT,SAAS;CACV,CAAC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KAAK,EAAE,CAAC;YACV,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,kBAAkB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,0BAA0B,CACjC,GAAyB,EACzB,OAAqB,EACrB,OAAY;IAEZ,MAAM,WAAW,GAAQ,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC9C,MAAM,UAAU,GAAa,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACtD,KAAK,IAAI,CAAC,GAAW,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACnD,MAAM,QAAQ,GAAW,UAAU,CAAC,CAAC,CAAC,CAAC;QACvC,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,EAAE,QAAQ,EAAE,WAAW,CAAC,QAAQ,CAAuB,EAAE,OAAO,CAAC,CAAC;QACrG,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YACvB,OAAO,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,MAAmC,CAAC,CAAC;QAChG,CAAC;QACD,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC;IACD,kBAAkB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -2,11 +2,15 @@ import { IncomingMessage, ServerResponse } from 'http';
|
|
|
2
2
|
import { RequestProcessorOptions } from '../options/index.js';
|
|
3
3
|
import { AladoServerError, Response } from '../dto/index.js';
|
|
4
4
|
/**
|
|
5
|
-
* Maps a request
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Maps a request path (already through clearRoutePath, query string removed) to a Swagger UI
|
|
6
|
+
* file name, or undefined if it is not one. Files are only served under the docs route; the docs
|
|
7
|
+
* page sets <base href="<route>/"> so its relative asset URLs resolve there. Only a docs route of
|
|
8
|
+
* "/" serves files from the root. The result is always an exact entry of the swagger-ui-dist
|
|
9
|
+
* listing, so no part of the URL ever reaches the filesystem (no `..`, no subdirectories).
|
|
8
10
|
*/
|
|
9
|
-
export declare function resolveSwaggerUiFile(
|
|
11
|
+
export declare function resolveSwaggerUiFile(pathname: string, docsRoute: string): string | undefined;
|
|
12
|
+
/** Swagger UI's index.html, with a <base> so its relative asset URLs stay under the docs route. */
|
|
13
|
+
export declare function swaggerIndexHtml(html: string, docsRoute: string): string;
|
|
10
14
|
/**
|
|
11
15
|
* Errors that carry an HTTP status (thrown on purpose, e.g. `{ statusCode: 404,
|
|
12
16
|
* message }`, or produced by the body parser) keep their status and message.
|
|
@@ -14,11 +18,17 @@ export declare function resolveSwaggerUiFile(url: string, docsRoute: string): st
|
|
|
14
18
|
* details only go to the logger.
|
|
15
19
|
*/
|
|
16
20
|
export declare function toClientError(e: any): AladoServerError;
|
|
21
|
+
export declare function clientIp(req: IncomingMessage, trustProxy?: boolean | number): string;
|
|
17
22
|
export declare class RequestProcessor {
|
|
18
23
|
private readonly options;
|
|
24
|
+
private swaggerIndex;
|
|
25
|
+
private swaggerInitializer;
|
|
26
|
+
private corsStatic?;
|
|
27
|
+
private corsMethods;
|
|
19
28
|
constructor(requestProcessorOptions: RequestProcessorOptions);
|
|
20
29
|
protected respond(res: ServerResponse, response: Response<any>, backgroundHeaders?: Record<string, string>): void;
|
|
21
30
|
protected respondError(res: ServerResponse, error: AladoServerError, headers?: Record<string, string>): void;
|
|
22
31
|
process(req: IncomingMessage, res: ServerResponse): Promise<void>;
|
|
32
|
+
protected corsHeaders(allowedMethods: string[] | undefined, origin: string): Record<string, string>;
|
|
23
33
|
protected logError(e: Error): void;
|
|
24
34
|
}
|