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

Merged
merged 7 commits into from
Feb 9, 2025
Merged

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 <23028015+climba03003@users.noreply.github.com>
Signed-off-by: Frazer Smith <frazer.dev@icloud.com>
Co-authored-by: KaKa <23028015+climba03003@users.noreply.github.com>
Signed-off-by: Frazer Smith <frazer.dev@icloud.com>
@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 Show resolved Hide resolved
Copy link
Member

@gurgunday gurgunday left a comment

Choose a reason for hiding this comment

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

Lgtm

@Fdawgs Fdawgs merged commit 9052d77 into main Feb 9, 2025
13 checks passed
@Fdawgs Fdawgs deleted the feat/config-hook branch February 9, 2025 17:10
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.

4 participants