Skip to content

Added prepare statement when building where clause#2365

Merged
harunollyo merged 7 commits into
devfrom
prepare_where_clause
Feb 17, 2026
Merged

Added prepare statement when building where clause#2365
harunollyo merged 7 commits into
devfrom
prepare_where_clause

Conversation

@Anindra123
Copy link
Copy Markdown
Collaborator

Overview

As a part of security fix in 3.9.4, where sql injection was possible through the coupon_code parameter a fix was added where esc_sql was called to remove any kind of sql injection, however this was not the correct fix. The correct fix is using prepare statement in prepare_where_clause method where any user value can be passed. Therefore, I have updated the method specifically the make_clause method that is being used in prepare_where_clause only, which creates the final clause, here i have checked whether the value is string or integer and added appropriate prepare statement for each type. I have also added some new unit test cases to check the prepare_where_clause output making sure it doesn't break the query.

Test Case Results

Screenshot 2026-02-09 at 5 44 05 PM

Comment thread helpers/QueryHelper.php
Comment thread helpers/QueryHelper.php Outdated
if ( in_array( $upper_operator, array( 'IN', 'NOT IN' ), true ) ) {
$value = '(' . self::prepare_in_clause( $value ) . ')';
} elseif ( in_array( $upper_operator, array( 'BETWEEN', 'NOT BETWEEN' ), true ) ) {
$values = explode( 'AND', $value );
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use it here

@harunollyo harunollyo merged commit 0bffd2d into dev Feb 17, 2026
10 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants