-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
Missing CSRF token makes params invalid in test #228
Comments
@kukicola Hey, thanks for reporting. Are you using |
@jodosha in Hanami app |
@kukicola, can you paste here the parameters that you're receiving? |
I created a sample app https://github.com/kukicola/hanami-csrf-example with two simple forms ( So that's a bit confusing to me that hanami validates csrf param by default. |
It allows to let that param always be accepted. The alternative would be that each form will need the validation param counterpart. We wanted to avoid this friction. |
@kukicola I had a look at this problem. It's a regression from 1.0. Hanami shouldn't validate CSRF Token in test env. |
Hello
In tests, CSRF token isn't set (and it's expected behavior) but calling
request.params.valid?
will returnfalse
because param is blank (even if my params validation rules don't include_csrf_token
field):I believe it's caused by:
https://github.com/hanami/controller/blob/main/lib/hanami/action/params.rb#L116
or
https://github.com/hanami/validations/blob/main/lib/hanami/validations/form.rb#L14
To fix it, I could remove input with CSRF token in views in test env or include middleware:
I think that in test env this default param validation should be removed
The text was updated successfully, but these errors were encountered: