-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
fix(index): add preHandler
hook
#207
Conversation
Signed-off-by: Frazer Smith <frazer.dev@icloud.com>
preHandler
hookpreHandler
hook
@@ -27,7 +27,7 @@ function fastifyBearerAuth (fastify, options, done) { | |||
|
|||
try { | |||
if (options.addHook === true) { | |||
fastify.addHook('onRequest', verifyBearerAuthFactory(options)) | |||
fastify.addHook('preHandler', verifyBearerAuthFactory(options)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not preValidation or preParsing for instance? We shouldn't validate anything if the auth isn't there in my opinion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That also works, was just updating the handler to correctly match the documentation. Can be changed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah sure, I was just pointing it out :)
In any case, this would be a major right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change it to preParsing if we're going to release a major?
I think that would be best. I've just rejigged |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would update the document and make the hook configurable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I do agree that this would be a major, I think the onRequest
hook seems right to me.
Whenever we get a request, we want to ensure that it is a valid client to call us.
Example: I have an endpoint with auth configured, if I get a malicious payload of 1GB, with this change we will parse it!
So, reading the issue:
I noticed this as I was registering @fastify/bearer-auth before @fastify/cors (which is an onRequest hook) and pre-flight requests were being caught by this plugin, and auth shouldn't be applied to them.
Isn't switching the cors/auth plugins the solution?
Or at most: fix the documentation
I'm leaning more to making it configurable as climba suggested. Both |
Seems fair. Make it configurable but default to |
The documentation states that this plugin adds a
preHandler
hook but the code says otherwise.I noticed this as I was registering
@fastify/bearer-auth
before@fastify/cors
(which is anonRequest
hook) and pre-flight requests were being caught by this plugin, and auth shouldn't be applied to them.Checklist
npm run test
andnpm run benchmark
and the Code of conduct