Skip to content
SQL injection Disclosed report Intermediate

Unauthenticated SQL injection in the `order` parameter - mars.nasa.gov `/api/v1/{news_items,events,missions}/`

The public JSON API endpoints placed the user-supplied `order` parameter directly into the SQL ORDER BY clause without binding or allow-listing it. An attacker could inject SQL fragments and use the difference between a successful response and a database error as an oracle to probe the query.

0xJ0cKkY Follow

Originally disclosed on Bugcrowd

Critical View original
  • Accepted in 16 hours
  • Fixed in 23 days
  • Disclosed after 29 days

Summary by 0xJ0cKkY

The order parameter of these public JSON API endpoints is placed into the SQL ORDER BY clause without being bound as a parameter or checked against an allow-list of permitted columns. The site's own front-end already sends raw SQL fragments in this parameter (order=publish_date desc,created_at desc), so the value is used as SQL text by design.

Two independent facts establish that the value is parsed as SQL rather than matched against a list of allowed tokens:

  • PostgreSQL parses SQL comments supplied in the parameter. id/**/desc and id/*x*/desc both produce exactly the id desc ordering - a comment, including one containing text, is correctly treated as whitespace.
  • A malformed comment produces a database error. id/*desc (unterminated) and id*/desc (stray close) both fail with HTTP 403. A filter that merely stripped or rejected comments could not produce this asymmetry: a balanced comment is honoured, an unbalanced one errors. Only a SQL parser behaves this way.

This gives a reliable oracle - HTTP 200 = valid SQL referencing a real column; HTTP 403 = the query failed at the database

The original report as published on Bugcrowd, by 0xJ0cKkY. Images and videos are our own copies; raw HTML is shown as text. View it on Bugcrowd.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the `order` value is concatenated into the SQL ORDER BY clause as raw text instead of being bound as a parameter or validated against an allow-list of column names.

Impact

An attacker could use the 200/403 difference as an oracle to confirm that injected SQL is parsed and to probe the query, though the text does not show data extraction.

What the attacker needed

None

The fix

The `order` value should be bound as a parameter or validated against an allow-list of permitted column names and directions.

How it was found

  1. Send a request to one of the public JSON API endpoints with an `order` value containing a balanced SQL comment.
  2. Observe that the response returns HTTP 200 and the ordering behaves as if the comment were whitespace.
  3. Send an `order` value with an unterminated or stray comment.
  4. Observe that the response returns HTTP 403, showing the database rejected the malformed SQL.

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 report has not been written yet. The Original tab links to the source.

A website builds a database query by pasting text the user typed straight into it. Here the text goes into the part that decides how results are sorted, and the site never checks it. Because the database reads that text as instructions, an attacker can add their own database syntax and watch whether the page loads or errors to learn about the query.

What is SQL injection?

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.

More from National Aeronautics and Space Administration (NASA) - Vulnerability Disclosure Program

View all

The newest disclosed reports for this program.

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.