Skip to content
SQL injection Write-up Intermediate

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.

mfthylmaz Follow

Published on medium.com

Hi Guys In this blog post, I’ll share the details of an SQL Injection vulnerability I discovered while exploring a web application.

mfthylmaz, on medium.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 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

  1. Register on the platform and browse the site while monitoring requests with Burp Suite.
  2. Notice the API request for categories that includes an orderBy parameter.
  3. Modify the orderBy value to include SQL syntax and observe that the response changes.
  4. Experiment with different SQL syntax to confirm the injection and identify PostgreSQL.
  5. 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.

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.