Skip to content

Commit 827a977

Browse files
authored
Merge pull request #865 from wpdev10/master
Fix security issue in register form builder reorder fields
2 parents 68beb46 + fa19d21 commit 827a977

14 files changed

Lines changed: 149 additions & 117 deletions

admin/assets/js/uwp-form-builder.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,10 @@
206206
*/
207207
updateFieldOrder: function ($sortable) {
208208
const manageFieldType = $sortable.closest('#uwp-selected-fields').find(".manage_field_type").val();
209+
const nonce = $sortable.closest('#uwp-selected-fields').find(".uwp_create_field_nonce").val();
209210
const order = $sortable.sortable("serialize") + '&update=update&manage_field_type=' + manageFieldType;
210211
const formId = $('[name="manage_field_form_id"]').val();
211-
const formIdParam = '&form_id=' + formId;
212+
const formIdParam = '&form_id=' + formId + '&_wpnonce=' + nonce;
212213
const actionType = UWP.Form_Builder.getActionType(manageFieldType);
213214
const action = actionType.action;
214215

admin/assets/js/uwp-form-builder.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

admin/settings/class-formbuilder.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,7 @@ public function custom_selected_fields( $form_type ) {
11071107
?>
11081108
<input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/>
11091109
<input type="hidden" name="manage_field_type" class="manage_field_type" value="custom_fields">
1110+
<input type="hidden" name="uwp_create_field_nonce" class="uwp_create_field_nonce" value="<?php echo wp_create_nonce( 'uwp_create_field_nonce' ); ?>"/>
11101111
<ul class="core uwp-tabs-selected uwp_form_extras ps-0 list-group">
11111112
<?php
11121113
// Retrieve fields saved with form id 0.
@@ -1852,6 +1853,7 @@ public function register_selected_fields( $form_type ) {
18521853
$form_id = self::get_form_id()
18531854
?>
18541855
<input type="hidden" name="manage_field_type" class="manage_field_type" value="register">
1856+
<input type="hidden" name="uwp_create_field_nonce" class="uwp_create_field_nonce" value="<?php echo wp_create_nonce( 'uwp_create_field_nonce' ); ?>"/>
18551857
<ul class="core uwp_form_extras uwp-tabs-selected ps-0 list-group ">
18561858
<?php
18571859

@@ -2522,7 +2524,10 @@ public function create_field() {
25222524

25232525
/* ------- check nonce field ------- */
25242526
if ( isset( $_REQUEST['update'] ) && $_REQUEST['update'] == 'update' && isset( $_REQUEST['create_field'] ) && isset( $_REQUEST['manage_field_type'] ) && $_REQUEST['manage_field_type'] == 'custom_fields' ) {
2525-
echo $this->set_field_order( $field_ids, $form_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2527+
if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp_create_field_nonce' ) ) {
2528+
return;
2529+
}
2530+
echo $this->set_field_order( $field_ids, $form_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
25262531
}
25272532

25282533
/* ---- Show field form in admin ---- */
@@ -3211,8 +3216,12 @@ public function register_ajax_handler() {
32113216
$field_id = isset( $_REQUEST['field_id'] ) ? trim( sanitize_text_field( $_REQUEST['field_id'] ), '_' ) : '';
32123217
$field_action = isset( $_REQUEST['field_ins_upd'] ) ? sanitize_text_field( $_REQUEST['field_ins_upd'] ) : '';
32133218

3214-
/* ------- check nonce field ------- */
3215-
if ( isset( $_REQUEST['update'] ) && $_REQUEST['update'] == 'update' ) {
3219+
/* ------- update order of fields ------- */
3220+
if ( isset( $_REQUEST['update'] ) && $_REQUEST['update'] == 'update' && isset( $_REQUEST['_wpnonce'] )) {
3221+
if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp_create_field_nonce' ) ) {
3222+
return;
3223+
}
3224+
32163225
$field_ids = array();
32173226
if ( ! empty( $_REQUEST['licontainer'] ) && is_array( $_REQUEST['licontainer'] ) ) {
32183227
foreach ( $_REQUEST['licontainer'] as $lic_id ) {

admin/settings/class-uwp-settings-user-sorting.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
if ( ! class_exists( 'UsersWP_Settings_User_Sorting', false ) ) {
1616

1717
/**
18-
* UsersWP_Settings_Email.
18+
* UsersWP_Settings_User_Sorting.
1919
*/
2020
class UsersWP_Settings_User_Sorting {
2121

languages/userswp-en_US.mo

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)