Skip to content

Commit 47eef5f

Browse files
authored
Merge pull request #225 from brainstormforce/fix/nonce-verification
fix: strengthen nonce verification across plugin
2 parents 5c25c7d + af8abbc commit 47eef5f

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ No, the plugin provides an easy-to-use interface where you can add schema markup
9797
4. Test the post or page URL in Google Rich Snippets Testing
9898

9999
## Changelog ##
100+
### 1.7.7 ###
101+
- Improvement: Added Security fixes.
102+
100103
### 1.7.6 ###
101104
- Improvement: Updated readme.txt.
102105

admin/index.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,41 +1170,52 @@ function display_status( $status ) {
11701170
if ( 'reset' == sanitize_text_field( wp_unslash( $_GET['action'] ) ) && isset( $_GET['nonce'] ) && current_user_can( 'manage_options' ) ) {
11711171
$option_to_reset = sanitize_text_field( wp_unslash( $_GET['options'] ) );
11721172
$nonce_value = sanitize_text_field( wp_unslash( $_GET['nonce'] ) );
1173+
$nonce_verified = false;
1174+
11731175
if ( 'review' == $option_to_reset && wp_verify_nonce( $nonce_value, 'aiosrs_item_nonce' ) ) {
11741176
delete_option( 'bsf_review' );
1177+
$nonce_verified = true;
11751178
}
11761179
if ( 'event' == $option_to_reset && wp_verify_nonce( $nonce_value, 'aiosrs_event_nonce' ) ) {
11771180
delete_option( 'bsf_event' );
1181+
$nonce_verified = true;
11781182
}
11791183
if ( 'person' == $option_to_reset && wp_verify_nonce( $nonce_value, 'aiosrs_person_nonce' ) ) {
11801184
delete_option( 'bsf_person' );
1185+
$nonce_verified = true;
11811186
}
1182-
11831187
if ( 'product' == $option_to_reset && wp_verify_nonce( $nonce_value, 'aiosrs_product_nonce' ) ) {
11841188
delete_option( 'bsf_product' );
1189+
$nonce_verified = true;
11851190
}
11861191
if ( 'recipe' == $option_to_reset && wp_verify_nonce( $nonce_value, 'aiosrs_recipe_nonce' ) ) {
11871192
delete_option( 'bsf_recipe' );
1193+
$nonce_verified = true;
11881194
}
11891195
if ( 'software' == $option_to_reset && wp_verify_nonce( $nonce_value, 'aiosrs_software_nonce' ) ) {
11901196
delete_option( 'bsf_software' );
1197+
$nonce_verified = true;
11911198
}
11921199
if ( 'video' == $option_to_reset && wp_verify_nonce( $nonce_value, 'aiosrs_video_nonce' ) ) {
11931200
delete_option( 'bsf_video' );
1201+
$nonce_verified = true;
11941202
}
1195-
11961203
if ( 'article' == $option_to_reset && wp_verify_nonce( $nonce_value, 'aiosrs_article_nonce' ) ) {
11971204
delete_option( 'bsf_article' );
1205+
$nonce_verified = true;
11981206
}
11991207
if ( 'service' == $option_to_reset && wp_verify_nonce( $nonce_value, 'aiosrs_service_nonce' ) ) {
12001208
delete_option( 'bsf_service' );
1209+
$nonce_verified = true;
12011210
}
1202-
12031211
if ( 'color' == $option_to_reset && wp_verify_nonce( $nonce_value, 'aiosrs_color_nonce' ) ) {
12041212
delete_option( 'bsf_custom' );
1213+
$nonce_verified = true;
12051214
}
12061215

1207-
bsf_reset_options( $option_to_reset );
1216+
if ( $nonce_verified ) {
1217+
bsf_reset_options( $option_to_reset );
1218+
}
12081219
}
12091220
}
12101221
/**

init.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function add_for_page_template( $display, $meta_box ) {
179179
public function show() {
180180
global $post;
181181
// Use nonce for verification.
182-
echo '<input type="hidden" name="wp_meta_box_nonce" value="', esc_attr( wp_create_nonce( basename( __FILE__ ) ) ), '" />';
182+
echo '<input type="hidden" name="wp_meta_box_nonce" value="', esc_attr( wp_create_nonce( 'bsf_meta_box_nonce_action' ) ), '" />';
183183
echo '<table class="form-table bsf_metabox">';
184184
foreach ( $this->_meta_box['fields'] as $field ) {
185185
// Set up blank or default values for empty ones.
@@ -452,7 +452,7 @@ public function show() {
452452
*/
453453
public function save( $post_id ) {
454454
// verify nonce.
455-
if ( ! isset( $_POST['wp_meta_box_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['wp_meta_box_nonce'] ) ), basename( __FILE__ ) ) ) {
455+
if ( ! isset( $_POST['wp_meta_box_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['wp_meta_box_nonce'] ) ), 'bsf_meta_box_nonce_action' ) ) {
456456
return $post_id;
457457
}
458458
// check autosave.
@@ -555,8 +555,8 @@ function bsf_scripts( $hook ) {
555555
'bsf-scripts',
556556
'bsf_ajax_data',
557557
array(
558-
'ajax_nonce' => wp_create_nonce( 'ajax_nonce' ),
559-
'post_id' => get_the_ID(),
558+
'bsf_meta_box_ajax_nonce' => wp_create_nonce( 'bsf_meta_box_ajax_nonce' ),
559+
'post_id' => get_the_ID(),
560560
)
561561
);
562562
wp_enqueue_script( 'bsf-timepicker' );
@@ -571,7 +571,7 @@ function bsf_scripts( $hook ) {
571571
*/
572572
function bsf_editor_footer_scripts() { ?>
573573
<?php
574-
if ( isset( $_GET['bsf_force_send'] ) && isset( $_GET['bsf_file_upload_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['bsf_file_upload_nonce'] ) ), 'ajax_nonce' ) && 'true' == sanitize_text_field( wp_unslash( $_GET['bsf_force_send'] ) ) ) {
574+
if ( isset( $_GET['bsf_force_send'] ) && isset( $_GET['bsf_file_upload_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['bsf_file_upload_nonce'] ) ), 'bsf_meta_box_ajax_nonce' ) && 'true' == sanitize_text_field( wp_unslash( $_GET['bsf_force_send'] ) ) ) {
575575
$label = sanitize_text_field( wp_unslash( $_GET['bsf_send_label'] ) );
576576
if ( empty( $label ) ) {
577577
$label = 'Select File';
@@ -595,7 +595,7 @@ function bsf_editor_footer_scripts() { ?>
595595
*/
596596
function bsf_force_send( $args ) {
597597

598-
if ( ! isset( $_GET['bsf_file_upload_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['bsf_file_upload_nonce'] ) ), 'ajax_nonce' ) ) {
598+
if ( ! isset( $_GET['bsf_file_upload_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['bsf_file_upload_nonce'] ) ), 'bsf_meta_box_ajax_nonce' ) ) {
599599
return $args;
600600
}
601601
// if the Gallery tab is opened from a custom meta box field, add Insert Into Post button.
@@ -644,15 +644,15 @@ function cmbGetParameterByNameInline(name) {
644644
*/
645645
function bsf_oembed_ajax_results() {
646646
// verify our nonce.
647-
if ( ! ( isset( $_REQUEST['bsf_ajax_nonce'], $_REQUEST['oembed_url'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['bsf_ajax_nonce'] ) ), 'ajax_nonce' ) ) ) {
648-
die();
647+
if ( ! ( isset( $_REQUEST['bsf_ajax_nonce'], $_REQUEST['oembed_url'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['bsf_ajax_nonce'] ) ), 'bsf_meta_box_ajax_nonce' ) ) ) {
648+
wp_send_json_error( __( 'Security check failed.', 'rich-snippets' ), 403 );
649649
}
650650
// verify capability.
651651
if ( ! current_user_can( 'edit_posts' ) ) {
652-
die();
652+
wp_send_json_error( __( 'Unauthorized access.', 'rich-snippets' ), 403 );
653653
}
654654
// sanitize our search string.
655-
$oembed_string = sanitize_text_field( $_REQUEST['oembed_url'] );
655+
$oembed_string = sanitize_text_field( wp_unslash( $_REQUEST['oembed_url'] ) );
656656
if ( empty( $oembed_string ) ) {
657657
$return = '<p class="ui-state-error-text">' . __( 'Please Try Again', 'rich-snippets' ) . '</p>';
658658
$found = 'not found';
@@ -669,7 +669,8 @@ function bsf_oembed_ajax_results() {
669669
$fallback = $wp_embed->maybe_make_link( $oembed_url );
670670
if ( $check_embed && $check_embed != $fallback ) {
671671
// Embed data.
672-
$return = '<div class="embed_status">' . $check_embed . '<a href="#" class="bsf_remove_file_button" rel="' . esc_attr( sanitize_text_field( wp_unslash( $_REQUEST['field_id'] ) ) ) . '">' . __( 'Remove Embed', 'rich-snippets' ) . '</a></div>';
672+
$field_id = isset( $_REQUEST['field_id'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['field_id'] ) ) : '';
673+
$return = '<div class="embed_status">' . $check_embed . '<a href="#" class="bsf_remove_file_button" rel="' . esc_attr( $field_id ) . '">' . __( 'Remove Embed', 'rich-snippets' ) . '</a></div>';
673674
// set our response id.
674675
$found = 'found';
675676
} else {
@@ -687,7 +688,7 @@ function bsf_oembed_ajax_results() {
687688
'id' => $found,
688689
)
689690
);
690-
die();
691+
wp_die();
691692
}
692693
// End. That's it, folks! //.
693694
?>

readme.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ No, the plugin provides an easy-to-use interface where you can add schema markup
9797
4. Test the post or page URL in Google Rich Snippets Testing
9898

9999
== Changelog ==
100+
### 1.7.7 ###
101+
- Improvement: Added Security fixes.
102+
100103
### 1.7.6 ###
101104
- Improvement: Updated readme.txt.
102105

0 commit comments

Comments
 (0)