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

Disable U2F Interface unless already configured. #571

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion class-two-factor-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,27 @@ public static function user_two_factor_options( $user ) {
$show_2fa_options ? '' : 'disabled="disabled"'
);

$providers = self::get_providers();

// Disable U2F unless already configured.
if ( isset( $providers['Two_Factor_FIDO_U2F'] ) ) {
$disabled = ! $providers['Two_Factor_FIDO_U2F']->is_available_for_user( $user );

/**
* Filter whether the deprecated U2F provider is available.
*
* The U2F provider does not support modern browsers, and it being enabled causes confusion.
*
* @param bool $disabled Whether the provider is disabled for this user.
* @param WP_User $user The user being displayed.
*/
$disabled = apply_filters( 'two_factor_u2f_disabled', $disabled, $user );

if ( $disabled ) {
unset( $providers['Two_Factor_FIDO_U2F'] );
}
}

wp_nonce_field( 'user_two_factor_options', '_nonce_user_two_factor_options', false );
?>
<h3><?php esc_html_e( 'Two-Factor Options', 'two-factor' ); ?></h3>
Expand All @@ -1732,7 +1753,7 @@ public static function user_two_factor_options( $user ) {
</tr>
</thead>
<tbody>
<?php foreach ( self::get_providers() as $provider_key => $object ) : ?>
<?php foreach ( $providers as $provider_key => $object ) : ?>
<tr>
<th scope="row"><input id="enabled-<?php echo esc_attr( $provider_key ); ?>" type="checkbox" name="<?php echo esc_attr( self::ENABLED_PROVIDERS_USER_META_KEY ); ?>[]" value="<?php echo esc_attr( $provider_key ); ?>" <?php checked( in_array( $provider_key, $enabled_providers, true ) ); ?> /></th>
<th scope="row"><input type="radio" name="<?php echo esc_attr( self::PROVIDER_USER_META_KEY ); ?>" value="<?php echo esc_attr( $provider_key ); ?>" <?php checked( $provider_key, $primary_provider_key ); ?> /></th>
Expand Down
18 changes: 18 additions & 0 deletions providers/class-two-factor-fido-u2f-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ public static function enqueue_assets( $hook ) {

$security_keys = Two_Factor_FIDO_U2F::get_security_keys( $user_id );

// Disabled interface if there's no keys.
if (
! $security_keys &&
/** This filter is documented in class-two-factor-core.php */
apply_filters( 'two_factor_u2f_disabled', true )
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we pass the user object to the filter to match the original?

) {
return;
}

// @todo Ensure that scripts don't fail because of missing u2fL10n.
try {
$data = Two_Factor_FIDO_U2F::$u2f->getRegisterData( $security_keys );
Expand Down Expand Up @@ -164,6 +173,15 @@ protected static function asset_version() {
* @param WP_User $user WP_User object of the logged-in user.
*/
public static function show_user_profile( $user ) {
// Don't display if the user cannot configure it.
if (
! Two_Factor_FIDO_U2F::get_instance()->is_available_for_user( $user ) &&
/** This filter is documented in class-two-factor-core.php */
apply_filters( 'two_factor_u2f_disabled', true )
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here -- should we pass the $user as the second argument to the filter?

) {
return;
}

wp_nonce_field( "user_security_keys-{$user->ID}", '_nonce_user_security_keys' );
$new_key = false;

Expand Down
3 changes: 1 addition & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ Stable tag: 0.9.1
License: GPL-2.0-or-later
License URI: https://spdx.org/licenses/GPL-2.0-or-later.html

Enable Two-Factor Authentication using time-based one-time passwords, Universal 2nd Factor (FIDO U2F, YubiKey), email, and backup verification codes.
Enable Two-Factor Authentication using time-based one-time passwords, email, and backup verification codes.

== Description ==

Use the "Two-Factor Options" section under "Users" → "Your Profile" to enable and configure one or multiple two-factor authentication providers for your account:

- Email codes
- Time Based One-Time Passwords (TOTP)
- FIDO Universal 2nd Factor (U2F)
- Backup Codes
- Dummy Method (only for testing purposes)

Expand Down