Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix - Escaping issue #1365

Merged
merged 5 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions assets/js/admin/form-builder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* global evf_data, jconfirm, PerfectScrollbar, evfSetClipboard, evfClearClipboard */
(function ( $, evf_data ) {

var $builder;

var EVFPanelBuilder = {
Expand All @@ -19,10 +18,25 @@
}

//To remove script tag.
$(document).on('input','.everest-forms-field-option-row-choices input[name$="[label]"]',function (e) {
$(document).on('input change','.everest-forms-field-option-row-choices input[name$="[label]"]',function (e) {
var $value = $(this).val();
$(this).val($value.replace(/<\s*script/gi, '').replace(/\s+on\w+\s*=/gi, ' '));
});

$(document).on('input change', 'input[name$="[required-field-message]"]', function (e) {
var $value = $(this).val();

const htmlTagPattern = /<[^>]*>/;
const htmlEntityPattern = /&[a-zA-Z0-9#]+;/;

if (htmlTagPattern.test($value) || htmlEntityPattern.test($value)) {
$(this).val('');
} else {
$(this).val($value.replace(/<\s*script/gi, '').replace(/\s+on\w+\s*=/gi, ' '));
}

});

});

$( document ).ready( function( $ ) {
Expand Down
17 changes: 10 additions & 7 deletions includes/shortcodes/class-evf-shortcode-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,11 @@
$likert_rows = isset( $field['likert_rows'] ) ? $field['likert_rows'] : array();
$row_keys = array();
foreach ( $likert_rows as $row_key => $row_label ) {
$row_keys[] = $row_key;
$row_slug = 'required-field-message-' . $row_key;
$sub_field_messages[ $row_key ] = isset( $field[ $row_slug ] ) ? evf_string_translation( $form_data['id'], $field['id'], $field[ $row_slug ], '-' . $row_slug ) : $required_validation;
$row_keys[] = $row_key;
$row_slug = 'required-field-message-' . $row_key;

$error_message = isset( $field[ $row_slug ] ) ? evf_string_translation( $form_data['id'], $field['id'], $field[ $row_slug ], '-' . $row_slug ) : $required_validation;
$sub_field_messages[ $row_key ] = esc_attr( wp_strip_all_tags( html_entity_decode( $error_message ) ) );
}
$container_data['row-keys'] = wp_json_encode( $row_keys );
} elseif ( 'address' === $field['type'] ) {
Expand All @@ -754,16 +756,17 @@

if ( true === $has_sub_fields ) {
foreach ( $sub_field_messages as $sub_field_type => $error_message ) {
$container_data[ 'required-field-message-' . $sub_field_type ] = $error_message;
$container_data[ 'required-field-message-' . $sub_field_type ] = esc_attr( wp_strip_all_tags( html_entity_decode( $error_message ) ) );
}
} else {

Check failure on line 761 in includes/shortcodes/class-evf-shortcode-form.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4 , WP Latest)

If control structure block found as the only statement within an "else" block. Use elseif instead.

if ( isset( $field['required_field_message_setting'] ) && 'global' === $field['required_field_message_setting'] ) {

$container_data['required-field-message'] = $required_validation;
} elseif ( isset( $field['required-field-message'] ) && '' !== $field['required-field-message'] ) {
$container_data['required-field-message'] = evf_string_translation( $form_data['id'], $field['id'], $field['required-field-message'], '-required-field-message' );
$required_data = evf_string_translation( $form_data['id'], $field['id'], $field['required-field-message'], '-required-field-message' );
$container_data['required-field-message'] = esc_attr( wp_strip_all_tags( html_entity_decode( $required_data ) ) );
} else {
$container_data['required-field-message'] = $required_validation;
$container_data['required-field-message'] = esc_attr( wp_strip_all_tags( html_entity_decode( $required_validation ) ) );
}
}
}
Expand Down
Loading