Making WordPress.org

Changeset 15212


Ignore:
Timestamp:
09/17/2026 04:25:15 PM (2 months ago)
Author:
obenland
Message:

Plugins: Tidy up the REST route permission checks

Closes ​https://github.com/WordPress/wordpress.org/pull/930.

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
2 added
21 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php

    r15188 r15212  
    33
    44use \WordPressdotorg\Plugin_Directory;
     5use WordPressdotorg\Plugin_Directory\API\Base;
    56use \WordPressdotorg\Plugin_Directory\Tools;
    67use \WordPressdotorg\Plugin_Directory\Tools\SVN;
    … …  
    135136         */
    136137        public function enqueue_assets( $hook_suffix ) {
    137                 global $post_type;
     138                global $post, $post_type;
    138139
    139140                if ( 'plugin' === $post_type ) {
    … …  
    148149                                                'removeCommitterAYS'   => __( 'Are you sure you want to remove this committer?', 'wporg-plugins' ),
    149150                                                'removeSupportRepAYS'  => __( 'Are you sure you want to remove this support rep?', 'wporg-plugins' ),
     151                                                'uploadNonce'          => Base::action_nonce( 'upload', $post->ID ),
    150152                                        ) );
    151153                                        break;
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-release-confirmation.php

    r15188 r15212  
    33
    44use WP_REST_Request;
     5use WordPressdotorg\Plugin_Directory\API\Base;
    56use WordPressdotorg\Plugin_Directory\Tools;
    67use WordPressdotorg\Plugin_Directory\Shortcodes\Release_Confirmation as Release_Confirmation_Shortcode;
    … …  
    6768                                        $new
    6869                                );
     70                                $request->set_param(
     71                                        Base::ACTION_NONCE_PARAM,
     72                                        Base::action_nonce( 'enable_release_confirmation', $post->post_name )
     73                                );
    6974
    7075                                // For some reason, this is causing a 502 bad gateway - upstream sent too big header
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/class-base.php

    r14873 r15212  
    88 */
    99class Base {
     10
     11        /**
     12         * The request parameter that carries a privileged route's action nonce.
     13         *
     14         * Kept separate from `_wpnonce`, which core's cookie authentication claims for
     15         * the generic `wp_rest` action before a route is reached.
     16         *
     17         * @var string
     18         */
     19        const ACTION_NONCE_PARAM = '_wporg_action';
     20
    1021        /**
    1122         * Initializes REST API customizations.
    1223         */
    1324        public static function init() {
     25                add_filter( 'rest_request_before_callbacks', array( __CLASS__, 'reject_cross_origin_write' ), 10, 3 );
     26
    1427                self::load_routes();
    1528        }
    … …  
    96109                return true;
    97110        }
     111
     112        /**
     113         * Mints the nonce a privileged route requires, bound to the action it authorizes.
     114         *
     115         * @param string $action  The route action, such as `add_committer`.
     116         * @param string $subject Optional. What the action is performed on, usually a plugin slug.
     117         * @return string The nonce to pass as {@see Base::ACTION_NONCE_PARAM}.
     118         */
     119        public static function action_nonce( $action, $subject = '' ) {
     120                return wp_create_nonce( self::action_nonce_name( $action, $subject ) );
     121        }
     122
     123        /**
     124         * Names the nonce action for a privileged route.
     125         *
     126         * @param string $action  The route action, such as `add_committer`.
     127         * @param string $subject Optional. What the action is performed on, usually a plugin slug.
     128         * @return string The nonce action.
     129         */
     130        protected static function action_nonce_name( $action, $subject = '' ) {
     131                $subject = (string) $subject;
     132
     133                return 'wporg_plugins_' . $action . ( '' !== $subject ? ':' . $subject : '' );
     134        }
     135
     136        /**
     137         * A Permission Check callback which requires the capability and action a route declares.
     138         *
     139         * Routes name both alongside their callback:
     140         *
     141         *     'permission_callback' => array( $this, 'permission_check_action' ),
     142         *     'wporg_capability'    => 'plugin_add_committer',
     143         *     'wporg_action'        => 'add_committer',
     144         *
     145         * The capability is checked against the request's plugin, and the nonce is bound to its
     146         * slug plus any further `wporg_nonce_params` the route lists, such as a release tag. A
     147         * route whose subject is not a plugin slug calls {@see Base::verify_action_nonce()}
     148         * itself with whatever identifies its own.
     149         *
     150         * @param \WP_REST_Request $request The Rest API Request.
     151         * @return bool|\WP_Error True when both hold, false or WP_Error upon failure.
     152         */
     153        public function permission_check_action( $request ) {
     154                $attributes = $request->get_attributes();
     155
     156                // A route that declares neither is refused rather than checked against nothing.
     157                if ( empty( $attributes['wporg_capability'] ) || empty( $attributes['wporg_action'] ) ) {
     158                        return false;
     159                }
     160
     161                $plugin = Plugin_Directory::get_plugin_post( $request['plugin_slug'] );
     162
     163                if ( ! $plugin || ! current_user_can( $attributes['wporg_capability'], $plugin ) ) {
     164                        return false;
     165                }
     166
     167                $subject = array( $request['plugin_slug'] );
     168
     169                foreach ( $attributes['wporg_nonce_params'] ?? array() as $param ) {
     170                        $subject[] = $request[ $param ];
     171                }
     172
     173                return $this->verify_action_nonce( $request, $attributes['wporg_action'], implode( ':', $subject ) );
     174        }
     175
     176        /**
     177         * Verifies that a request carries the nonce for the action it is asking for.
     178         *
     179         * Returns the same error code as a stale `wp_rest` nonce, so the routes that turn
     180         * that into a "link has expired" page keep doing so.
     181         *
     182         * @param \WP_REST_Request $request The Rest API Request.
     183         * @param string           $action  The route action, such as `add_committer`.
     184         * @param string           $subject Optional. What the action is performed on.
     185         * @return bool|\WP_Error True if the nonce is valid, WP_Error upon failure.
     186         */
     187        public function verify_action_nonce( $request, $action, $subject = '' ) {
     188                $nonce = $request->get_param( self::ACTION_NONCE_PARAM );
     189
     190                if ( ! $nonce || ! wp_verify_nonce( $nonce, self::action_nonce_name( $action, $subject ) ) ) {
     191                        return new \WP_Error(
     192                                'rest_cookie_invalid_nonce',
     193                                __( 'Sorry! You cannot do that.', 'wporg-plugins' ),
     194                                array( 'status' => \WP_Http::FORBIDDEN )
     195                        );
     196                }
     197
     198                return true;
     199        }
     200
     201        /**
     202         * Keeps a cookie-authenticated write to this namespace on the directory's own pages.
     203         *
     204         * The login cookie is shared across the wordpress.org hosts, so the session does not
     205         * say which host a request came from; `Origin` does.
     206         *
     207         * Routes whose permission callback is `__return_true` are exempt, such as the
     208         * blueprint Playground fetches from its own origin: the session is not what
     209         * authorizes those.
     210         *
     211         * @param mixed            $response Result to send to the client.
     212         * @param array            $handler  Route handler used for the request.
     213         * @param \WP_REST_Request $request  Request used to generate the response.
     214         * @return mixed The response, or WP_Error when the write came from elsewhere.
     215         */
     216        public static function reject_cross_origin_write( $response, $handler, $request ) {
     217                if ( null !== $response ) {
     218                        return $response;
     219                }
     220
     221                if ( ! str_starts_with( strtolower( ltrim( $request->get_route(), '/' ) ), 'plugins/v1/' ) ) {
     222                        return $response;
     223                }
     224
     225                if ( in_array( $request->get_method(), array( 'GET', 'HEAD', 'OPTIONS' ), true ) ) {
     226                        return $response;
     227                }
     228
     229                if ( isset( $handler['permission_callback'] ) && '__return_true' === $handler['permission_callback'] ) {
     230                        return $response;
     231                }
     232
     233                if ( ! is_user_logged_in() ) {
     234                        return $response;
     235                }
     236
     237                $origin = get_http_origin();
     238                if ( ! $origin || in_array( $origin, self::same_site_origins(), true ) ) {
     239                        return $response;
     240                }
     241
     242                return new \WP_Error(
     243                        'rest_cross_origin_write',
     244                        __( 'Sorry! You cannot do that.', 'wporg-plugins' ),
     245                        array( 'status' => \WP_Http::FORBIDDEN )
     246                );
     247        }
     248
     249        /**
     250         * The origins this site's own pages are served from.
     251         *
     252         * Each localised directory is its own site, so `home_url()` already names the host
     253         * that served the page making the request. Anything the mapping does not cover is
     254         * a legitimate write refused, which is what the filter is for.
     255         *
     256         * @return array The origins a write may carry.
     257         */
     258        protected static function same_site_origins() {
     259                $origins = array();
     260
     261                foreach ( array( home_url(), admin_url() ) as $url ) {
     262                        $parts = wp_parse_url( $url );
     263
     264                        if ( ! empty( $parts['scheme'] ) && ! empty( $parts['host'] ) ) {
     265                                $origins[] = $parts['scheme'] . '://' . $parts['host'] .
     266                                        ( empty( $parts['port'] ) ? '' : ':' . $parts['port'] );
     267                        }
     268                }
     269
     270                /**
     271                 * Filters the origins a `plugins/v1` write may be made from.
     272                 *
     273                 * @param array $origins Origins serving this directory's own pages.
     274                 */
     275                $origins = apply_filters( 'wporg_plugins_same_site_origins', array_unique( $origins ) );
     276
     277                return array_map( 'strval', (array) $origins );
     278        }
    98279}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-categorization.php

    r12337 r15212  
    1919                                'methods'             => WP_REST_Server::CREATABLE,
    2020                                'callback'            => [ $this, 'save_external_repository_url' ],
    21                                 'permission_callback' => function( $request ) {
    22                                         return current_user_can(
    23                                                 'plugin_admin_edit',
    24                                                 Plugin_Directory::get_plugin_post( $request['plugin_slug'] )
    25                                         );
    26                                 },
     21                                'permission_callback' => [ $this, 'permission_check_action' ],
     22                                'wporg_capability'    => 'plugin_admin_edit',
     23                                'wporg_action'        => 'save_categorization',
    2724                                'args'                => [
    2825                                        'plugin_slug' => [
    … …  
    4239                                'methods'             => WP_REST_Server::CREATABLE,
    4340                                'callback'            => [ $this, 'save_external_support_url' ],
    44                                 'permission_callback' => function( $request ) {
    45                                         return current_user_can(
    46                                                 'plugin_admin_edit',
    47                                                 Plugin_Directory::get_plugin_post( $request['plugin_slug'] )
    48                                         );
    49                                 },
     41                                'permission_callback' => [ $this, 'permission_check_action' ],
     42                                'wporg_capability'    => 'plugin_admin_edit',
     43                                'wporg_action'        => 'save_categorization',
    5044                                'args'                => [
    5145                                        'plugin_slug' => [
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-committers.php

    r15044 r15212  
    3939                                'methods'             => WP_REST_Server::CREATABLE,
    4040                                'callback'            => array( $this, 'add_committer' ),
    41                                 'permission_callback' => function( $request ) {
    42                                         return current_user_can(
    43                                                 'plugin_add_committer',
    44                                                 Plugin_Directory::get_plugin_post( $request['plugin_slug'] )
    45                                         );
    46                                 },
     41                                'permission_callback' => array( $this, 'permission_check_action' ),
     42                                'wporg_capability'    => 'plugin_add_committer',
     43                                'wporg_action'        => 'add_committer',
    4744                                'args'                => array(
    4845                                        'plugin_slug' => array(
    … …  
    5754                        'methods'             => WP_REST_Server::DELETABLE,
    5855                        'callback'            => array( $this, 'revoke_committer' ),
    59                         'permission_callback' => function( $request ) {
    60                                 return current_user_can(
    61                                         'plugin_remove_committer',
    62                                         Plugin_Directory::get_plugin_post( $request['plugin_slug'] )
    63                                 );
    64                         },
     56                        'permission_callback' => array( $this, 'permission_check_action' ),
     57                        'wporg_capability'    => 'plugin_remove_committer',
     58                        'wporg_action'        => 'remove_committer',
    6559                        'args'                => array(
    6660                                'plugin_slug' => array(
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-release-confirmation.php

    r14698 r15212  
    3030                                ],
    3131                        ],
    32                         'permission_callback' => function( $request ) {
    33                                 $plugin = Plugin_Directory::get_plugin_post( $request['plugin_slug'] );
    34 
    35                                 return current_user_can( 'plugin_manage_releases', $plugin );
    36                         },
     32                        'permission_callback' => [ $this, 'permission_check_action' ],
     33                        'wporg_capability'    => 'plugin_manage_releases',
     34                        'wporg_action'        => 'enable_release_confirmation',
    3735                ] );
    3836
    … …  
    4846                                ]
    4947                        ],
    50                         'permission_callback' => [ $this, 'permission_can_access_plugin' ],
     48                        'permission_callback' => [ $this, 'permission_can_access_release' ],
     49                        'wporg_capability'    => 'plugin_manage_releases',
     50                        'wporg_action'        => 'confirm_release',
     51                        'wporg_nonce_params'  => [ 'plugin_tag' ],
    5152                ] );
    5253
    … …  
    6263                                ]
    6364                        ],
    64                         'permission_callback' => [ $this, 'permission_can_access_plugin' ],
     65                        'permission_callback' => [ $this, 'permission_can_access_release' ],
     66                        'wporg_capability'    => 'plugin_manage_releases',
     67                        'wporg_action'        => 'discard_release',
     68                        'wporg_nonce_params'  => [ 'plugin_tag' ],
    6569                ] );
    6670
    … …  
    7680                                ]
    7781                        ],
    78                         'permission_callback' => function( $request ) {
    79                                 if ( current_user_can( 'plugin_review' ) ) {
    80                                         return $this->permission_can_access_plugin( $request );
    81                                 }
    82 
    83                                 return false;
    84                         },
     82                        'permission_callback' => [ $this, 'permission_can_undo_discard' ],
     83                        'wporg_capability'    => 'plugin_manage_releases',
     84                        'wporg_action'        => 'undo_discard_release',
     85                        'wporg_nonce_params'  => [ 'plugin_tag' ],
    8586                ] );
    8687
    … …  
    9596                        is_array( $result ) && isset( $result['code'] ) &&
    9697                        (
    97                                 preg_match( '!^/plugins/v1/plugin/([^/]+)/release-confirmation(/[^/]+)?$!', $request->get_route(), $m )
     98                                preg_match( '!^/plugins/v1/plugin/([^/]+)/release-confirmation(/[^/]+){0,2}$!', $request->get_route(), $m )
    9899                                ||
    99100                                '/plugins/v1/release-confirmation-access' === $request->get_route()
    100101                        )
    101102                ) {
    102                         if ( 'rest_cookie_invalid_nonce' == $result['code'] || 'rest_forbidden' == $result['code'] ) {
     103                        if (
     104                                'rest_cookie_invalid_nonce' === $result['code'] ||
     105                                'rest_forbidden' === $result['code'] ||
     106                                'rest_cross_origin_write' === $result['code']
     107                        ) {
    103108                                wp_die( 'The link you have followed has expired.' );
    104109                        }
    … …  
    109114
    110115        /**
     116         * Validate that the user can manage releases for the given tag, and meant to.
     117         *
     118         * These routes list `plugin_tag` among their nonce params, so the token is bound to
     119         * the tag as well as the plugin and one release's link does not authorize another's.
     120         * The check runs before the 2FA hand-off in
     121         * {@see Plugin_Release_Confirmation::permission_can_access_plugin()}, which would
     122         * otherwise redirect a request this route goes on to refuse.
     123         *
     124         * @param \WP_REST_Request $request The Rest API Request.
     125         * @return bool|\WP_Error True when both hold, false or WP_Error upon failure.
     126         */
     127        public function permission_can_access_release( $request ) {
     128                $verified = $this->permission_check_action( $request );
     129
     130                if ( true !== $verified ) {
     131                        return $verified;
     132                }
     133
     134                return $this->permission_can_access_plugin( $request );
     135        }
     136
     137        /**
     138         * Validate that a reviewer can undo the discarding of the given release.
     139         *
     140         * @param \WP_REST_Request $request The Rest API Request.
     141         * @return bool|\WP_Error True when the reviewer may, false or WP_Error upon failure.
     142         */
     143        public function permission_can_undo_discard( $request ) {
     144                if ( ! current_user_can( 'plugin_review' ) ) {
     145                        return false;
     146                }
     147
     148                return $this->permission_can_access_release( $request );
     149        }
     150
     151        /**
     152         * Whether the current user may manage the requested plugin's releases.
     153         *
     154         * @param \WP_REST_Request $request The Rest API Request.
     155         * @return bool True if the plugin exists and the user may manage its releases.
     156         */
     157        protected function can_manage_releases( $request ) {
     158                $plugin = Plugin_Directory::get_plugin_post( $request['plugin_slug'] );
     159
     160                return $plugin && current_user_can( 'plugin_manage_releases', $plugin );
     161        }
     162
     163        /**
    111164         * Validate that the user can manage releases for the given plugin.
     165         *
     166         * @param \WP_REST_Request $request The Rest API Request.
     167         * @return bool True if the user may manage the plugin's releases.
    112168         */
    113169        public function permission_can_access_plugin( $request ) {
    114                 $plugin = Plugin_Directory::get_plugin_post( $request['plugin_slug'] );
    115 
    116                 if ( ! $plugin || ! current_user_can( 'plugin_manage_releases', $plugin ) ) {
     170                if ( ! $this->can_manage_releases( $request ) ) {
    117171                        return false;
    118172                }
    … …  
    130184                // Before we say no, check if the user just needs to validate their 2FA.
    131185                if ( $status && $status['needs_revalidate'] && 'GET' === $request->get_method() ) {
     186                        // The route's own nonce has to survive the trip through revalidation.
    132187                        $current_rest_url = add_query_arg(
    133188                                array(
    134                                         '_wpnonce'         => wp_create_nonce( 'wp_rest' ),
    135                                         '_wp_http_referer' => wp_get_referer(),
     189                                        '_wpnonce'               => wp_create_nonce( 'wp_rest' ),
     190                                        '_wp_http_referer'       => wp_get_referer(),
     191                                        self::ACTION_NONCE_PARAM => $request->get_param( self::ACTION_NONCE_PARAM ),
    136192                                ),
    137193                                get_rest_url( null, $request->get_route() )
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-self-close.php

    r12180 r15212  
    2323                                ],
    2424                        ],
    25                         'permission_callback' => function( $request ) {
    26                                 $plugin = Plugin_Directory::get_plugin_post( $request['plugin_slug'] );
    27 
    28                                 return current_user_can( 'plugin_self_close', $plugin );
    29                         },
     25                        'permission_callback' => [ $this, 'permission_check_action' ],
     26                        'wporg_capability'    => 'plugin_self_close',
     27                        'wporg_action'        => 'self_close',
    3028                ] );
    3129
    … …  
    4341                        if ( 'rest_cookie_invalid_nonce' == $result['code'] ) {
    4442                                wp_die( 'The link you have followed has expired.' );
    45                         } elseif ( 'rest_forbidden' == $result['code'] ) {
     43                        } elseif ( 'rest_forbidden' === $result['code'] || 'rest_cross_origin_write' === $result['code'] ) {
    4644                                wp_die( "Sorry, You can't do that." );
    4745                        }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-self-toggle-preview.php

    r14305 r15212  
    2323                                ],
    2424                        ],
    25                         'permission_callback' => function( $request ) {
    26                                 $plugin = Plugin_Directory::get_plugin_post( $request['plugin_slug'] );
    27 
    28                                 return current_user_can( 'plugin_toggle_public_preview', $plugin );
    29                         },
     25                        'permission_callback' => [ $this, 'permission_check_action' ],
     26                        'wporg_capability'    => 'plugin_toggle_public_preview',
     27                        'wporg_action'        => 'self_toggle_preview',
    3028                ] );
    3129
    … …  
    4341                        if ( 'rest_cookie_invalid_nonce' == $result['code'] ) {
    4442                                wp_die( 'The link you have followed has expired.' );
    45                         } elseif ( 'rest_forbidden' == $result['code'] ) {
     43                        } elseif ( 'rest_forbidden' === $result['code'] || 'rest_cross_origin_write' === $result['code'] ) {
    4644                                wp_die( "Sorry, You can't do that." );
    4745                        }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-self-transfer.php

    r11744 r15212  
    2828                                ]
    2929                        ],
    30                         'permission_callback' => function( $request ) {
    31                                 $plugin = Plugin_Directory::get_plugin_post( $request['plugin_slug'] );
    32 
    33                                 return current_user_can( 'plugin_self_transfer', $plugin );
    34                         },
     30                        'permission_callback' => [ $this, 'permission_check_action' ],
     31                        'wporg_capability'    => 'plugin_self_transfer',
     32                        'wporg_action'        => 'self_transfer',
    3533                ] );
    3634
    … …  
    4846                        if ( 'rest_cookie_invalid_nonce' == $result['code'] ) {
    4947                                wp_die( 'The link you have followed has expired.' );
    50                         } elseif ( 'rest_forbidden' == $result['code'] ) {
     48                        } elseif ( 'rest_forbidden' === $result['code'] || 'rest_cross_origin_write' === $result['code'] ) {
    5149                                wp_die( "Sorry, You can't do that." );
    5250                        }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-support-reps.php

    r11373 r15212  
    3939                                'methods'             => WP_REST_Server::CREATABLE,
    4040                                'callback'            => array( $this, 'add_support_rep' ),
    41                                 'permission_callback' => function( $request ) {
    42                                         return current_user_can(
    43                                                 'plugin_add_support_rep',
    44                                                 Plugin_Directory::get_plugin_post( $request['plugin_slug'] )
    45                                         );
    46                                 },
     41                                'permission_callback' => array( $this, 'permission_check_action' ),
     42                                'wporg_capability'    => 'plugin_add_support_rep',
     43                                'wporg_action'        => 'add_support_rep',
    4744                                'args'                => array(
    4845                                        'plugin_slug' => array(
    … …  
    5754                        'methods'             => WP_REST_Server::DELETABLE,
    5855                        'callback'            => array( $this, 'remove_support_rep' ),
    59                         'permission_callback' => function( $request ) {
    60                                 return current_user_can(
    61                                         'plugin_remove_support_rep',
    62                                         Plugin_Directory::get_plugin_post( $request['plugin_slug'] )
    63                                 );
    64                         },
     56                        'permission_callback' => array( $this, 'permission_check_action' ),
     57                        'wporg_capability'    => 'plugin_remove_support_rep',
     58                        'wporg_action'        => 'remove_support_rep',
    6559                        'args'                => array(
    6660                                'plugin_slug' => array(
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-upload.php

    r15166 r15212  
    6060                }
    6161
    62                 return true;
     62                return $this->verify_action_nonce( $request, 'upload', $post->ID );
    6363        }
    6464
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php

    r15190 r15212  
    11<?php
    22namespace WordPressdotorg\Plugin_Directory;
     3
     4use WordPressdotorg\Plugin_Directory\API\Base;
    35
    46// Explicitly require dependencies so this file can be sourced outside the Plugin Directory.
    … …  
    949951
    950952                return add_query_arg(
    951                         array( '_wpnonce' => wp_create_nonce( 'wp_rest' ) ),
     953                        array(
     954                                '_wpnonce'               => wp_create_nonce( 'wp_rest' ),
     955                                Base::ACTION_NONCE_PARAM => Base::action_nonce( 'self_close', $post->post_name ),
     956                        ),
    952957                        home_url( 'wp-json/plugins/v1/plugin/' . $post->post_name . '/self-close' )
    953958                );
    … …  
    964969
    965970                return add_query_arg(
    966                         array( '_wpnonce' => wp_create_nonce( 'wp_rest' ) ),
     971                        array(
     972                                '_wpnonce'               => wp_create_nonce( 'wp_rest' ),
     973                                Base::ACTION_NONCE_PARAM => Base::action_nonce( 'self_transfer', $post->post_name ),
     974                        ),
    967975                        home_url( 'wp-json/plugins/v1/plugin/' . $post->post_name . '/self-transfer' )
    968976                );
    … …  
    979987
    980988                return add_query_arg(
    981                         array( '_wpnonce' => wp_create_nonce( 'wp_rest' ) ),
     989                        array(
     990                                '_wpnonce'               => wp_create_nonce( 'wp_rest' ),
     991                                Base::ACTION_NONCE_PARAM => Base::action_nonce( 'self_toggle_preview', $post->post_name ),
     992                        ),
    982993                        home_url( 'wp-json/plugins/v1/plugin/' . $post->post_name . '/self-toggle-preview' )
    983994                );
    … …  
    9941005
    9951006                return add_query_arg(
    996                         array( '_wpnonce' => wp_create_nonce( 'wp_rest' ), 'dismiss' => 1 ),
     1007                        array(
     1008                                '_wpnonce'               => wp_create_nonce( 'wp_rest' ),
     1009                                Base::ACTION_NONCE_PARAM => Base::action_nonce( 'self_toggle_preview', $post->post_name ),
     1010                                'dismiss'                => 1,
     1011                        ),
    9971012                        home_url( 'wp-json/plugins/v1/plugin/' . $post->post_name . '/self-toggle-preview' )
    9981013                );
    … …  
    10091024
    10101025                return add_query_arg(
    1011                         array( '_wpnonce' => wp_create_nonce( 'wp_rest' ) ),
     1026                        array(
     1027                                '_wpnonce'               => wp_create_nonce( 'wp_rest' ),
     1028                                Base::ACTION_NONCE_PARAM => Base::action_nonce( 'enable_release_confirmation', $post->post_name ),
     1029                        ),
    10121030                        home_url( 'wp-json/plugins/v1/plugin/' . $post->post_name . '/release-confirmation' )
    10131031                );
    … …  
    10271045                if ( 'approve' === $what ) {
    10281046                        $endpoint = 'plugin/%s/release-confirmation/%s';
     1047                        $action   = 'confirm_release';
    10291048                } elseif ( 'discard' === $what ) {
    10301049                        $endpoint = 'plugin/%s/release-confirmation/%s/discard';
     1050                        $action   = 'discard_release';
    10311051                } elseif ( 'undo-discard' === $what ) {
    10321052                        $endpoint = 'plugin/%s/release-confirmation/%s/undo-discard';
     1053                        $action   = 'undo_discard_release';
    10331054                } else {
    10341055                        return '';
    … …  
    10381059
    10391060                return add_query_arg(
    1040                         array( '_wpnonce' => wp_create_nonce( 'wp_rest' ) ),
     1061                        array(
     1062                                '_wpnonce'               => wp_create_nonce( 'wp_rest' ),
     1063                                Base::ACTION_NONCE_PARAM => Base::action_nonce( $action, $post->post_name . ':' . $tag ),
     1064                        ),
    10411065                        $url
    10421066                );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/js/edit-form.js

    r14779 r15212  
    210210                        data.append( $file.prop( 'name' ), file_input.files[0] );
    211211                        data.append( 'admin', true );
     212                        data.append( '_wporg_action', pluginDirectory.uploadNonce );
    212213
    213214                        wp.apiRequest( {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload.php

    r15188 r15212  
    11<?php
    22namespace WordPressdotorg\Plugin_Directory\Shortcodes;
     3use WordPressdotorg\Plugin_Directory\API\Base;
    34use WordPressdotorg\Plugin_Directory\Template;
    45use function WordPressdotorg\Two_Factor\get_onboarding_account_url;
    … …  
    306307                                                                                <input type="hidden" name="action" value="request-slug-change" />
    307308                                                                                <input type="hidden" name="id" value="<?php echo esc_attr( $plugin->ID ); ?>" />
     309                                                                                <input type="hidden" name="<?php echo esc_attr( Base::ACTION_NONCE_PARAM ); ?>" value="<?php echo esc_attr( Base::action_nonce( 'upload', $plugin->ID ) ); ?>" />
    308310
    309311                                                                                <div class="notice notice-info notice-alt">
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets/class-committers.php

    r15188 r15212  
    22namespace WordPressdotorg\Plugin_Directory\Widgets;
    33
     4use WordPressdotorg\Plugin_Directory\API\Base;
    45use WordPressdotorg\Plugin_Directory\Tools;
    56
    … …  
    3940                                'restUrl'            => get_rest_url(),
    4041                                'restNonce'          => wp_create_nonce( 'wp_rest' ),
     42                                'addNonce'           => Base::action_nonce( 'add_committer', $post->post_name ),
     43                                'removeNonce'        => Base::action_nonce( 'remove_committer', $post->post_name ),
    4144                                'pluginSlug'         => $post->post_name,
    4245                                'removeCommitterAYS' => __( 'Are you sure you want to remove %s as a committer?', 'wporg-plugins' ),
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets/class-support-reps.php

    r15188 r15212  
    22namespace WordPressdotorg\Plugin_Directory\Widgets;
    33
     4use WordPressdotorg\Plugin_Directory\API\Base;
    45use WordPressdotorg\Plugin_Directory\Tools;
    56
    … …  
    4041                                'restUrl'             => get_rest_url(),
    4142                                'restNonce'           => wp_create_nonce( 'wp_rest' ),
     43                                'addNonce'            => Base::action_nonce( 'add_support_rep', $post->post_name ),
     44                                'removeNonce'         => Base::action_nonce( 'remove_support_rep', $post->post_name ),
    4245                                'pluginSlug'          => $post->post_name,
    4346                                'removeSupportRepAYS' => __( 'Are you sure you want to remove %s as a support rep?', 'wporg-plugins' ),
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets/js/committers.js

    r13633 r15212  
    3838                                        $this.addClass( 'spinner' );
    3939       
    40                                         url = pluginDir.restUrl + 'plugins/v1/plugin/' + pluginDir.pluginSlug + '/committers/' + user_id + '/?_wpnonce=' + pluginDir.restNonce;
     40                                        url = pluginDir.restUrl + 'plugins/v1/plugin/' + pluginDir.pluginSlug + '/committers/' + user_id + '/?_wpnonce=' + pluginDir.restNonce
     41                                        + '&_wporg_action=' + pluginDir.removeNonce;
    4142       
    4243                                        $.post( {
    … …  
    5758                                                $newUserInput = $row.find( 'input[name="committer"]' ),
    5859                                                $button = $row.find( '.button-small' ).addClass( 'spinner' ),
    59                                                 url = pluginDir.restUrl + 'plugins/v1/plugin/' + pluginDir.pluginSlug + '/committers/?_wpnonce=' + pluginDir.restNonce;
     60                                                url = pluginDir.restUrl + 'plugins/v1/plugin/' + pluginDir.pluginSlug + '/committers/?_wpnonce=' + pluginDir.restNonce
     61                                                + '&_wporg_action=' + pluginDir.addNonce;
    6062       
    6163                                        $.post( {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets/js/support-reps.js

    r13633 r15212  
    3838                                $this.addClass( 'spinner' );
    3939
    40                                 url = pluginDir.restUrl + 'plugins/v1/plugin/' + pluginDir.pluginSlug + '/support-reps/' + user_id + '/?_wpnonce=' + pluginDir.restNonce;
     40                                url = pluginDir.restUrl + 'plugins/v1/plugin/' + pluginDir.pluginSlug + '/support-reps/' + user_id + '/?_wpnonce=' + pluginDir.restNonce
     41                                        + '&_wporg_action=' + pluginDir.removeNonce;
    4142
    4243                                $.post( {
    … …  
    5758                                        $newUserInput = $row.find( 'input[name="support_rep"]' ),
    5859                                        $button = $row.find( '.button-small' ).addClass( 'spinner' ),
    59                                         url = pluginDir.restUrl + 'plugins/v1/plugin/' + pluginDir.pluginSlug + '/support-reps/?_wpnonce=' + pluginDir.restNonce;
     60                                        url = pluginDir.restUrl + 'plugins/v1/plugin/' + pluginDir.pluginSlug + '/support-reps/?_wpnonce=' + pluginDir.restNonce
     61                                                + '&_wporg_action=' + pluginDir.addNonce;
    6062
    6163                                $.post( {
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins-2024/functions.php

    r15109 r15212  
    1010namespace WordPressdotorg\Plugin_Directory\Theme;
    1111
     12use WordPressdotorg\Plugin_Directory\API\Base;
    1213use WordPressdotorg\Plugin_Directory\Plugin_Directory;
    1314use WordPressdotorg\Plugin_Directory\Template;
    … …  
    110111                        wp_enqueue_script( 'wporg-plugins-categorization', get_stylesheet_directory_uri() . '/js/section-categorization.js', array( 'jquery' ), filemtime( __DIR__ . '/js/section-categorization.js' ), true );
    111112                        wp_localize_script( 'wporg-plugins-categorization', 'categorizationOptions', [
    112                                 'restUrl'    => get_rest_url(),
    113                                 'restNonce'  => wp_create_nonce( 'wp_rest' ),
    114                                 'pluginSlug' => $post->post_name,
     113                                'restUrl'     => get_rest_url(),
     114                                'restNonce'   => wp_create_nonce( 'wp_rest' ),
     115                                'actionNonce' => Base::action_nonce( 'save_categorization', $post->post_name ),
     116                                'pluginSlug'  => $post->post_name,
    115117                        ] );
    116118                }
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins-2024/js/section-categorization.js

    r12346 r15212  
    3434                let fieldInput = form.querySelector( 'input[name="' + field_name + '"]' ),
    3535                        button = form.querySelector( '.button-small' )?.classList.add( 'spinner' ),
    36                         url = pluginDir.restUrl + 'plugins/v1/plugin/' + pluginDir.pluginSlug + '/' + form.id + '/?_wpnonce=' + pluginDir.restNonce;
     36                        url = pluginDir.restUrl + 'plugins/v1/plugin/' + pluginDir.pluginSlug + '/' + form.id + '/?_wpnonce=' + pluginDir.restNonce
     37                                + '&_wporg_action=' + pluginDir.actionNonce,
    3738                        originalValue = fieldInput.dataset.originalValue ?? '';
    3839
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins-2024/js/upload.js

    r14979 r15212  
    1414                        type: 'PATCH',
    1515                        data: {
    16                                 post_name: slug
     16                                post_name: slug,
     17                                _wporg_action: $form.find('input[name="_wporg_action"]').val()
    1718                        }
    1819                } )
Note: See TracChangeset for help on using the changeset viewer.