Disabling CSRF guard for specific routes #665
Labels
performance
Framework performance issue
REST API
API standard
standards and best practices
Coding guidelines
Milestone
Sometimes, you need to exclude certain routes from CSRF checks. For example, routes that are meant to be consumed by another application instead of a browser (see #385, #521, #558, #568). It's also useful for things like raw asset loading, where you want to avoid initializing the CSRF middleware altogether, because it has a dependency on
session
- which in turn can cause too many read/write attempts in succession, as we saw with #633.One option is to disable global CSRF middleware, and instead require that each route explicitly declare the CSRF check as route middleware ("whitelist" approach). I'm not sure if this would still end up initializing the middleware on routes that don't actually use it.
Or, we can leave global CSRF middleware enabled, and then provide a means for routes to declare themselves exempt from CSRF checks ("blacklist" approach). Again, we'd want to check the blacklist before the middleware is even instantiated in the first place.
You can see how we're implementing blacklisting for asset routes right now:
So, maybe we could just go with a blacklist, and build a wrapper around it so that it doesn't have to do this in
index.php
?This is also related to #617.
The text was updated successfully, but these errors were encountered: