SQL Injection via ORDER BY Parameter
The orderBy parameter of an API endpoint was vulnerable to SQL injection, allowing an attacker to inject SQL syntax into the query. The author confirmed this by using a time-based technique with a PostgreSQL sleep function, showing that crafted queries reached the database.
Hi Guys In this blog post, I’ll share the details of an SQL Injection vulnerability I discovered while exploring a web application.
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 the application concatenated the orderBy parameter directly into a SQL query without validating or parameterising it.
Impact
An attacker could inject arbitrary SQL into the orderBy parameter, potentially reading or modifying database data, though the text only demonstrates time-based confirmation.
What the attacker needed
A free account; access to the categories API endpoint
The fix
The orderBy parameter should be validated against a whitelist of allowed column names and directions, or parameterised, rather than concatenated into the query.
How it was found
- Register on the platform and browse the site while monitoring requests with Burp Suite.
- Notice the API request for categories that includes an orderBy parameter.
- Modify the orderBy value to include SQL syntax and observe that the response changes.
- Experiment with different SQL syntax to confirm the injection and identify PostgreSQL.
- Use a time-based technique with a PostgreSQL sleep function to prove the query executes.
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 handling, so an attacker can change the query's meaning. Here, the orderBy parameter that sorts categories was not sanitised, letting the author add extra SQL commands. They proved it by making the database wait, which showed the injected command ran.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.