close
Skip to content

Fix authentication before 2FA challenge#11943

Merged
Gargron merged 1 commit into
masterfrom
fix-2fa
Sep 24, 2019
Merged

Fix authentication before 2FA challenge#11943
Gargron merged 1 commit into
masterfrom
fix-2fa

Conversation

@Gargron
Copy link
Copy Markdown
Member

@Gargron Gargron commented Sep 24, 2019

Regression from #11831

Thankfully a master-only, unreleased bug.

It is my mistake but the Devise and Warden code around that functionality is very misleading: The sign_in call in the Devise::SessionsController is a lie, because warden.authenticate! the controller calls earlier already sets the session. Not only that, if you remove the warden.authenticate! call from the controller altogether, there is still another part of Devise that will call warden.authenticate which will succeed when the correct username/password are in the request params and also set the session. To add insult to injury, :database_authenticatable also has a side-effect, by setting the rememberable token in a cookie. So as it turns out there was no way to keep the code DRY and run configured strategies without any side effects just to find the correct user record to check for 2FA setting.

Instead we have to duplicate the functionality to perform the 2FA setting check, i.e. finding the user from LDAP, PAM or database depending on configuration in our own sessions controller. It is also important that all the Warden strategies fail for users who have 2FA enabled, so that the aforementioned fuckery does not get in the way.

@Gargron Gargron added the security Security issues and fixes, vulnerabilities label Sep 24, 2019
Comment thread lib/devise/pam_authenticatable.rb Outdated
@Gargron Gargron merged commit a1f04c1 into master Sep 24, 2019
@Gargron Gargron deleted the fix-2fa branch September 24, 2019 02:35
hiyuki2578 pushed a commit to ProjectMyosotis/mastodon that referenced this pull request Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security Security issues and fixes, vulnerabilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants