[0] Application
From the README of the module (github.com/shoppingflux/module-prestashop):
« Synchronize stocks, prices, products feed and orders from or to marketplace
available on ShoppingFeed »
Shoppingfeed is a PrestaShop module written by 202 ecommerce for Shoppingfeed. It
pushes the catalog of a shop to the marketplaces and brings the orders back. The
catalog leaves the shop as an XML feed, served by a front controller of the
module (controllers/front/product.php) that Shoppingfeed fetches over HTTP. A
feed is selected by a token passed in the URL, and the tokens live in the
shoppingfeed_token table.
We found the issue at Wargan during an audit ordered by Shoppingfeed and 202 ecommerce. It is fixed in 1.8.3, released the same day, and it was made public on 2023/04/18 as CVE-2023-28839.
[I] The vulnerability
A) Overview
The feed controller takes the token parameter of the request and looks it up in
the database with a query built by string concatenation. The controller is a
public page of the shop (it has to be, Shoppingfeed calls it from outside), so
anyone can reach the query and change it. The answer of the page tells whether
the query returned a row, which is enough to read the database one bit at a time.
B) Required data
The URL of a shop that runs the module in a version from 1.4.0 to 1.8.2. No account and no valid token are needed.
C) Explanation
The controller reads the parameter and hands it to findByToken
(controllers/front/product.php, 1.8.2):
public function initContent()
{
$token = Tools::getValue('token');
if (empty($token)) {
$token = (new ShoppingfeedToken())->getDefaultToken();
} else {
$token = (new ShoppingfeedToken())->findByToken($token);
}
if ($token === false) {
exit();
}
Tools::getValue reads the value from POST or GET and does not escape anything
for SQL. findByToken puts it between two single quotes
(classes/ShoppingfeedToken.php:136-145):
public function findByToken($token)
{
$query = (new DbQuery())
->select('*')
->from(self::$definition['table'])
->where("content = '$token'")
;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($query);
}
DbQuery::where appends the string as it is. A single quote in token closes
the literal and the rest of the value is SQL.
The code is the same in 1.4.0, the release that introduced the token table and this controller (1.3.1 has neither).
D) Exploitation
The controller answers in two different ways. When the query returns no row it
stops at exit() and the body is empty. When the query returns a row it goes on
and sends the XML feed of that row. A condition appended to the query therefore
shows in the answer:
/index.php?fc=module&module=shoppingfeed&controller=product&token=x' OR '1'='1 -> the XML feed
/index.php?fc=module&module=shoppingfeed&controller=product&token=x' OR '1'='2 -> empty answer
Replacing the constant condition with a subquery gives a boolean oracle on any table the database user of the shop can read. (The first request is also a way to get a product feed without knowing its token.)
E) Consequences
An anonymous visitor can read the database of the shop: customers, addresses,
orders, and the employee table with the password hashes of the back office
accounts. The advisory published by Friends of Presta rates it 9.8
(CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H) and lists admin access and data
removal among the possible uses.
[II] Mitigation
1. Escape the token before it reaches the query. PrestaShop has pSQL() for
this, and the same class already goes through ObjectModel for its writes, which
escapes the fields on its own.
The fix in 1.8.3. One line, the one recommended above
(classes/ShoppingfeedToken.php):
- ->where("content = '$token'")
+ ->where('content = "' . pSQL($token) . '"')
Upgrade the module to 1.8.3 or later.
[III] Timeline
2022/10/14: Vulnerability found during an audit ordered by Shoppingfeed and 202 ecommerce, Shoppingfeed 1.8.3 released the same day 2023/04/18: Advisory published by Friends of Presta, CVE-2023-28839 2026/11/30: This page made public
[IV] Author
John JEAN is a French security researcher, CTO at Wargan (https://www.wargan.com).
Follow me on X @johnjean
[V] PGP
My current PGP key is 0xDC3CB82BF0967AF0, you can get it on the Work with me page.