go-jwt-middleware icon indicating copy to clipboard operation
go-jwt-middleware copied to clipboard

Missing cookie causes CookieTokenExtractor to return error

Open simonrobb opened this issue 2 years ago • 5 comments

Describe the problem

I'm using the CookieTokenExtractor and when the named cookie is not present in the request, the following error is returned: error extracting token: http: named cookie not present.

The Cookie method on http.Request returns a ErrNoCookie error when the cookie doesn't exist, and that result is being directly returned by the extractor code.

What was the expected behavior?

I would expect that when the named cookie isn't present, the extractor returns no error (and an empty token). This would put its behaviour in line with the AuthHeaderTokenExtractor.

Reproduction

  1. Use the CookieTokenExtractor, and don't pass a cookie with the provided name.
  2. Check the error returned to the errorHandler.

Environment

go-jwt-middleware v2.0.1

simonrobb avatar Oct 06 '22 04:10 simonrobb

Suggested fix in this commit: https://github.com/auth0/go-jwt-middleware/commit/451a80238baa51c6bb83085da763a6f160402f26

simonrobb avatar Oct 06 '22 05:10 simonrobb

Any comment on this proposal?

This comment in middleware.go further suggests this is not the expected behavior: https://github.com/auth0/go-jwt-middleware/blob/master/middleware.go#L61.

simonrobb avatar Oct 21 '22 06:10 simonrobb

Hey @simonrobb 👋🏻 apologies for the delay in getting back to you. I'll have some time to take a look at this next week.

sergiught avatar Oct 26 '22 08:10 sergiught

Hey @simonrobb I was able to fix this in https://github.com/auth0/go-jwt-middleware/pull/172/ and it will be available in the next release. Before cutting it, I wanna tackle a few more issues and improvements, so stay tuned!

Thanks again for raising this!

I'll close this down once we make the release.

sergiught avatar Oct 27 '22 16:10 sergiught

Thanks @sergiught, that's great to hear!

simonrobb avatar Oct 28 '22 04:10 simonrobb

Hey @simonrobb 👋🏻 this is now available within https://github.com/auth0/go-jwt-middleware/releases/tag/v2.1.0. Thanks for your patience!

sergiught avatar Nov 02 '22 13:11 sergiught

Great work @sergiught, thank you!

simonrobb avatar Nov 03 '22 05:11 simonrobb