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

[RFC][Security] Reduce authentication usage "magic"? #45827

Open
wouterj opened this issue Mar 23, 2022 · 5 comments
Open

[RFC][Security] Reduce authentication usage "magic"? #45827

wouterj opened this issue Mar 23, 2022 · 5 comments
Labels
RFC Security

Comments

@wouterj
Copy link
Member

@wouterj wouterj commented Mar 23, 2022

Description

Source: https://twitter.com/matthiasnoback/status/1503652556186206211 by @matthiasnoback

I think it's interesting to see if and how we can reduce the magic (i.e. remove it or make it more obvious by providing helper classes/methods?)

  • As a developer you wouldn't expect to have to deal with expressions. It's easy to get a disconnect between the actual controllers, their routing paths, and the regular expressions in the firewall. It's also very easy to break things: when you change a routing path, you can accidentally move a controller outside the firewall, making it unprotected or broken because it relies on a logged in user to be available. Instead, you'd expect to be able to mark controllers, not request URI patterns to be behind a firewall. That way, if you change the routing path, the controller still remains behind the controller.
  • The template gets access to the authentication exception itself and the docs say, don't show getMessage(), use getMessageKey(). It would be better to pass some other type of object to the template/controller; one that only has the getMessageKey() method.
  • Other aspects you wouldn't expect are a login controller that only shows the login form (login happens in a kernel event subscriber), and a logout controller that doesn't do anything.

Example

No response

@carsonbot carsonbot added RFC Security labels Mar 23, 2022
@wouterj wouterj changed the title [RFC][Security] Can we reduce the "magic"? [RFC][Security] Reduce authentication usage "magic" Mar 23, 2022
@wouterj wouterj changed the title [RFC][Security] Reduce authentication usage "magic" [RFC][Security] Reduce authentication usage "magic"? Mar 23, 2022
@ro0NL
Copy link
Contributor

@ro0NL ro0NL commented Mar 23, 2022

ref #20257

@wouterj
Copy link
Member Author

@wouterj wouterj commented Mar 23, 2022

I think for the firewall, defining an application wide regex also has a major advantage of making sure certain sections are secured (e.g. by relying only on controller based config, you need to remember to add it to new controllers). Maybe we can use attributes more as a "sanity check": e.g. check whether all #[Secured] controllers are within a firewall during compilation?

@stof
Copy link
Member

@stof stof commented Mar 23, 2022

  • and a logout controller that doesn't do anything.

technically, you don't need a logout controller at all. you need a logout route (so that the router does not return a 404 when reaching that URL). The logout controller associated to that route is never executed as the firewall generates a response early when handling the logout. The only benefit of that logout controller is that it allows you to keep using annotations or attributes to define the route (by design, those formats cannot define a route without an associated controller)

@stof
Copy link
Member

@stof stof commented Mar 23, 2022

And about defining access control rules for controllers, I think this is mostly about moving #[IsGranted] from SensioFrameworkExtraBundle to the core

@ro0NL
Copy link
Contributor

@ro0NL ro0NL commented Mar 24, 2022

#[IsGranted] is out of scope when mounting vendor controllers btw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Security
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants