Skip to content

Commit 982741f

Browse files
Merge pull request #2189 from rtCamp/revert-2185-fix/nonce-verification-issues
Revert "Fix Nonce Verification flags in the Codebase"
2 parents 588f449 + e76957c commit 982741f

19 files changed

Lines changed: 35 additions & 62 deletions

app/admin/RTMediaAdmin.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,6 @@ public function ui( $hook ) {
779779
'RTMedia_Admin_Settings_JS',
780780
array(
781781
'rtmedia_default_sizes_error_message' => esc_html__( 'Invalid value for [default_size_property].', 'buddypress-media' ),
782-
'rtmedia_buddypress_convert_nonce' => wp_create_nonce( 'rtmedia_buddypress_convert_nonce' ),
783782
)
784783
);
785784

@@ -1350,7 +1349,7 @@ public function settings_sub_tabs() {
13501349
*/
13511350
public function save_multisite_options() {
13521351
global $rtmedia_admin;
1353-
do_action( 'rtmedia_sanitize_settings', wp_unslash( $_POST ) ); // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification, WordPress.Security.NonceVerification.Missing -- Nonce verification is handled by network_admin_edit_ action hook which requires valid nonce and proper capabilities.
1352+
do_action( 'rtmedia_sanitize_settings', wp_unslash( $_POST ) ); // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification, WordPress.Security.NonceVerification.Missing
13541353

13551354
$rtmedia_options = filter_input( INPUT_POST, 'rtmedia_options' );
13561355
if ( isset( $rtmedia_options ) ) {
@@ -1516,13 +1515,7 @@ public function import_settings( $file_path ) {
15161515
* Ajax callback function Convert videos mailchimp.
15171516
*/
15181517
public function convert_videos_mailchimp_send() {
1519-
$nonce = sanitize_text_field( wp_unslash( $_POST['wp_nonce'] ) );
1520-
1521-
if( ! wp_verify_nonce( $nonce, 'rtmedia_buddypress_convert_nonce' ) ) {
1522-
esc_html_e( 'Invalid Request.', 'buddypress-media' );
1523-
wp_die();
1524-
}
1525-
1518+
// todo: nonce required.
15261519
$interested = sanitize_text_field( filter_input( INPUT_POST, 'linkback', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) );
15271520
$choice = sanitize_text_field( filter_input( INPUT_POST, 'choice', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) );
15281521
$url = filter_input( INPUT_POST, 'url', FILTER_SANITIZE_URL );

app/admin/templates/settings/main.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
</div>
2525
<?php } ?>
2626
<input type="hidden" name="rtmedia-options-save" value="true">
27-
<?php wp_nonce_field( 'rtmedia_settings', 'wp_nonce' ); ?>
2827
<input type="submit" class="rtmedia-settings-submit button button-primary button-big" value="<?php esc_attr_e( 'Save Settings', 'buddypress-media' ); ?>">
2928
</div>
3029
<?php
@@ -56,7 +55,6 @@
5655
</div>
5756

5857
<input type="hidden" name="rtmedia-options-save" value="true">
59-
<?php wp_nonce_field( 'rtmedia_settings', 'wp_nonce' ); ?>
6058
<input type="submit" class="rtmedia-settings-submit button button-primary button-big" value="<?php esc_attr_e( 'Save Settings', 'buddypress-media' ); ?>">
6159
</div>
6260
</div>

app/assets/admin/js/settings.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -810,10 +810,8 @@ jQuery( document ).ready( function ( $ ) {
810810
email: jQuery( '.email' ).val(),
811811
url: jQuery( '.url' ).val(),
812812
choice: jQuery( 'input[name="choice"]:checked' ).val(),
813-
interested: jQuery( 'input[name="interested"]:checked' ).val(),
814-
wp_nonce: RTMedia_Admin_Settings_JS?.rtmedia_buddypress_convert_nonce ?? ''
813+
interested: jQuery( 'input[name="interested"]:checked' ).val()
815814
};
816-
817815
jQuery.post( ajaxurl, data, function ( response ) {
818816
var p_data = {
819817
msg :response,

app/assets/js/rtMedia.backbone.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ jQuery(function ($) {
256256
backbone: true,
257257
is_album: o_is_album,
258258
is_edit_allowed: o_is_edit_allowed,
259-
wp_nonce: rtmedia_backbone_strings?.rtmedia_album_gallery_nonce,
260259
},
261260
function () {
262261
rtmedia_load_template_flag = false;

app/helper/RTMediaSettings.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,12 @@ class RTMediaSettings {
2020
* @access public
2121
*/
2222
public function __construct() {
23-
23+
// todo: nonce required.
2424
if ( ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
2525
add_action( 'admin_init', array( $this, 'settings' ) );
2626

27-
$rtmedia_option_save = filter_input( INPUT_POST, 'rtmedia-options-save', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification, WordPress.Security.NonceVerification.Missing -- Not required since we are only checking if it is a save action.
27+
$rtmedia_option_save = filter_input( INPUT_POST, 'rtmedia-options-save', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
2828
if ( isset( $rtmedia_option_save ) ) {
29-
30-
if( ! isset( $_POST ) || !array_key_exists( 'wp_nonce', $_POST ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['wp_nonce'] ) ), 'rtmedia_settings' ) ) {
31-
return;
32-
}
33-
3429
add_action( 'init', array( $this, 'settings' ) );
3530
}
3631
}
@@ -213,15 +208,15 @@ public function sanitize_before_save_options( $options ) {
213208
* @return void
214209
*/
215210
public function settings() {
216-
211+
// todo: nonce required.
217212
global $rtmedia, $rtmedia_addon, $rtmedia_save_setting_single;
218213
$options = rtmedia_get_site_option( 'rtmedia-options' );
219214
$options = $this->sanitize_options( $options );
220215
$rtmedia->options = $options;
221216
// Save Settings first then proceed.
222-
$rtmedia_option_save = filter_input( INPUT_POST, 'rtmedia-options-save', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification, WordPress.Security.NonceVerification.Missing -- Not required since it is the responsibility of caller function to verify nonce.
217+
$rtmedia_option_save = filter_input( INPUT_POST, 'rtmedia-options-save', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
223218
if ( isset( $rtmedia_option_save ) && current_user_can( 'manage_options' ) ) {
224-
$options = filter_input( INPUT_POST, 'rtmedia-options', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification, WordPress.Security.NonceVerification.Missing -- Not required since it is the responsibility of caller function to verify nonce.
219+
$options = filter_input( INPUT_POST, 'rtmedia-options', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
225220
$options = $this->sanitize_before_save_options( $options );
226221
$options = apply_filters( 'rtmedia_pro_options_save_settings', $options );
227222
$is_rewrite_rule_flush = apply_filters( 'rtmedia_flush_rewrite_rule', false );
@@ -231,7 +226,7 @@ public function settings() {
231226
flush_rewrite_rules( false );
232227
}
233228
$settings_saved = '';
234-
$setting_save = filter_input( INPUT_GET, 'settings-saved', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification, WordPress.Security.NonceVerification.Missing -- Not required since it is the responsibility of caller function to verify nonce.
229+
$setting_save = filter_input( INPUT_GET, 'settings-saved', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
235230
if ( ! isset( $setting_save ) ) {
236231
$settings_saved = '&settings-saved=true';
237232
}
@@ -410,7 +405,7 @@ public function sanitize( $input ) {
410405
rtmedia_update_site_option( 'rtm-settings-saved', esc_html__( 'Settings saved.', 'buddypress-media' ) );
411406
}
412407

413-
do_action( 'rtmedia_sanitize_settings', $_POST, $input ); // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification, WordPress.Security.NonceVerification.Missing -- Not required since this function is responsible only for sanitization of data.
408+
do_action( 'rtmedia_sanitize_settings', $_POST, $input ); // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification, WordPress.Security.NonceVerification.Missing
414409

415410
return $input;
416411
}

app/helper/RTMediaSupport.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function render_support( $page = '' ) {
179179
* @return void
180180
*/
181181
public function service_selector() {
182-
// phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification, WordPress.Security.NonceVerification.Missing -- Not required since we are only checking which tab is checked in the settings.
182+
// todo: nonce required.
183183
$form = filter_input( INPUT_POST, 'form', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
184184

185185
include RTMEDIA_PATH . 'app/helper/templates/service-sector.php';
@@ -411,9 +411,9 @@ public function migration_html( $page = '' ) {
411411
* @return void
412412
*/
413413
public function get_form( $form = '' ) {
414-
414+
// todo: nonce required.
415415
if ( empty( $form ) ) {
416-
$form = filter_input( INPUT_POST, 'form' . FILTER_SANITIZE_FULL_SPECIAL_CHARS ); // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification, WordPress.Security.NonceVerification.Missing -- Not required since we are only checking which tab is selected and send the form for it.
416+
$form = filter_input( INPUT_POST, 'form' . FILTER_SANITIZE_FULL_SPECIAL_CHARS );
417417
$form = isset( $form ) ? $form : 'premium_support';
418418
}
419419
$meta_title = '';

app/main/RTMedia.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,15 +1121,16 @@ public static function load_translation() {
11211121
* @return bool
11221122
*/
11231123
public function check_global_album() {
1124+
// todo: Nonce required.
11241125
$album = new RTMediaAlbum();
11251126
$global_album = $album->get_default();
11261127

1127-
$action = sanitize_text_field( filter_input( INPUT_POST, 'action', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.NoNonceVerification -- We are just intercepting if a action is for a different kind of upload and removing a field based on it.
1128-
$mode = sanitize_text_field( filter_input( INPUT_POST, 'mode', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.NoNonceVerification -- We are just intercepting if a action is for a different kind of upload and removing a field based on it.
1128+
$action = sanitize_text_field( filter_input( INPUT_POST, 'action', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) );
1129+
$mode = sanitize_text_field( filter_input( INPUT_POST, 'mode', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) );
11291130

11301131
// Hack for plupload default name.
11311132
if ( ! empty( $action ) && ! empty( $mode ) && 'file_upload' === $mode ) {
1132-
unset( $_POST['name'] ); // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification, WordPress.Security.NonceVerification.Missing -- We are removing the value from the $_POST.
1133+
unset( $_POST['name'] ); // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification, WordPress.Security.NonceVerification.Missing
11331134
}
11341135

11351136
global $rtmedia_error;
@@ -1490,8 +1491,7 @@ public function enqueue_scripts_styles() {
14901491

14911492
// Localizing strings for rtMedia.backbone.js.
14921493
$rtmedia_backbone_strings = array(
1493-
'rtm_edit_file_name' => esc_html__( 'Edit File Name', 'buddypress-media' ),
1494-
'rtmedia_album_gallery_nonce' => wp_create_nonce( 'rtmedia_album_gallery' ),
1494+
'rtm_edit_file_name' => esc_html__( 'Edit File Name', 'buddypress-media' ),
14951495
);
14961496

14971497
// Localise fot rtmedia-backcone js.

app/main/controllers/activity/RTMediaBuddyPressActivity.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,8 @@ public function bp_before_activity_post_update_parse_args( $args ) {
14931493
// if content is non-breaking space then set it to empty.
14941494
if ( isset( $args['content'] ) && '' === $args['content'] ) {
14951495

1496-
if ( ! empty( $_POST['rtMedia_attached_files'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Not needed since we are only checking if the field exists and it is done already.
1496+
// Nonce verification is not required here as it is already done in previously.
1497+
if ( ! empty( $_POST['rtMedia_attached_files'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
14971498
$args['content'] = '&nbsp;';
14981499
}
14991500
}

app/main/controllers/api/RTMediaJsonApi.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,11 +1082,11 @@ public function rtmedia_api_process_update_avatar_request() {
10821082
$ec_avatar_updated = 130003;
10831083
$msg_avatar_updated = esc_html__( 'avatar updated', 'buddypress-media' );
10841084

1085-
if ( empty( $_FILES['file'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Not needed since we are only checking if the value exists.
1085+
if ( empty( $_FILES['file'] ) ) {
10861086
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_no_file, $msg_no_file ) );
10871087
}
10881088

1089-
$uploaded = bp_core_avatar_handle_upload( $_FILES, 'xprofile_avatar_upload_dir' ); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- It is verified by the external plugin function.
1089+
$uploaded = bp_core_avatar_handle_upload( $_FILES, 'xprofile_avatar_upload_dir' );
10901090
if ( ! $uploaded ) {
10911091
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_invalid_image, $msg_invalid_image ) );
10921092
} else {
@@ -1139,7 +1139,7 @@ public function rtmedia_api_process_rtmedia_upload_media_request() {
11391139
$updated = false;
11401140
$uploaded_look = false;
11411141

1142-
if ( empty( $rtmedia_file ) && empty( $_FILES['rtmedia_file'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- We are only checking presence of a data.
1142+
if ( empty( $rtmedia_file ) && empty( $_FILES['rtmedia_file'] ) ) {
11431143
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_no_file, $msg_no_file ) );
11441144
}
11451145

@@ -1154,7 +1154,7 @@ public function rtmedia_api_process_rtmedia_upload_media_request() {
11541154
}
11551155
}
11561156

1157-
if ( ! empty( $_FILES['rtmedia_file'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- We are only checking presence of a data.
1157+
if ( ! empty( $_FILES['rtmedia_file'] ) ) {
11581158
// phpcs:disable Squiz.PHP.DisallowMultipleAssignments.Found, WordPress.Security.NonceVerification.NoNonceVerification
11591159
$_POST['rtmedia_upload_nonce'] = $_REQUEST['rtmedia_upload_nonce'] = wp_create_nonce( 'rtmedia_upload_nonce' );
11601160
$_POST['rtmedia_simple_file_upload'] = $_REQUEST['rtmedia_simple_file_upload'] = 1;

app/main/controllers/group/RTMediaBuddyPressGroupActivity.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public function bp_before_groups_post_update_parse_args( $args ) {
3232
// if content is non-breaking space then set it to empty.
3333
if ( isset( $args['content'] ) && '' === $args['content'] ) {
3434

35-
if ( ! empty( $_POST['rtMedia_attached_files'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Not needed since we are only checking if the field exists and it is done already.
35+
// Nonce verification is not required here as it is already done in previously.
36+
if ( ! empty( $_POST['rtMedia_attached_files'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
3637
$args['content'] = '&nbsp;';
3738
}
3839
}

0 commit comments

Comments
 (0)