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

Fix authentication before 2FA challenge #11943

Merged
merged 1 commit into from
Sep 24, 2019
Merged

Fix authentication before 2FA challenge #11943

merged 1 commit into from
Sep 24, 2019

Conversation

Gargron
Copy link
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
lib/devise/pam_authenticatable.rb Outdated Show resolved Hide resolved
@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.

None yet

2 participants