PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
← All changes | includes/process-donation.php +35 -12 4.16.7.14.16.9 View file →
@@ -23,10 +23,11 @@
23 23 *
24 24 * Handles the donation form process.
25 25 *
26 26 * @access private
27 - * @since 4.16.6 Bail early when the form ID is not a give_forms post or is a Visual Form Builder (v3) form.
28 - * @since 3.16.1 Use give_maybe_safe_unserialize() on $user_info data
27 + * @since 4.16.7.2 Reject serialized data in name fields before storing donation data.
28 + * @since 4.16.6 Bail early when the form ID is not a give_forms post or is a Visual Form Builder (v3) form.
29 + * @since 3.16.1 Use give_maybe_safe_unserialize() on $user_info data
29 30 * @since 1.0
30 31 *
31 32 * @throws ReflectionException Exception Handling.
32 33 *
@@ -162,8 +163,21 @@
162 163 'last_name' => $user['user_last'],
163 164 'address' => $user['address'],
164 165 ];
165 166
167 + // Reject serialized data in name fields.
168 + $serialized_keys = array_filter(
169 + $user_info,
170 + static function ( $value ) {
171 + return is_string( $value ) && \Give\Helpers\Utils::isSerialized( $value );
172 + }
173 + );
174 +
175 + if ( ! empty( $serialized_keys ) ) {
176 + give_set_error( 'give_serialized_user_info', esc_html__( 'Name fields cannot contain serialized data.', 'give' ) );
177 + return;
178 + }
179 +
166 180 $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
167 181
168 182 // Donation form ID.
169 183 $form_id = isset( $post_data['give-form-id'] ) ? absint( $post_data['give-form-id'] ) : 0;
@@ -196,9 +210,9 @@
196 210 $purchase_key
197 211 );
198 212
199 213 // Setup donation information.
200 - $user_info = array_map('\Give\Helpers\Utils::maybeSafeUnserialize', stripslashes_deep( $user_info ));
214 + $user_info = stripslashes_deep( $user_info );
201 215 $donation_data = [
202 216 'price' => $price,
203 217 'purchase_key' => $purchase_key,
204 218 'user_email' => $user['user_email'],
@@ -873,8 +887,9 @@
873 887 /**
874 888 * Donation Form Validate Logged In User.
875 889 *
876 890 * @access private
891 + * @since 4.16.7.2 Sanitize first and last name values when falling back to stored user data.
877 892 * @since 1.0
878 893 *
879 894 * @return array
880 895 */
@@ -908,13 +923,13 @@
908 923 'user_email' => ! empty( $post_data['give_email'] )
909 924 ? sanitize_email( $post_data['give_email'] )
910 925 : $user_data->user_email,
911 926 'user_first' => ! empty( $post_data['give_first'] )
912 - ? $post_data['give_first']
913 - : $user_data->first_name,
927 + ? give_clean( $post_data['give_first'] )
928 + : give_clean( $user_data->first_name ),
914 929 'user_last' => ! empty( $post_data['give_last'] )
915 - ? $post_data['give_last']
916 - : $user_data->last_name,
930 + ? give_clean( $post_data['give_last'] )
931 + : give_clean( $user_data->last_name ),
917 932 ];
918 933
919 934 // Validate essential form fields.
920 935 give_donation_form_validate_name_fields( $post_data );
@@ -1673,11 +1688,12 @@
1673 1688 * Validates and checks if name fields are valid or not.
1674 1689 *
1675 1690 * @param array $post_data List of post data.
1676 1691 *
1677 - * @since 3.16.5 Check if "give_title" is set to prevent PHP warnings
1678 - * @since 3.16.4 Add additional validation for company name field
1679 - * @since 3.16.3 Add additional validations for name title prefix field
1692 + * @since 4.16.7.2 Validate last name field even when omitted.
1693 + * @since 3.16.5 Check if "give_title" is set to prevent PHP warnings
1694 + * @since 3.16.4 Add additional validation for company name field
1695 + * @since 3.16.3 Add additional validations for name title prefix field
1680 1696 * @since 2.1
1681 1697 *
1682 1698 * @return void
1683 1699 */
@@ -1697,11 +1713,18 @@
1697 1713 give_set_error( 'invalid_name_title', esc_html__( 'The name title prefix field is not valid.', 'give' ) );
1698 1714 }
1699 1715
1700 1716 $is_alpha_first_name = ( ! is_email( $post_data['give_first'] ) && ! preg_match( '~[0-9]~', $post_data['give_first'] ) );
1701 - $is_alpha_last_name = ( ! is_email( $post_data['give_last'] ) && ! preg_match( '~[0-9]~', $post_data['give_last'] ) );
1717 +
1718 + $lastName = isset( $post_data['give_last'] ) ? $post_data['give_last'] : '';
1719 + $is_alpha_last_name = ( ! is_email( $lastName ) && ! preg_match( '~[0-9]~', $lastName ) );
1720 +
1702 1721 $is_alpha_title = ( isset($post_data['give_title']) && ! is_email( $post_data['give_title'] ) && ! preg_match( '~[0-9]~', $post_data['give_title'] ) );
1703 1722
1704 - if (!$is_alpha_first_name || ( ! empty( $post_data['give_last'] ) && ! $is_alpha_last_name) || ( ! empty( $post_data['give_title'] ) && ! $is_alpha_title) ) {
1723 + if ( ! $is_alpha_first_name || ( ! empty( $lastName ) && ! $is_alpha_last_name ) || ( ! empty( $post_data['give_title'] ) && ! $is_alpha_title ) ) {
1705 1724 give_set_error( 'invalid_name', esc_html__( 'The First Name and Last Name fields cannot contain an email address or numbers.', 'give' ) );
1725 + }
1726 +
1727 + if ( give_is_last_name_required( $formId ) && empty( $lastName ) ) {
1728 + give_set_error( 'invalid_last_name', esc_html__( 'Please enter your last name.', 'give' ) );
1706 1729 }
1707 1730 }