Skip to content

Conversation

@mikeselander
Copy link

@mikeselander mikeselander commented Sep 3, 2018

Adds a network-level setting to require two-factor authentication on a per-role or universal level. If 2fa forcing is on and a user matches the criteria, we force the user into a 2fa settings screen and they cannot use the site until they add valid 2fa to their account.

Super administrators can edit the settings with this interface via network settings:
screen shot 2018-09-04 at 1 40 41 pm

Users who fall within the required buckets will see this interface:
screen shot 2018-09-04 at 1 42 16 pm

@mikeselander
Copy link
Author

mikeselander commented Sep 4, 2018

@joehoyle can I please get a review and test from you on this functionality?

It's specifically setup for networks at the moment and also worth noting that I've written the code inline with the standards and style setup for the upstream repo. A lot of the style and architectural pattern is pretty gross, but hoping that we can get this upstreamed faster by going that route.

@joehoyle
Copy link
Member

joehoyle commented Sep 4, 2018

@mikeselander functinalty wise: it's working great! Though the enable screen looks like this:

Have those items at the bottom shown. I ran npm install and grunt, and then I don't have any errors in console for missing assets. Also if I submit it and there's an error, it seems it doesn't show any validation.

+1 for a non-multisite support too, as central.aws.hmn.md isn't multisite. I'd imagine you could just use the existing functions for that?

@mikeselander
Copy link
Author

Have those items at the bottom shown.

Odd, I have never seen those 🤔 I'll try to re-produce.

Also if I submit it and there's an error, it seems it doesn't show any validation.

