Parcel tracking builds its database query from raw input
Repository shop-backend · TrackingController.php (parcel tracking, no login)
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
Description
A recent change to the parcel tracking form pastes the visitor’s tracking number directly into the database query. The form needs no login, so any visitor can extend the query and read tables they should never see. The database account behind it can only read, which is why nothing can be changed.
Steps to reproduce
- Open the parcel tracking form on the shop page, without logging in.
- Follow the code: the entered tracking number goes straight into the database query.
- In the test system, confirm that a specially formed tracking number returns rows from the customer table.
TrackingController.php:41
$sql = "SELECT … WHERE tracking_no = '" . $input . "'";
Database account: shop_read (read-only) Business impact
Anyone on the internet can copy all customers’ addresses and order histories: a GDPR breach, reportable within 72 hours. Found in the code before release, it costs one line to fix.
Remediation
Use a parameterised query for the tracking number, and check that it matches the expected format. Search the code for other queries built from input. Add an automatic code check to the build that flags such queries.
OWASP Top 10 2021: A03 Injection · CWE-89 (SQL Injection) · OWASP ASVS 4.0 V5.3