Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Security] Add a method in the security helper to ease programmatic logout #41406

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

Merged
merged 3 commits into from
Jul 20, 2022

Conversation

johnkrovitch
Copy link
Contributor

@johnkrovitch johnkrovitch commented May 25, 2021

Q A
Branch? 6.x
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #40663
License MIT
Doc PR

This PR aims to ease the programmatic login using the Security helper, to fix (#40663).

A simple method has been added to the Security helper.

Thanks !

@johnkrovitch johnkrovitch force-pushed the feature/auto-logout branch from 1c11464 to 0b8ee6f Compare May 26, 2021 07:34
@nicolas-grekas nicolas-grekas added this to the 5.4 milestone May 26, 2021
@johnkrovitch johnkrovitch force-pushed the feature/auto-logout branch 2 times, most recently from c4646e3 to 23aad7b Compare May 31, 2021 09:36
Copy link
Member

@Seldaek Seldaek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! There are a few points which IMO need some work still

@wouterj wouterj modified the milestones: 5.4, 6.1 Nov 4, 2021
@johnkrovitch
Copy link
Contributor Author

Thanks for your returns, I'm working on it.

@johnkrovitch johnkrovitch force-pushed the feature/auto-logout branch 9 times, most recently from e824ed6 to c135401 Compare December 2, 2021 14:53
Copy link
Member

@wouterj wouterj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi there! Thanks for updating this PR :)

I've left some final improvements. Some of them a bit tricky, so feel free to leave a comment asking for help if you don't understand how to apply them :)

@johnkrovitch johnkrovitch force-pushed the feature/auto-logout branch 5 times, most recently from 94c7372 to 5d42598 Compare December 2, 2021 15:47
@Seldaek
Copy link
Member

Seldaek commented Jul 12, 2022

I wonder if there should be a way to bypass CSRF? One of the use cases where I've needed programmatic logout is when handling user invitations.. There if you click the invite email and you are already logged in we show "accept invite" or "create new account". If you click that we log you out and send you back to the invite page which then shows a registration form.

In this case, we authenticate the request has the token from the email anyway, and we absolutely do not need a CSRF token.. Of course we could add one on the "create new account" button I guess if needed, just doesn't seem necessary.

@chalasr
Copy link
Member

chalasr commented Jul 12, 2022

I think most use cases for this method are in similar situations. I'll think of a way to bypass it, will probably end up with a bool parameter. Thanks!

@Seldaek
Copy link
Member

Seldaek commented Jul 17, 2022

@chalasr thanks, LGTM now I think - haven't reviewed the whole code in depth though, but on the surface the API makes sense to me.

@chalasr chalasr force-pushed the feature/auto-logout branch 3 times, most recently from efc530c to ea80c5c Compare July 19, 2022 15:52
@wouterj
Copy link
Member

wouterj commented Jul 19, 2022

I'm not 100% sure, but I'm leaning towards not allowing to bypass CSRF. If an application enabled logout CSRF as a way to prevent login csrf, I would expect all ways of logging out to be protected by CSRF. With this boolean, I no longer can be sure.

Of course, @Seldaek understands login CSRF and knows that CSRF would only be "added noise" in this specific scenario, but I think the framework has a duty to protect those unaware of login CSRF to be as safe as possible.

@chalasr chalasr force-pushed the feature/auto-logout branch from ea80c5c to 080d861 Compare July 19, 2022 15:58
@chalasr
Copy link
Member

chalasr commented Jul 19, 2022

CSRF protection is pointless if logout happens on a GET request, or as a side effect of a state change of another resource which might itself already be CSRF protected using a different token, or Jordi's use case.
I strongly think such cases are the ones for which this method makes the most sense instead of requesting a regular logout endpoint, I would find it too bad to force dealing with it while it's not needed

@Seldaek
Copy link
Member

Seldaek commented Jul 19, 2022

Yeah IMO there's a clear need for the bypass.. But I could live with csrf being enabled by default instead of bypassed by default.

@fabpot
Copy link
Member

fabpot commented Jul 20, 2022

I think that having the default value (for CSRF validation) set to true by default is enough for me as it forces a conscious decision from the developer.

@chalasr chalasr force-pushed the feature/auto-logout branch from 080d861 to e5e7d5e Compare July 20, 2022 16:13
@fabpot
Copy link
Member

fabpot commented Jul 20, 2022

Thank you @johnkrovitch.

@johnkrovitch
Copy link
Contributor Author

You're welcome. Thank you all

@johnkrovitch johnkrovitch deleted the feature/auto-logout branch October 5, 2022 09:00
wouterj added a commit to symfony/symfony-docs that referenced this pull request Oct 16, 2022
This PR was merged into the 6.2 branch.

Discussion
----------

 docs: add docs for programmatic logout

This PR adds documentation for the new feature "programmatic logout" merge in the PR symfony/symfony#41406

Commits
-------

ac46df4 [#17328] Minor changes
5611f88 docs: add docs for programmatic logout
@fabpot fabpot mentioned this pull request Oct 24, 2022
symfony-splitter pushed a commit to symfony/framework-bundle that referenced this pull request Jul 28, 2023
…to SecurityBundle (chalasr)

This PR was merged into the 6.2 branch.

Discussion
----------

[Security][SecurityBundle] Move the `Security` helper to SecurityBundle

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | yes
| Tickets       | Fixes symfony/symfony#46066 (comment)
| License       | MIT
| Doc PR        | todo

The `Security` helper is a high-level service providing an easy access to commonly-needed features coming from various low-level abstractions. Basically, it's a facade.
Based on this, it makes sense to me to make it available only via the full-stack framework, as proposed by Wouter in symfony/symfony#46066 (comment).

This unlocks #46066, symfony/symfony#41274 and symfony/symfony#41406.
/cc @wouterj @johnkrovitch @Kocal

Commits
-------

7b91bcb068 [Security] Move the `Security` helper to SecurityBundle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Security][DX] RFC: A simple way to do programmatic logout
10 participants