gorilla/csrf

[bug] Not providing token results in wrong error

FlorianLoch opened this issue · 1 comments

Describe the bug
Not providing any token with a request results in ErrBadToken being given to the error handler. While technically not being wrong that really is not what to be expected when there is an ErrNoToken (which actually never gets returned, see below). It would have saved myself quite some hours of debugging knowing the token did not make it to the backend due to some nginx setting discarding headers with non-compliant names instead of assuming the token is invalid (due to whatever reason).

While being at the code I realised that the only time ErrNoToken being used in the code so far never gets executed (if I did not miss something massively) due to a condition never becoming true.

I want to furthermore annotate that no token being in the session store does not report a clear error. I consider this subpar but fixing it would be a little more invasive (introducing a new error to the API) and would probably require some discussion first.

Versions
Happens with current version as of creating this issue.

Steps to Reproduce
Simply omit the token in a request and investigate the error given to the registered errorHandler resp. look at the HTTP response. You might also have a look at the test case I added.

Code Snippets
I already made a PR (sorry for that, I wanted to verify my concerns first and was not aware of how things get handled in this repo: #149)

stale commented

This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days.