This is an architectural problem with the plugin itself that would require modifying a good bit of internals to fix. The plugin is built to only ever work on a save submission from a user panel and none of them return or throw errors :(

Some of the methods (TOTP for example) do show an error message within their little pane if something has gone wrong.

+1 for a non-multisite support too, as central.aws.hmn.md isn't multisite. I'd imagine you could just use the existing functions for that?

Ya, I can mostly use the same functions and then registering the options for single sites. I'll add that in 👍

@mikeselander
Copy link
Author

@joehoyle I've fixed this visual issues and added single site support. Mind taking another look through?

@rmccue
Copy link
Member

rmccue commented Sep 5, 2018

Should this be PR'd directly to the upstream repo rather than merged?

@joehoyle
Copy link
Member

joehoyle commented Sep 5, 2018

@mikeselander nice, it's looking pretty good to me. I don't know why the plugin shows the "Security Keys" section if you haven't selected U2F.

Out of interest, does the plugin allow you to filter the options for 2fa? I guess it could be a site setting again, but it seems odd site administrators can't whitelist the allowed 2fa authentication methods.

$two_factor_forced_roles = self::get_forced_user_roles();
$required_roles = array_filter( $user->roles, function( $role ) use ( $two_factor_forced_roles ) {
return in_array( $role, $two_factor_forced_roles, true );
}, ARRAY_FILTER_USE_BOTH);
Copy link
Member

Choose a reason for hiding this comment

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

Missing space at the end.

* @return bool
*/
public static function get_universally_forced_option() {
$is_forced = is_multisite() ? get_site_option( self::FORCED_SITE_META_KEY, false ) : get_option( self::FORCED_SITE_META_KEY, false );
Copy link
Member

Choose a reason for hiding this comment

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

You don't need this ternary:

This function is almost identical to get_option(), except that in multisite, it returns the network-wide option. For non-multisite installs, it uses get_option.

Copy link
Author

Choose a reason for hiding this comment

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

Ah, TIL :)

<tbody>
<tr>
<th scope="row">
<?php esc_html_e( 'Universally force two-factor', 'two-factor' ); ?>
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure of this working. "Force all users to enable two-factor"?

@joehoyle
Copy link
Member

joehoyle commented Sep 5, 2018

@mikeselander actually, I see for enable 2fa you are doing it inline, as opposed to redirecting to a specific URL. For whatever reason this means if I am on hte homepage, it shows like this:

It might be better to have a discrete URL where this is shown (maybe wp-login.php?action=force-2fa for example), rather than trying to show it in-place on all URLs.

@joehoyle
Copy link
Member

joehoyle commented Sep 5, 2018

Also noticed I have a fatal on the homepage screenshot:

Fatal error: Uncaught Error: Call to undefined function convert_to_screen() in /usr/src/app/wordpress/wp-admin/includes/class-wp-list-table.php:132 Stack trace: #0 /usr/src/app/content/plugins/two-factor/providers/class.two-factor-fido-u2f-admin.php(189): WP_List_Table->__construct() #1 /usr/src/app/wordpress/wp-includes/class-wp-hook.php(286): Two_Factor_FIDO_U2F_Admin::show_user_profile(Object(WP_User)) #2 /usr/src/app/wordpress/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array) #3 /usr/src/app/wordpress/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #4 /usr/src/app/content/plugins/two-factor/class.two-factor-core.php(827): do_action('show_user_secur...', Object(WP_User)) #5 /usr/src/app/content/plugins/two-factor/class.two-factor-core.php(537): Two_Factor_Core::user_two_factor_options(Object(WP_User)) #6 /usr/src/app/content/plugins/two-factor/class.two-factor-core.php(501): Two_Factor_Core::force_2fa_login_html() #7 /usr/src/app/wordpress/wp-includes/class-wp-hook.php(286): Two_Factor_Core:: in /usr/src/app/wordpress/wp-admin/includes/class-wp-list-table.php on line 132

@mikeselander
Copy link
Author

Also noticed I have a fatal on the homepage screenshot:

Will look and re-produce 👍

@mikeselander nice, it's looking pretty good to me. I don't know why the plugin shows the "Security Keys" section if you haven't selected U2F.

Ya, that's just something that it does ¯\_(ツ)_/¯

Out of interest, does the plugin allow you to filter the options for 2fa? I guess it could be a site setting again, but it seems odd site administrators can't whitelist the allowed 2fa authentication methods.

It does allow you to filter the methods that are available - The filter is two_factor_providers and can be found here: https://github.com/humanmade/two-factor/blob/master/class.two-factor-core.php#L77-L86

@mikeselander
Copy link
Author

Should this be PR'd directly to the upstream repo rather than merged?

@rmccue I wanted to get Joe's feedback before opening a PR against the upstream repo. I also am wary of how long this could take to get merged into the upstream repo and my client needs it this week.

@rmccue
Copy link
Member

rmccue commented Sep 6, 2018

I wanted to get Joe's feedback before opening a PR against the upstream repo. I also am wary of how long this could take to get merged into the upstream repo and my client needs it this week.

Yeah, just wanted to check if we wanted to fork or not :)

@rmccue
Copy link
Member

rmccue commented Oct 16, 2018

Linking the upstream PR: WordPress#239

Should we close this PR in favour of handling it over there?

@shadyvb shadyvb mentioned this pull request Feb 14, 2022
@shadyvb
Copy link

shadyvb commented Feb 14, 2022

Opening back now, since upstream PR hasn't been merged.

@shadyvb shadyvb reopened this Feb 14, 2022
@shadyvb
Copy link

shadyvb commented Feb 14, 2022

Travis install seems to be busted here, so will ignore and merge, tested the functionality and it seems to be working as expected.

@shadyvb shadyvb merged commit 6b59def into master Feb 14, 2022
@roborourke
Copy link

Yeah I think it's missing a git submodule for the xwp dev library

@roborourke
Copy link

What are your thoughts on the release version? 0.2.2? technically 0.2.1 introduced a bug by missing a bunch of this plugin :/

We can go for 0.3.0 but we'll need to backport that update through to v7

joehoyle pushed a commit that referenced this pull request Aug 4, 2023
Update function.login-header.php to be compatible with WP 5.7
joehoyle pushed a commit that referenced this pull request Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants