Skip to content
This repository has been archived by the owner on Dec 2, 2021. It is now read-only.

Bypass 2fa with remember-me option #253

Closed
winus opened this issue Dec 5, 2019 · 11 comments
Closed

Bypass 2fa with remember-me option #253

winus opened this issue Dec 5, 2019 · 11 comments

Comments

@winus
Copy link

winus commented Dec 5, 2019

Bundle version: 4.10.0
Symfony version: 3.4.31

Description
Bypass 2fa by rememberme cookie

To Reproduce
We have a login form with remember_me (checkbox) functionality, When using the checkbox, symfony creates a cookie "REMEMBERME". That moment we get redirected to the 2fa-auth page. We have no access to the other pages. On that moment, when we remove our SESSIONID key with the browsers cookie inspector/tool, we can go to our homepage "/" and be IS_AUTHENTICED_REMEMBERED. Effectively being logged in without 2fa.

@winus winus added the Bug label Dec 5, 2019
@scheb
Copy link
Owner

scheb commented Dec 5, 2019

Ouch, I can confirm that unfortunately. And I don't have a clear plan (yet) how to fix this issue properly. I did some research and right now it looks the best approach would be to decorate the firewall's security.authentication.rememberme.* services to prevent the remember-me cookie from being set when the user enters a two-factor process after a successful login.

/summon @chalasr Do you have and idea how we can solve this?

@scheb scheb added the Security label Dec 5, 2019
scheb added a commit that referenced this issue Dec 5, 2019
@winus
Copy link
Author

winus commented Dec 6, 2019

Well it happens :-) Found it, ( well actually more like, though of the theoretical issue ) while investigating another problem in our application.

I've did a bit of research also, but my knowledge of the login process ( and abstract services) is limited. I found a RememberMeTokenProvider. And my guess would be to override the Symfony's default one.
On the original moment we should check whether the remember me was checked, and put it in the token(i guess).

When the 2fa is succes, we should check the variable / attribute in the token and trigger the RememberMeTokenProvider of Symfony.

@scheb
Copy link
Owner

scheb commented Dec 6, 2019

Yes, something like that would be the solution to set the remember me token after 2fa has been completed.

The issue that I'd like to solve first is how to avoid the cookie to be set right after login. The way this is implemented, it's outside of the bundle's control and I'm wondering what the best approach would be to hook in and prevent it.

@chalasr
Copy link
Contributor

chalasr commented Dec 6, 2019

@scheb I think you could inject the RememberMeServicesInterface instance in your AuthenticationProviderDecorator.
That service is generated by RememberMeFactory (one per firewall), so you should be able to check its existence + inject it from your compiler pass by guessing the generated service name.
Then, in AuthenticationProviderDecorator, if the authenticated token is an instance of RememberMeToken, call RememberMeServicesInterface::loginFail() and, once 2fa completed, call RememberMeServicesInterface::autoLogin() to set back the cookie.

scheb added a commit that referenced this issue Dec 8, 2019
scheb added a commit that referenced this issue Dec 8, 2019
scheb added a commit that referenced this issue Dec 8, 2019
scheb added a commit that referenced this issue Dec 8, 2019
scheb added a commit that referenced this issue Dec 8, 2019
@scheb
Copy link
Owner

scheb commented Dec 8, 2019

This issue is fixed in versions 4.11.0 and 3.26.0.

@chalasr Thanks for your help, much appreciated!

@bytehead, @brusch, @Seldaek I believe you should upgrade to ^3.26.0 / ^4.11.0

@scheb scheb closed this as completed Dec 8, 2019
@Seldaek
Copy link
Contributor

Seldaek commented Dec 8, 2019

Thanks, deployed the fixed version

@bytehead
Copy link
Contributor

bytehead commented Dec 9, 2019

Thank you @scheb!

@brusch
Copy link

brusch commented Dec 9, 2019

@scheb Thanks a lot!

leofeyer pushed a commit to contao/contao that referenced this issue Dec 9, 2019
Description
-----------

See scheb/two-factor-bundle#253.

Commits
-------

c55fe7e Bump scheb/two-factor-bundle version to ^4.11
f7efee2 Adjust version constraint
leofeyer pushed a commit to contao/core-bundle that referenced this issue Dec 9, 2019
Description
-----------

See scheb/two-factor-bundle#253.

Commits
-------

c55fe7e2 Bump scheb/two-factor-bundle version to ^4.11
f7efee2d Adjust version constraint
@zerkms
Copy link
Contributor

zerkms commented Dec 18, 2019

Is it possible to tell when it was introduced? Or was it there forever?

@scheb
Copy link
Owner

scheb commented Dec 19, 2019

I haven't tested every version of the bundle with every version of Symfony, but the way this issue works very likely affects all versions from 3 until 3.26.0 and all versions from 4 until 4.11.0, independent of the Symfony version.

And now that I think about it, all versions from 1.x and 2.x, which depend on a session flag to ask for 2fa, probably have and still have this issue.

@zerkms
Copy link
Contributor

zerkms commented Dec 19, 2019

@scheb I'm here because I also discovered this behaviour yesterday myself, but I was going to report it privately through the direct email.

Wondering if issues like that should be considered as highly sensitive security bugs.

@scheb scheb changed the title Bypass 2fa Bypass 2fa with remember-me option Dec 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants