Making WordPress.org


Ignore:
Timestamp:
12/11/2024 05:36:31 AM (18 months ago)
Author:
dd32
Message:

Plugin Directory: Require 2FA verification to confirm a plugin release.

This replaces the email access links.
All plugin committers are required to have 2FA enabled now.

Closes https://github.com/WordPress/wordpress.org/pull/344.
Fixes #7704.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-release-confirmation.php

    r14218 r14262  
    77use WordPressdotorg\Plugin_Directory\Tools;
    88use WordPressdotorg\Plugin_Directory\Jobs\Plugin_Import;
    9 use WordPressdotorg\Plugin_Directory\Shortcodes\Release_Confirmation as Release_Confirmation_Shortcode;
    109use WordPressdotorg\Plugin_Directory\Email\Release_Confirmation_Enabled as Release_Confirmation_Enabled_Email;
    11 use WordPressdotorg\Plugin_Directory\Email\Release_Confirmation_Access as Release_Confirmation_Access_Email;
     10use Two_Factor_Core;
     11use function WordPressdotorg\Two_Factor\Revalidation\{
     12    get_status as get_revalidation_status,
     13    get_url as get_revalidation_url,
     14};
    1215
    1316/**
     
    8083                return false;
    8184            },
    82         ] );
    83 
    84         register_rest_route( 'plugins/v1', '/release-confirmation-access', [
    85             'methods'             => \WP_REST_Server::READABLE,
    86             'callback'            => [ $this, 'send_access_email' ],
    87             'args'                => [
    88             ],
    89             'permission_callback' => 'is_user_logged_in',
    9085        ] );
    9186
     
    119114        $plugin = Plugin_Directory::get_plugin_post( $request['plugin_slug'] );
    120115
    121         return (
    122             Release_Confirmation_Shortcode::can_access() &&
    123             current_user_can( 'plugin_manage_releases', $plugin )
    124         );
     116        if ( ! $plugin || ! current_user_can( 'plugin_manage_releases', $plugin ) ) {
     117            return false;
     118        }
     119
     120        // Check to see if they've confirmed their 2FA status recently..
     121        $status = get_revalidation_status();
     122        if ( $status && $status['can_save'] ) {
     123            return true;
     124        }
     125
     126        // Before we say no, check if the user just needs to validate their 2FA.
     127        if ( $status && $status['needs_revalidate'] && 'GET' === $request->get_method() ) {
     128            $current_rest_url = add_query_arg(
     129                array(
     130                    '_wpnonce'         => wp_create_nonce( 'wp_rest' ),
     131                    '_wp_http_referer' => wp_get_referer(),
     132                ),
     133                get_rest_url( null, $request->get_route() )
     134            );
     135
     136            wp_safe_redirect( get_revalidation_url( $current_rest_url ) );
     137            exit;
     138        }
     139
     140        return false;
    125141    }
    126142
     
    300316    }
    301317
    302     /**
    303      * Send a Access email
    304      */
    305     public function send_access_email( $request ) {
    306         $result = [
    307             'location' => wp_get_referer() ?: home_url( '/developers/releases/' ),
    308         ];
    309         $result['location'] = add_query_arg( 'send_access_email', '1', $result['location'] );
    310         header( 'Location: ' . $result['location'] );
    311 
    312         $email = new Release_Confirmation_Access_Email(
    313             wp_get_current_user()
    314         );
    315         $result['sent'] = $email->send();
    316 
    317         return $result;
    318     }
    319 
    320318    public function validate_plugin_tag_callback( $tag, $request ) {
    321319        $plugin = Plugin_Directory::get_plugin_post( $request['plugin_slug'] );
Note: See TracChangeset for help on using the changeset viewer.