Skip to content
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
27 changes: 27 additions & 0 deletions assets/js/backend/create-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
var params = {
action: 'super_get_element_builder_html',
nonce: super_create_form_i18n.admin_nonce,
tag: obj.$el.data('shortcode'),
group: obj.$el.data('group'),
predefined: $predefined,
Expand All @@ -957,6 +958,14 @@
});
};

// Returns true (and informs the user) when the server or a firewall rejected a builder request
SUPER.builder_request_rejected = function (xhr) {
var body = (typeof xhr.responseText === 'string' ? xhr.responseText.trim() : '');
if (xhr.status == 200 && body !== '-1' && body !== '0') return false;
alert(super_create_form_i18n.request_rejected.replace('%s', xhr.status));
return true;
};

SUPER.save_form = function ($this, $method, $button, $initial_i18n, callback, updatingRawFormCode) {
var i,ii,
form = document.querySelector('.super-preview-elements'),
Expand Down Expand Up @@ -1008,6 +1017,13 @@
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4) {
if (SUPER.builder_request_rejected(this)) {
$('.super-create-form .super-actions .super-save').html('<i class="fas fa-save"></i>Save');
if ($method == 1) $('.super-create-form .super-actions .super-preview:eq(3)').html('Preview');
if ($method == 3) $('.super-preview-elements, .super-form-settings').removeClass('super-loading');
if ($method == 2 && typeof callback === "function") callback();
return false;
}
// Success:
if (this.status == 200) {
$('.super-create-form .super-actions .super-save').html('<i class="fas fa-save"></i>Save');
Expand Down Expand Up @@ -1110,6 +1126,12 @@
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4) {
if (SUPER.builder_request_rejected(this)) {
$('.super-live-preview').removeClass('super-loading').css('display', 'none');
$('.super-tabs-content').css('display', '');
$this.html('Preview').removeClass('super-active');
return false;
}
// Success:
if (this.status == 200) {
$('.super-live-preview').removeClass('super-loading');
Expand All @@ -1133,6 +1155,7 @@
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
var params = {
action: 'super_load_preview',
nonce: super_create_form_i18n.admin_nonce,
form_id: $form_id
};
params = $.param(params);
Expand Down Expand Up @@ -1743,6 +1766,7 @@
url: ajaxurl,
data: {
action: 'super_switch_language',
nonce: super_create_form_i18n.admin_nonce,
form_id: $('.super-create-form input[name="form_id"]').val(),
i18n: $i18n
},
Expand Down Expand Up @@ -1949,6 +1973,7 @@
url: ajaxurl,
data: {
action: 'super_undo_redo',
nonce: super_create_form_i18n.admin_nonce,
form_id: $('.super-create-form input[name="form_id"]').val(),
elements: JSON.stringify($history[$index])
},
Expand Down Expand Up @@ -2545,6 +2570,7 @@
}
var params = {
action: 'super_get_element_builder_html',
nonce: super_create_form_i18n.admin_nonce,
tag: $tag,
group: $group,
builder: ($tag == 'tabs' ? $builder : 0),
Expand Down Expand Up @@ -2738,6 +2764,7 @@
}
var params = {
action: 'super_load_element_settings',
nonce: super_create_form_i18n.admin_nonce,
form_id: $('.super-create-form input[name="form_id"]').val(),
tag: $tag,
group: $group,
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

## Unreleased

- **Security fix:** The form builder's preview, language switch, undo/redo, element settings and element HTML requests now require an administrator and a valid security token, so other logged-in users can no longer load form markup or settings.
- **Fix:** When the builder's save or preview request is rejected (for example after the session expired or a security plugin blocked it), the button is restored and a message asks you to reload the page instead of staying on "Saving..." forever.
- **Fix:** PDF Generator font data (Cyrillic and Arabic) is now attached to the Super Forms common script, so it still loads when a JavaScript optimization plugin reorders or delays scripts.
- **Fix:** PDF Generator "Enable debug mode" now only downloads the PDF and no longer submits the form, so no entry is saved and no e-mails are sent.
- **Fix:** When the PDF cannot be created, a message is shown and the visitor can close it and try again, instead of the form staying on "Generating PDF file..." forever. Nothing is submitted in that case.
Expand Down
17 changes: 16 additions & 1 deletion includes/class-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,8 @@ public static function language_switcher() {
* @since 4.7.0
*/
public static function switch_language() {
self::authorize_admin_ajax_request();
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- guarded by SUPER_Ajax::authorize_admin_ajax_request() (manage_options + check_ajax_referer('super_admin_ajax'))
$form_id = absint($_POST['form_id']);
// Retrieve all settings with the correct default values
$settings = SUPER_Common::get_form_settings($form_id);
Expand Down Expand Up @@ -849,6 +851,8 @@ public static function print_custom_html() {
* @since 3.8.0
*/
public static function undo_redo() {
self::authorize_admin_ajax_request();
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- guarded by SUPER_Ajax::authorize_admin_ajax_request() (manage_options + check_ajax_referer('super_admin_ajax'))
$form_id = absint($_POST['form_id']);
$elements = $_POST['elements'];
$shortcodes = SUPER_Shortcodes::shortcodes();
Expand Down Expand Up @@ -2983,7 +2987,10 @@ public static function import_global_settings() {
* @since 1.0.0
*/
public static function load_preview() {
$form_id = absint( $_POST['form_id'] );
self::authorize_admin_ajax_request();
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- guarded by SUPER_Ajax::authorize_admin_ajax_request() (manage_options + check_ajax_referer('super_admin_ajax'))
$form_id = isset( $_POST['form_id'] ) ? absint( $_POST['form_id'] ) : 0;
self::require_admin_form( $form_id );
echo SUPER_Shortcodes::super_form_func( array( 'id'=>$form_id ) );
die();
}
Expand Down Expand Up @@ -3300,6 +3307,10 @@ public static function loop_over_element_setting_fields($fields, $data, $shortco
* @since 1.0.0
*/
public static function load_element_settings( $tag=null, $group=null, $data=null ) {
// Only the builder AJAX request is guarded; internal PHP calls pass their own arguments
if( doing_action( 'wp_ajax_super_load_element_settings' ) ) {
self::authorize_admin_ajax_request();
}
if($tag==null) $tag = $_POST['tag'];
if($group==null) $group = $_POST['group'];
if($data==null) $data = $_POST['data'];
Expand Down Expand Up @@ -3448,6 +3459,10 @@ public static function load_element_settings( $tag=null, $group=null, $data=null
* @since 1.0.0
*/
public static function get_element_builder_html( $tag=null, $group=null, $inner=null, $data=null, $method=1 ) {
// Only the builder AJAX request is guarded; internal PHP calls pass their own arguments
if( doing_action( 'wp_ajax_super_get_element_builder_html' ) ) {
self::authorize_admin_ajax_request();
}
$i18n = (isset($_POST['i18n']) ? $_POST['i18n'] : '');
$form_id = 0;
if( isset( $_POST['form_id'] ) ) {
Expand Down
2 changes: 2 additions & 0 deletions super-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -3622,6 +3622,8 @@ public static function get_scripts() {
'localize'=> array(
'save_form_nonce' => wp_create_nonce( 'super_save_form' ),
'admin_nonce' => wp_create_nonce( 'super_admin_ajax' ),
/* translators: %s: HTTP status code of the rejected request */
'request_rejected' => esc_html__( 'The request was rejected (HTTP %s). Your session may have expired or a security plugin blocked it. Please reload the page and try again.', 'super-forms' ),
'not_editing_an_element' => sprintf( esc_html__( 'You are currently not editing an element.%sEdit any alement by clicking the %s icon.', 'super-forms' ), '<br />', '<i class="fa fa-pencil"></i>' ),
'no_backups_found' => esc_html__( 'No backups found...', 'super-forms' ),
'confirm_reset' => esc_html__( 'Are you sure you want to reset all the form settings according to your current global settings?', 'super-forms' ),
Expand Down
Loading
Loading