From ad93945ff294affc1171d4659be1e856a9b0e1f6 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sat, 13 Jan 2024 15:20:49 +0000 Subject: [PATCH 1/2] docs(readme): replace `fastify.io` links with `fastify.dev` Signed-off-by: Frazer Smith --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3fc0ba0..159352b 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ fastify.register(require('@fastify/auth'), { defaultRelation: 'and'} ) _For more examples, please check [`example-composited.js`](test/example-composited.js)_ -This plugin support `callback` and `Promise` returned by the functions. Note that an `async` function **does not have** to call the `done` parameter, otherwise the route handler to which the auth methods are linked to [might be called multiple times](https://www.fastify.io/docs/latest/Hooks/#respond-to-a-request-from-a-hook): +This plugin support `callback` and `Promise` returned by the functions. Note that an `async` function **does not have** to call the `done` parameter, otherwise the route handler to which the auth methods are linked to [might be called multiple times](https://www.fastify.dev/docs/latest/Hooks/#respond-to-a-request-from-a-hook): ```js fastify .decorate('asyncVerifyJWTandLevel', async function (request, reply) { @@ -190,7 +190,7 @@ The difference between the two approaches is that if you use the route level `pr ### `onRequest` vs. `preHandler` hook -The main difference between the `onRequest` and `preHandler` stages of the [Fastify Lifecycle](https://www.fastify.io/docs/latest/Reference/Lifecycle/) is that the body payload is not parsed in the `onRequest` stage. Parsing the body can be a potential security risk, as it can be used for denial of service (DoS) attacks. Therefore, it is recommended to avoid parsing the body for unauthorized access. +The main difference between the `onRequest` and `preHandler` stages of the [Fastify Lifecycle](https://www.fastify.dev/docs/latest/Reference/Lifecycle/) is that the body payload is not parsed in the `onRequest` stage. Parsing the body can be a potential security risk, as it can be used for denial of service (DoS) attacks. Therefore, it is recommended to avoid parsing the body for unauthorized access. Using the `@fastify/auth` plugin in the `preHandler` hook can result in unnecessary memory allocation if a malicious user sends a large payload in the request body and the request is unauthorized. In this case, Fastify will parse the body, even though the request is not authorized, leading to unnecessary memory allocation. To avoid this, it is recommended to use the `onRequest` hook for authentication, if the authentication method does not require the request body, such as `@fastify/jwt`, which expects the authentication in the request header. From 00650d4bb50077fb83e4ca6d79bcc8a3d4f2a8c8 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sat, 13 Jan 2024 15:40:34 +0000 Subject: [PATCH 2/2] Update README.md Co-authored-by: Aras Abbasi Signed-off-by: Frazer Smith --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 159352b..5364e54 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ fastify.register(require('@fastify/auth'), { defaultRelation: 'and'} ) _For more examples, please check [`example-composited.js`](test/example-composited.js)_ -This plugin support `callback` and `Promise` returned by the functions. Note that an `async` function **does not have** to call the `done` parameter, otherwise the route handler to which the auth methods are linked to [might be called multiple times](https://www.fastify.dev/docs/latest/Hooks/#respond-to-a-request-from-a-hook): +This plugin support `callback` and `Promise` returned by the functions. Note that an `async` function **does not have** to call the `done` parameter, otherwise the route handler to which the auth methods are linked to [might be called multiple times](https://fastify.dev/docs/latest/Reference/Hooks/#respond-to-a-request-from-a-hook): ```js fastify .decorate('asyncVerifyJWTandLevel', async function (request, reply) {