Skip to content

Commit e7e11a5

Browse files
improve field sanitization
1 parent 2247605 commit e7e11a5

File tree

5 files changed

+45
-19
lines changed

5 files changed

+45
-19
lines changed

includes/classes/class-field-shortcodes.php

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ public function text_field( $atts ) {
4343
$atts,
4444
'text'
4545
);
46-
47-
$atts['name'] = sanitize_text_field( esc_attr( esc_html__($atts['name']) ) );
4846

47+
// sanitize name attribute before using it.
48+
$atts['name'] = $this->sanitize_and_escape( $atts['name'] );
49+
4950
// translators: %s: input field name to be entered by the user
5051
$name = sanitize_text_field( sprintf( esc_attr__( 'Enter %s', 'pff-paystack' ), $atts['name'] ) );
5152
$required = $atts['required'] === 'required' ? 'required' : '';
@@ -71,6 +72,7 @@ public function text_field( $atts ) {
7172
* @return string
7273
*/
7374
public function textarea_field( $atts ) {
75+
7476
$atts = shortcode_atts(
7577
array(
7678
'name' => esc_html__( 'Title', 'pff-paystack' ),
@@ -79,8 +81,8 @@ public function textarea_field( $atts ) {
7981
$atts,
8082
'textarea'
8183
);
82-
83-
$atts['name'] = sanitize_text_field( esc_attr( esc_html__($atts['name']) ) );
84+
// sanitize name attribute before using it
85+
$atts['name'] = $this->sanitize_and_escape( $atts['name'] );
8486

8587
// translators: %s: textarea field to be entered by the user
8688
$name = sanitize_text_field( sprintf( esc_attr__( 'Enter %s', 'pff-paystack' ), $atts['name'] ) );
@@ -160,10 +162,10 @@ public function input_field( $atts ) {
160162
$atts,
161163
'input'
162164
);
163-
164-
$atts['name'] = sanitize_text_field( esc_attr( esc_html__($atts['name']) ) );
165-
165+
166+
$atts['name'] = $this->sanitize_and_escape( $atts['name'] );
166167
$name = sanitize_text_field( $atts['name'] );
168+
167169
$required = $atts['required'] === 'required' ? 'required' : '';
168170
$fileInputId = uniqid( 'file-input-' );
169171
$textInputId = uniqid( 'text-input-' );
@@ -201,9 +203,10 @@ public function datepicker_field( $atts ) {
201203
$atts,
202204
'datepicker'
203205
);
204-
205-
$atts['name'] = sanitize_text_field( esc_attr( esc_html__($atts['name']) ) );
206206

207+
// sanitize name attribute before using it
208+
$atts['name'] = $this->sanitize_and_escape( $atts['name'] );
209+
207210
// translators: %s: datepicker field to be selected by the user
208211
$name = sanitize_text_field( sprintf( esc_attr__( 'Enter %s', 'pff-paystack' ), $atts['name'] ) );
209212
$required = $atts['required'] === 'required' ? 'required' : '';
@@ -238,7 +241,6 @@ public function select_field( $atts ) {
238241
$atts,
239242
'select'
240243
);
241-
$atts['name'] = sanitize_text_field( esc_attr( esc_html__($atts['name']) ) );
242244

243245
$name = sanitize_text_field( $atts['name'] );
244246
$options = array_map( 'sanitize_text_field', explode( ',', $atts['options'] ) );
@@ -280,9 +282,7 @@ public function radio_field( $atts ) {
280282
$atts,
281283
'radio'
282284
);
283-
284-
$atts['name'] = sanitize_text_field( esc_attr( esc_html__($atts['name']) ) );
285-
285+
286286
$name = sanitize_text_field( $atts['name'] );
287287
$options = array_map( 'sanitize_text_field', explode( ',', $atts['options'] ) );
288288
$required = $atts['required'] === 'required' ? 'required' : '';
@@ -311,4 +311,24 @@ public function radio_field( $atts ) {
311311

312312
return $code;
313313
}
314-
}
314+
315+
/**
316+
* Sanitize and escape a string for safe HTML output.
317+
*
318+
* @param string $value The input string to sanitize and escape.
319+
* @return string The sanitized and escaped string.
320+
*/
321+
private function sanitize_and_escape( $value ) {
322+
// Remove all HTML tags, including malformed ones
323+
$value = wp_kses( $value, array() );
324+
325+
// Replace backticks with single quotes
326+
$value = str_replace( '`', '`', $value );
327+
328+
// Sanitize the string for safe database storage
329+
$value = sanitize_text_field( $value );
330+
331+
// Escape the string for safe HTML output
332+
return esc_html( $value );
333+
}
334+
}

includes/classes/class-settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public function is_option_selected( $value, $compare ) {
193193
}
194194

195195
/**
196-
* Checks to see if the curren value is selected.
196+
* Sanitises the field name
197197
*
198198
* @param string $value
199199
* /

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pff-paystack",
3-
"version": "4.0.2",
3+
"version": "4.0.3",
44
"description": "Paystack Payment forms for WordPress",
55
"main": "gulpfile.js",
66
"scripts": {

paystack-forms.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: Payment Forms for Paystack
44
Plugin URI: https://github.com/PaystackHQ/Wordpress-Payment-forms-for-Paystack
55
Description: Payment Forms for Paystack allows you create forms that will be used to bill clients for goods and services via Paystack.
6-
Version: 4.0.2
6+
Version: 32
77
Author: Paystack
88
Author URI: http://paystack.com
99
License: GPL-2.0+
@@ -16,7 +16,7 @@
1616
define( 'PFF_PAYSTACK_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
1717
define( 'PFF_PAYSTACK_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
1818
define( 'PFF_PAYSTACK_MAIN_FILE', __FILE__ );
19-
define( 'PFF_PAYSTACK_VERSION', '4.0.2' );
19+
define( 'PFF_PAYSTACK_VERSION', '4.0.3' );
2020
define( 'PFF_PAYSTACK_TABLE', 'paystack_forms_payments' );
2121
define( 'PFF_PLUGIN_BASENAME', plugin_basename(__FILE__) );
2222
define( 'PFF_PLUGIN_NAME', 'pff-paystack' );

readme.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Donate link: https://paystack.com/demo
44
Tags: paystack, recurrent payments, donation, forms, payments
55
Requires at least: 5.0
66
Tested up to: 6.7
7-
Stable tag: 4.0.2
7+
Stable tag: 4.0.3
88
Requires PHP: 7.4
99
License: GPLv2 or later
1010
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -91,6 +91,12 @@ If you get stuck, you can ask for help in the [Payment Forms for Paystack Plugin
9191
Yes you can! Join in on our [GitHub repository](https://github.com/PaystackOSS/plugin-payment-forms-for-wordpress) :)
9292

9393
== Changelog ==
94+
= 4.0.4 =
95+
* Add better sanitization to form fields
96+
97+
= 4.0.3 =
98+
* Security update - Add extra sanitization to form fields
99+
94100
= 4.0.2 =
95101
* Security Update - Adding in sanitization to the Payments List order variable.
96102

0 commit comments

Comments
 (0)