Skip to content

Commit e6821ef

Browse files
authored
Nonce check order flaw in post-quickdraft-save
$_REQUEST['post_ID'] is used to load a post object before the referer is actually checked on line 93. A crafted request can cause a database lookup on an arbitrary post_ID before authorization. $_REQUEST['_wpnonce'] is also accessed without checking key existence.
1 parent e12ddb3 commit e6821ef

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/wp-admin/post.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,14 @@
7272
switch ( $action ) {
7373
case 'post-quickdraft-save':
7474
// Check nonce and capabilities.
75-
$nonce = $_REQUEST['_wpnonce'];
75+
$nonce = isset( $_REQUEST['_wpnonce'] ) ? $_REQUEST['_wpnonce'] : '';
76+
$post_id = absint( $_REQUEST['post_ID'] ?? 0 );
7677
$error_msg = false;
7778

7879
// For output of the Quick Draft dashboard widget.
7980
require_once ABSPATH . 'wp-admin/includes/dashboard.php';
8081

81-
if ( ! wp_verify_nonce( $nonce, 'add-post' ) ) {
82+
if ( ! $post_id || ! wp_verify_nonce( $nonce, 'add-post' ) ) {
8283
$error_msg = __( 'Unable to submit this form, please refresh and try again.' );
8384
}
8485

@@ -90,7 +91,14 @@
9091
return wp_dashboard_quick_press( $error_msg );
9192
}
9293

93-
$post = get_post( $_REQUEST['post_ID'] );
94+
$post = get_post( $post_id );
95+
if ( ! $post ) {
96+
$error_msg = __( 'Unable to submit this form, please refresh and try again.' );
97+
}
98+
99+
if ( $error_msg ) {
100+
return wp_dashboard_quick_press( $error_msg );
101+
}
94102
check_admin_referer( 'add-' . $post->post_type );
95103

96104
$_POST['comment_status'] = get_default_comment_status( $post->post_type );

0 commit comments

Comments
 (0)