Skip to content

Commit 7e4f0b7

Browse files
committed
Add nonce verification to revocation
1 parent aefc0c4 commit 7e4f0b7

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

inc/admin/profile/namespace.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function render_token_row( WP_User $user, Access_Token $token ) {
8585
sprintf(
8686
'<button class="button" name="oauth2_revoke" title="%s" value="%s">%s</button>',
8787
$button_title,
88-
esc_attr( $token->get_key() ),
88+
wp_create_nonce( 'oauth2_revoke:' . $token->get_key() ) . ':' . esc_attr( $token->get_key() ),
8989
esc_html__( 'Revoke', 'oauth2' )
9090
),
9191
];
@@ -138,7 +138,18 @@ function handle_revocation( $user_id ) {
138138
return;
139139
}
140140

141-
$key = wp_unslash( $_POST['oauth2_revoke'] );
141+
$data = wp_unslash( $_POST['oauth2_revoke'] ); // WPCS: CSRF OK
142+
if ( strpos( $data, ':' ) === null ) {
143+
return;
144+
}
145+
146+
// Split out nonce and check it.
147+
list( $nonce, $key ) = explode( ':', $data, 2 );
148+
if ( ! wp_verify_nonce( $nonce, 'oauth2_revoke:' . $key ) ) {
149+
wp_nonce_ays( 'oauth2_revoke' );
150+
die();
151+
}
152+
142153
$token = Access_Token::get_by_id( $key );
143154
if ( empty( $token ) ) {
144155
var_dump( $key, $token );

0 commit comments

Comments
 (0)