Skip to content
SQL injection Write-up Intermediate

Patch analysis

An unauthenticated SQL injection existed in WooCommerce and WooCommerce Blocks, allowing an attacker to inject SQL commands via a URL parameter. The attacker could execute arbitrary SQL, as demonstrated by a time-based sleep payload.

blog.wpsec.com

Published on blog.wpsec.com

On 15th July 2021, news was going around regarding an unauthenticated SQL Injection in WooCommerce. WooCommerce released a blog post about the vulnerabilities here: https://woocommerce.com/posts/critical-vulnerability-detected-july-2021/#.

Jonas Lejon, on blog.wpsec.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely insufficient sanitisation of the taxonomy parameter before it is used in a SQL query, as the patch added sanitisation via wc_sanitize_taxonomy_name.

Impact

An unauthenticated attacker could execute arbitrary SQL commands, potentially leading to data theft or modification.

What the attacker needed

Vulnerable WooCommerce version; no authentication required

The fix

The vulnerability was fixed in WooCommerce versions 3.3.6 to 5.5.1 and WooCommerce Blocks versions 2.5.16 to 5.5.1 by adding sanitisation.

How it was found

  1. Set up a WordPress site with a vulnerable version of WooCommerce.
  2. Identify the API route /wp-json/wc/store/products/collection-data.
  3. Craft a URL with a triple URL-encoded SQL payload in the calculate_attribute_counts parameter.
  4. Send the request and observe the time delay confirming SQL 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 write-up has not been written yet. The Original tab links to the source.

SQL injection is when user input is inserted into a database query without proper cleaning, letting an attacker change the query's meaning. Here, a URL parameter was not properly sanitised, so an attacker could add extra SQL code to make the database wait, proving the injection works.

What is SQL injection?

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.

Similar reports

View all

Same bug class and techniques, clearest first.

SQL injection

The lesson behind this report.

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.