Skip to content

Commit

Permalink
regenerate nonce to bypass possible cached page
Browse files Browse the repository at this point in the history
  • Loading branch information
RensTillmann committed Jan 27, 2022
1 parent c19d65a commit f429159
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 65 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

- [PDF Generator Add-on](https://renstillmann.github.io/super-forms/#/pdf-generator-add-on)

## Jan 27, 2022 - Version 6.0.5

- **Fix:** Regenerate nonce for sites that use cache

## Jan 26, 2022 - Version 6.0.4

- **Fix:** When `editing` is enabled for a `Listings` (Listings Add-on) make sure the styles/scripts are loaded so that normal form functions and styles are applied
Expand Down
151 changes: 89 additions & 62 deletions src/assets/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -3381,21 +3381,22 @@ function SUPERreCaptcha(){
}else{
clearInterval(completeSubmitInterval);
// Prepare arguments
var formData = SUPER.prepare_form_data($(args.form)); // returns {data:$data, form_id:$form_id, entry_id:$entry_id, list_id:$list_id};
args = {
event: args.event,
form: args.form,
data: formData.data,
form_id: formData.form_id,
entry_id: formData.entry_id,
list_id: formData.list_id,
oldHtml: oldHtml,
sf_nonce: formData.sf_nonce
};
args.callback = function(){
SUPER.complete_submit(args);
};
SUPER.before_submit_hook(args);
SUPER.prepare_form_data($(args.form), function(formData){
args = {
event: args.event,
form: args.form,
data: formData.data,
form_id: formData.form_id,
entry_id: formData.entry_id,
list_id: formData.list_id,
oldHtml: oldHtml,
sf_nonce: formData.sf_nonce
};
args.callback = function(){
SUPER.complete_submit(args);
};
SUPER.before_submit_hook(args);
});
}
}, 100);

Expand Down Expand Up @@ -3685,17 +3686,18 @@ function SUPERreCaptcha(){
clearTimeout(SUPER.save_form_progress_timeout);
}
SUPER.save_form_progress_timeout = setTimeout(function () {
var $data = SUPER.prepare_form_data($(args.form));
var $form_id = $data.form_id;
$data = SUPER.after_form_data_collected_hook($data.data);
$.ajax({
url: super_common_i18n.ajaxurl,
type: 'post',
data: {
action: 'super_save_form_progress',
data: $data,
form_id: $form_id
}
SUPER.prepare_form_data($(args.form), function(formData){
var $form_id = formData.form_id;
formData = SUPER.after_form_data_collected_hook(formData.data);
$.ajax({
url: super_common_i18n.ajaxurl,
type: 'post',
data: {
action: 'super_save_form_progress',
data: formData,
form_id: $form_id
}
});
});
}, 1000);
// 1 second timeout, to make sure that we do not make unnecessary requests to the server
Expand Down Expand Up @@ -4065,7 +4067,7 @@ function SUPERreCaptcha(){
};

// @since 3.2.0 - prepare form data
SUPER.prepare_form_data = function($form){
SUPER.prepare_form_data = function($form, callback){
var $data = SUPER.prepare_form_data_fields($form),
$form_id = '',
$entry_id = '',
Expand Down Expand Up @@ -4137,13 +4139,37 @@ function SUPERreCaptcha(){
if($form.find('input[name="hidden_list_id"]').length !== 0) {
$list_id = $form.find('input[name="hidden_list_id"]').val();
}
return {
data:$data,
form_id:$form_id,
entry_id:$entry_id,
list_id:$list_id,
sf_nonce: $form.find('input[name="sf_nonce"]').val()
};

// Generate new nonce
$.ajax({
url: super_common_i18n.ajaxurl,
type: 'post',
data: {
action: 'super_create_nonce'
},
success: function (nonce) {
// Update new nonce
$('input[name="sf_nonce"]').val(nonce);
},
complete: function(){
if(typeof callback === 'function'){
callback({
data:$data,
form_id:$form_id,
entry_id:$entry_id,
list_id:$list_id,
sf_nonce: $form.find('input[name="sf_nonce"]').val()
});
}

},
error: function (xhr, ajaxOptions, thrownError) {
// eslint-disable-next-line no-console
console.log(xhr, ajaxOptions, thrownError);
alert('Could not generate nonce');
}
});

};

// @since 1.3
Expand Down Expand Up @@ -5648,33 +5674,34 @@ function SUPERreCaptcha(){
if( $print_file && $print_file.value!=='' && $print_file.value!='0' ) {
// @since 3.9.0 - print custom HTML
$file_id = $print_file.value;
$data = SUPER.prepare_form_data($(args.form));
$data = SUPER.after_form_data_collected_hook($data.data);
$.ajax({
url: super_common_i18n.ajaxurl,
type: 'post',
data: {
action: 'super_print_custom_html',
data: $data,
file_id: $file_id
},
success: function (result) {
win.document.write(result);
win.document.close();
win.focus();
// @since 2.3 - chrome browser bug
setTimeout(function() {
win.print();
win.close();
}, 250);
return false;
},
error: function (xhr, ajaxOptions, thrownError) {
// eslint-disable-next-line no-console
console.log(xhr, ajaxOptions, thrownError);
alert(super_common_i18n.errors.failed_to_process_data);
return false;
}
SUPER.prepare_form_data($(args.form), function(formData){
formData = SUPER.after_form_data_collected_hook(formData.data);
$.ajax({
url: super_common_i18n.ajaxurl,
type: 'post',
data: {
action: 'super_print_custom_html',
data: formData,
file_id: $file_id
},
success: function (result) {
win.document.write(result);
win.document.close();
win.focus();
// @since 2.3 - chrome browser bug
setTimeout(function() {
win.print();
win.close();
}, 250);
return false;
},
error: function (xhr, ajaxOptions, thrownError) {
// eslint-disable-next-line no-console
console.log(xhr, ajaxOptions, thrownError);
alert(super_common_i18n.errors.failed_to_process_data);
return false;
}
});
});
}else{
$css = "<style type=\"text/css\">";
Expand Down Expand Up @@ -8153,7 +8180,7 @@ function SUPERreCaptcha(){
});
};


jQuery(document).ready(function ($) {

var $doc = $(document);
Expand Down
4 changes: 4 additions & 0 deletions src/docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

- [PDF Generator Add-on](https://renstillmann.github.io/super-forms/#/pdf-generator-add-on)

## Jan 27, 2022 - Version 6.0.5

- **Fix:** Regenerate nonce for sites that use cache

## Jan 26, 2022 - Version 6.0.4

- **Fix:** When `editing` is enabled for a `Listings` (Listings Add-on) make sure the styles/scripts are loaded so that normal form functions and styles are applied
Expand Down
2 changes: 1 addition & 1 deletion src/includes/class-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -5945,7 +5945,7 @@ public static function super_form_func( $atts, $elements_only=false ) {

// @since 4.7.0 - translation langauge switcher
if(empty($settings['i18n_switch'])) $settings['i18n_switch'] = 'false';
if($settings['i18n_switch']=='true'){
if(empty($i18n) && $settings['i18n_switch']=='true'){
$translations = SUPER_Common::get_form_translations($form_id);
if(!empty($translations) && is_array($translations) && count($translations)>1 ){
wp_enqueue_style( 'super-flags', SUPER_PLUGIN_FILE . 'assets/css/frontend/flags.css', array(), SUPER_VERSION );
Expand Down
4 changes: 2 additions & 2 deletions src/super-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @wordpress-plugin
* Plugin Name: Super Forms - Drag & Drop Form Builder
* Description: The most advanced, flexible and easy to use form builder for WordPress!
* Version: 6.0.4
* Version: 6.0.5
* Plugin URI: http://f4d.nl/super-forms
* Author URI: http://f4d.nl/super-forms
* Author: feeling4design
Expand Down Expand Up @@ -43,7 +43,7 @@ final class SUPER_Forms {
*
* @since 1.0.0
*/
public $version = '6.0.4';
public $version = '6.0.5';
public $slug = 'super-forms';
public $apiUrl = 'https://api.super-forms.com/';
public $apiVersion = 'v1';
Expand Down

0 comments on commit f429159

Please sign in to comment.