Code audit
A bug in Magento's SQL condition builder allowed an attacker to inject SQL via the 'from' and 'to' parameters of a product synchronisation endpoint. This unauthenticated blind SQL injection could let an attacker read any data from the database, including admin sessions or password hashes.
ambionics.io
Published on ambionics.io
After attacking PrestaShop several months ago, my next target of choice was another eCommerce platform, Magento. This platform is one of the most used around the world, after WooCommerce, and it supported over $101 billion in digital commerce for customers last year.
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
The code reused the already-built 'from' SQL fragment as the format string for the 'to' condition, so any question mark in the 'from' value was replaced by the quoted 'to' value, breaking out of the SQL string.
Impact
An attacker could read any data from the database, including admin sessions or password hashes, and use them to access the backend.
What the attacker needed
Magento 2.2.0 to 2.3.0; no authentication required
The fix
The fix was to build the 'to' condition separately and then concatenate it, rather than reusing the 'from' query as a format string; Magento released patched versions.
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 escaping, letting an attacker change the query's meaning. Here, a coding mistake in how range conditions were built meant that a crafted value could break out of the intended SQL and run arbitrary database commands. Because the endpoint required no login, anyone could exploit it to steal sensitive data.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.