fastify 3.22.1 → 3.23.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/build/build-validation.js +2 -0
- package/docs/Server.md +13 -1
- package/docs/Validation-and-Serialization.md +9 -1
- package/fastify.d.ts +2 -0
- package/fastify.js +1 -0
- package/lib/configValidator.js +455 -423
- package/lib/request.js +9 -3
- package/lib/server.js +1 -0
- package/package.json +2 -2
- package/test/bundler/README.md +7 -7
- package/test/internals/initialConfig.test.js +2 -0
- package/test/internals/request.test.js +47 -0
- package/test/requestTimeout.test.js +50 -0
- package/test/types/content-type-parser.test-d.ts +1 -1
- package/test/types/instance.test-d.ts +1 -1
- package/test/types/logger.test-d.ts +1 -1
|
@@ -16,6 +16,7 @@ const defaultInitOptions = {
|
|
|
16
16
|
connectionTimeout: 0, // 0 sec
|
|
17
17
|
keepAliveTimeout: 5000, // 5 sec
|
|
18
18
|
maxRequestsPerSocket: 0, // no limit
|
|
19
|
+
requestTimeout: 0, // no limit
|
|
19
20
|
bodyLimit: 1024 * 1024, // 1 MiB
|
|
20
21
|
caseSensitive: true,
|
|
21
22
|
disableRequestLogging: false,
|
|
@@ -49,6 +50,7 @@ const schema = {
|
|
|
49
50
|
connectionTimeout: { type: 'integer', default: defaultInitOptions.connectionTimeout },
|
|
50
51
|
keepAliveTimeout: { type: 'integer', default: defaultInitOptions.keepAliveTimeout },
|
|
51
52
|
maxRequestsPerSocket: { type: 'integer', default: defaultInitOptions.maxRequestsPerSocket, nullable: true },
|
|
53
|
+
requestTimeout: { type: 'integer', default: defaultInitOptions.requestTimeout },
|
|
52
54
|
bodyLimit: { type: 'integer', default: defaultInitOptions.bodyLimit },
|
|
53
55
|
caseSensitive: { type: 'boolean', default: defaultInitOptions.caseSensitive },
|
|
54
56
|
http2: { type: 'boolean' },
|
package/docs/Server.md
CHANGED
|
@@ -13,6 +13,7 @@ document describes the properties available in that options object.
|
|
|
13
13
|
- [connectionTimeout](./Server.md#connectiontimeout)
|
|
14
14
|
- [keepAliveTimeout](./Server.md#keepalivetimeout)
|
|
15
15
|
- [maxRequestsPerSocket](./Server.md#maxRequestsPerSocket)
|
|
16
|
+
- [requestTimeout](./Server.md#requestTimeout)
|
|
16
17
|
- [ignoreTrailingSlash](./Server.md#ignoretrailingslash)
|
|
17
18
|
- [maxParamLength](./Server.md#maxparamlength)
|
|
18
19
|
- [onProtoPoisoning](./Server.md#onprotopoisoning)
|
|
@@ -94,6 +95,17 @@ is in use. Also, when `serverFactory` option is specified, this option is ignore
|
|
|
94
95
|
|
|
95
96
|
+ Default: `0` (no limit)
|
|
96
97
|
|
|
98
|
+
<a name="factory-request-timeout"></a>
|
|
99
|
+
### `requestTimeout`
|
|
100
|
+
|
|
101
|
+
Defines the maximum number of milliseconds for receiving the entire request from the client.
|
|
102
|
+
[`server.requestTimeout` property](https://nodejs.org/dist/latest/docs/api/http.html#http_server_requesttimeout)
|
|
103
|
+
to understand the effect of this option. Also, when `serverFactory` option is specified, this option is ignored.
|
|
104
|
+
It must be set to a non-zero value (e.g. 120 seconds) to protect against potential Denial-of-Service attacks in case the server is deployed without a reverse proxy in front.
|
|
105
|
+
> At the time of this writing, only node version greater or equal to 14.11.0 support this option. Check the Node.js documentation for availability in the version you are running.
|
|
106
|
+
|
|
107
|
+
+ Default: `0` (no limit)
|
|
108
|
+
|
|
97
109
|
<a name="factory-ignore-slash"></a>
|
|
98
110
|
### `ignoreTrailingSlash`
|
|
99
111
|
|
|
@@ -480,7 +492,7 @@ Configure the Ajv v6 instance used by Fastify without providing a custom one.
|
|
|
480
492
|
const fastify = require('fastify')({
|
|
481
493
|
ajv: {
|
|
482
494
|
customOptions: {
|
|
483
|
-
nullable: false // Refer to [ajv options](https://ajv
|
|
495
|
+
nullable: false // Refer to [ajv options](https://github.com/ajv-validator/ajv/tree/v6#options)
|
|
484
496
|
},
|
|
485
497
|
plugins: [
|
|
486
498
|
require('ajv-merge-patch'),
|
|
@@ -10,6 +10,10 @@ Fastify uses a schema-based approach, and even if it is not mandatory we recomme
|
|
|
10
10
|
> user-provided schemas. See [Ajv](https://npm.im/ajv) and
|
|
11
11
|
> [fast-json-stringify](https://npm.im/fast-json-stringify) for more
|
|
12
12
|
> details.
|
|
13
|
+
>
|
|
14
|
+
> Moreover, the [`$async` Ajv feature](https://ajv.js.org/guide/async-validation.html) should not be used as part of the first validation strategy.
|
|
15
|
+
> This option is used to access Databases and reading them during the validation process may lead to Denial of Service Attacks to your
|
|
16
|
+
> application. If you need to run `async` tasks, use [Fastify's hooks](./Hooks.md) instead after validation completes, such as `preHandler`.
|
|
13
17
|
|
|
14
18
|
|
|
15
19
|
### Core concepts
|
|
@@ -642,6 +646,7 @@ fastify.setErrorHandler(function (error, request, reply) {
|
|
|
642
646
|
```
|
|
643
647
|
|
|
644
648
|
If you want custom error response in schema without headaches and quickly, you can take a look at [`ajv-errors`](https://github.com/epoberezkin/ajv-errors). Check out the [example](https://github.com/fastify/example/blob/HEAD/validation-messages/custom-errors-messages.js) usage.
|
|
649
|
+
> Make sure to install version 1.0.1 of `ajv-errors`, because later versions of it are not compatible with AJV v6 (the version shipped by Fastify v3).
|
|
645
650
|
|
|
646
651
|
Below is an example showing how to add **custom error messages for each property** of a schema by supplying custom AJV options.
|
|
647
652
|
Inline comments in the schema below describe how to configure it to show a different error message for each case:
|
|
@@ -649,7 +654,10 @@ Inline comments in the schema below describe how to configure it to show a diffe
|
|
|
649
654
|
```js
|
|
650
655
|
const fastify = Fastify({
|
|
651
656
|
ajv: {
|
|
652
|
-
customOptions: {
|
|
657
|
+
customOptions: {
|
|
658
|
+
jsonPointers: true,
|
|
659
|
+
allErrors: true // Warning: Enabling this option may lead to this security issue https://www.cvedetails.com/cve/CVE-2020-8192/
|
|
660
|
+
},
|
|
653
661
|
plugins: [
|
|
654
662
|
require('ajv-errors')
|
|
655
663
|
]
|
package/fastify.d.ts
CHANGED
|
@@ -97,6 +97,8 @@ export type FastifyServerOptions<
|
|
|
97
97
|
ignoreTrailingSlash?: boolean,
|
|
98
98
|
connectionTimeout?: number,
|
|
99
99
|
keepAliveTimeout?: number,
|
|
100
|
+
maxRequestsPerSocket?: number,
|
|
101
|
+
requestTimeout?: number,
|
|
100
102
|
pluginTimeout?: number,
|
|
101
103
|
bodyLimit?: number,
|
|
102
104
|
maxParamLength?: number,
|
package/fastify.js
CHANGED
|
@@ -133,6 +133,7 @@ function fastify (options) {
|
|
|
133
133
|
options.connectionTimeout = options.connectionTimeout || defaultInitOptions.connectionTimeout
|
|
134
134
|
options.keepAliveTimeout = options.keepAliveTimeout || defaultInitOptions.keepAliveTimeout
|
|
135
135
|
options.maxRequestsPerSocket = options.maxRequestsPerSocket || defaultInitOptions.maxRequestsPerSocket
|
|
136
|
+
options.requestTimeout = options.requestTimeout || defaultInitOptions.requestTimeout
|
|
136
137
|
options.logger = logger
|
|
137
138
|
options.genReqId = genReqId
|
|
138
139
|
options.requestIdHeader = requestIdHeader
|