Skip to content
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

CsrfMiddleware and CsrfAwareActionInterface #70

Closed
mj4444ru opened this issue Oct 13, 2020 · 5 comments
Closed

CsrfMiddleware and CsrfAwareActionInterface #70

mj4444ru opened this issue Oct 13, 2020 · 5 comments
Labels
status:ready for adoption Feel free to implement this issue.

Comments

@mj4444ru
Copy link

CsrfMiddleware is currently running for all requests. However, this functionality is sometimes not required, or a separate implementation is required for individual endpoints that process external requests as API.

Magento has a CsrfAwareActionInterface endpoint interface. If implemented, the endpoint checks the Csrf itself, otherwise the Csrf is checked by Magento. You need to do something like this.

@samdark
Copy link
Member

samdark commented Oct 14, 2020

That's already possible. Middleware could be used in three ways:

  1. Via main application stack.
  2. Via route group stack.
  3. Via individual route stack.

All these are configured at the application level. That's already in docs but will be even more visible after alpha release: https://github.com/yiisoft/docs/blob/master/guide/en/structure/middleware.md

@mj4444ru
Copy link
Author

It is clear that it is possible to add it. But I mean that it would be nice to be able to add the CsrfAwareActionInterface interface in the controller and not implement your own CsrfMiddleware. Now we have CsrfMiddleware whose area is very limited, and it is inconvenient to use it for separate routes. In case of difficulties, 99% of people will not write their own CsrfMiddleware, they will simply disable it.

@samdark
Copy link
Member

samdark commented Oct 15, 2020

Now we have CsrfMiddleware whose area is very limited

It's not. Exactly the same middleware could be registered for individual route or routes group.

it is inconvenient to use it for separate routes

What is inconvenient in the following?

Group::create('/user', [
  // routes here        
])->addMiddleware(\Yiisoft\Csrf\CsrfMiddleware::class),

@mj4444ru
Copy link
Author

mj4444ru commented Oct 16, 2020

What if third-party modules add routes for which Csrf is not needed? Will they have to ask the user to change their global configuration? Remove from the chain above CsrfMiddleware applications? I find it difficult.
I understand that you want to make it as simple as possible, but a step to the left, a step to the right, there are problems. This is not forward-looking.

PS: This is from experience. I had to solve a similar problem the other day in a commercial project.

@samdark samdark reopened this Oct 19, 2020
@samdark
Copy link
Member

samdark commented Oct 19, 2020

Alright. CSRF is likely worth to be moved to router level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready for adoption Feel free to implement this issue.
Projects
None yet
Development

No branches or pull requests

2 participants