Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: explicit hook configuration via addHook #212

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Fdawgs
Copy link
Member

@Fdawgs Fdawgs commented Feb 4, 2025

Supersedes #207.

This PR updates the addHook option to allow the hook type to be explicitly configured to be either onRequest or preParsing.
The hooks are limited to these two values so that developers cannot open themselves up to DoS attacks.
If the option is nullish or true it defaults to onRequest, which is its original functionality.

Checklist

@Fdawgs Fdawgs changed the title feat: add hook option feat: add hook option Feb 4, 2025
@Fdawgs Fdawgs changed the title feat: add hook option feat: explicit hook configuration via addHook Feb 4, 2025
@Fdawgs Fdawgs requested a review from a team February 5, 2025 07:22
test/hooks.test.js Outdated Show resolved Hide resolved
test/hooks.test.js Outdated Show resolved Hide resolved
Fdawgs and others added 2 commits February 5, 2025 07:28
Co-authored-by: KaKa <[email protected]>
Signed-off-by: Frazer Smith <[email protected]>
Co-authored-by: KaKa <[email protected]>
Signed-off-by: Frazer Smith <[email protected]>
@Fdawgs Fdawgs requested a review from Copilot February 5, 2025 07:30
Readme.md Outdated Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

Readme.md:83

  • The addHook option description is duplicated. Please remove the redundant description.
* `addHook`: If `false`, this plugin will not register any hook automatically. Instead, it provides two decorations: `fastify.verifyBearerAuth` and `fastify.verifyBearerAuthFactory`. If `true` or nullish, it will default to `onRequest`. You can also specify `onRequest` or `preParsing` to register the respective hook

lib/errors.js:6

  • The error message for FST_BEARER_AUTH_INVALID_HOOK is clear and helpful.
const FST_BEARER_AUTH_INVALID_HOOK = createError('FST_BEARER_AUTH_INVALID_HOOK', 'options.addHook must be either "onRequest" or "preParsing"')
Readme.md Outdated Show resolved Hide resolved
Readme.md Outdated
Comment on lines 82 to 83
* `addHook`: If `false`, no hook is registered automatically, and instead the `fastify.verifyBearerAuth` and `fastify.verifyBearerAuthFactory` decorators are exposed.
If `true` or nullish, defaults to `onRequest`. `onRequest` or `preParsing` can also be used to register the respective hook
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This text does not make it clear to me that it accepts the strings "onRequest" and "preParsing" to specify the hook to be used. It wasn't until I was reviewing the code changes that I understood the selection is meant to be provided here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsumners Hopefully a bit clearer in 341250b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants