-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
3.0 - adding error callback to CsrfComponent #6546
Comments
The csrf check does not rely on the session |
My bad. But it does rely on a cookie right? A cookie that can also expire. |
The cookie will live for as long as you have the browser open |
Unless you switch to privacy mode. Or if you delete them. Ok that's tricky situations, but I trust my users to find many more of them :D In cakephp 2 it was possible to capture csrf errors with the blackhole method. Not in cakephp 3. Don't you think that's a regression? Is there a reason why SecurityComponent would have such a feature and not the Csrf one? |
I just think adding the callback would be misleading.
|
I don't see the lack of a callback as a regression as the current CSRF implemenatation is totally separate and distinct from the previous one. Would having a specific exception class help? That way you could render a different error template for CSRF errors which sounds like what you need if I'm understanding things correctly. |
In cakephp 2, we could define a blackhole method as this:
$type being one of these strings: 'auth', 'csrf', 'secure', ... So in case of csrf error, it was possible to tell the user something like "please make sure you have cookies enabled or reload the page to refresh session/cookie and try again" instead of just throwing a 400 error. In cakephp 3, I don't see how to do the same thing. Here is why I think this is a regression. Maybe adding a "blackhole-like" callback is not a good option. If you guys prefer using a specific exception class, it'll be good too, as long as I can render a different error template for CSRF errors as you said @markstory . |
btw, I can work on this if you agree with this feature. |
I think specific exceptions is a better way to handle these kinds of situations going forward. Exceptions can be easily converted into error pages, or responses, or caught by controller hook methods like |
I think a custom exception is the way to go |
Fixed with #6620 |
Added InvalidCsrfTokenException. Implements #6546
* origin/3.1: (305 commits) Update version number to 3.0.6 New mock objects version causes our test suites to fail. Update FloatType.php Update DateTimeType.php Updated docBlock Fix empty query expressions for generating invalid SQL. Add tests for empty expression objects in association conditions. Add option to disable local XML file parsing. Port the Inflector fixes from #6635 to 3.0 Fix typo in error template file name. Add test for ProgressHelper output with options. Add missing doc blcoks. Fix getOriginal() not preserving nulls. Fix incorrect doc blocks and PHPCS. Fixed @SInCE in QueryExpressionTest Added __call() on QueryExpression to allow for and() and or() to be called transparently. Implements #6477 Added default message for InvalidCsrfTokenException Updated thrown exception messages to be more descriptive of the cause replace DS with DIRECTORY_SEPARATOR in filesystem sub-package Added InvalidCsrfTokenException. Implements #6546 Use ProgressHelper in i18n task. ...
In cakephp 2, it was possible to handle Csrf errors with a blackhole method. In cakephp 3, Csrf handling was moved out from SecurityComponent to CsrfComponent, but the CsrfComponent does not offer the option to choose how to handle csrf errors (no blackhole callback).
I'm asking this cause most of the time, csrf errors are caused by session expiration rather than hack attempt. I think it would be nice to be able to tell the user "sorry, your session has expired" instead of throwing a 403 error.
What do you think?
The text was updated successfully, but these errors were encountered: