Repository navigation
Ensure that doesn't 'fail open' if existing providers poof. #586
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
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c79bbcc
Ensure that doesn't 'fail open' if existing providers poof.
georgestephanis bd676f9
Do the fallback slightly downstream.
georgestephanis 9ad6dd6
Handle the WP_Error fail cases
georgestephanis c9aa7ac
Add a unit test for this.
georgestephanis a745c3c
Ensure we're comparing the keys.
georgestephanis f8c780d
Use a class that won't get stripped out.
georgestephanis 2e616ea
Update the error messages for understandability.
georgestephanis 947afdd
Merge branch 'master' into add/fallback-email
dd32 d12c89a
Merge branch 'master' into add/fallback-email
georgestephanis 1f0035b
Whoops, reintroduced in merge.
georgestephanis 66b43ae
Tidy up and run it further downstream.
georgestephanis 953e5c2
Revert "Tidy up and run it further downstream."
georgestephanis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Do the fallback slightly downstream.
- Loading branch information
commit bd676f9516768a8a9ac22b643268e8f84071140c
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only part that I'm concerned about since we're changing the return type of a public helper method that previously only returned an array. Some clients might not account for that.
Maybe we could split this into two parts -- one that adds back the email factor and another one used during login flow to return the error if no fallback options are available (but were historically configured)? This would keep the function signatures while still preventing login.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, if returning the error breaks something not accounting for it, I honestly kinda see that as a win, as we don't want it to silently allow stuff to go through if they had ... FIDO U2F as their only provider and it goes away, for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree! I'm only suggesting that we do that during the login attempts instead of whenever somebody calls the
get_available_providers_for_user(). My suggestion would be to silently addTwo_Factor_Emailin this method and use another helper during login to return error if they previously had a method configured but none of them are supported anymore. This approach would keep the method signature intact while still preventing login.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now we are adding the Email method is available. Are you suggesting we always add the Email method? Or that we would return an empty array in that case instead of a
WP_Error?I do lean towards returning a
WP_Errorand accepting this as an intentional BC break.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rewrote this in 66b43ae but would be fine reverting that -- so either way.
We're only adding the Email method if the user previously had some method configured (by checking their usermeta key) but now no methods are available (for example, because a configured method has gone away).
The goal is to ensure only that if an existing method is removed, the account won't lose all two-factor protections without the user even realizing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does worry me that this function is now failing open, and a developer would have to know to implement the same logic as the 2FA plugin is doing to be safe.
Inspired a bit by various Core function signatures, what if we introduce a
$wp_errorparameter. It'd be false by default, but whentruewould do the necessary validation and construct a properWP_Errorobject.We could then fire a
_doing_it_wrongnotice if the function is called without$wp_error. That way developers would know they are doing something dangerous.Inspired by GB's BC promise, we could then potentially switch the default to
trueor just make that the default value after a few versions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be fine with that from what I understand of it, but I'm not positive I follow all of it. My brain may be too much in the weeds of a different problem right now. @TimothyBJacobs , do you think you may be able to do a pr to the pr to revert 66b43ae and show what you're thinking? Or just take over this branch -- I'm 100% fine with that too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I can push a commit this evening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is causing fatal errors on wordpress.org now.
From https://github.com/WordPress/wporg-two-factor/blob/trunk/wporg-two-factor.php#L423-L426
There seem to other instances in this plugin where it assumes the return value to always be an array:
two-factor/class-two-factor-core.php
Line 2091 in 62ac5a4
two-factor/class-two-factor-core.php
Lines 774 to 776 in 62ac5a4