liveBook · Manning

Parameterized query

As explained in Secure APIs

A parameterized query is a database query whose code and externally supplied values are transmitted separately so values cannot alter the query structure.

A parameterized query keeps database instructions separate from externally supplied values. User input is treated as data rather than as part of the query structure, reducing the risk that an attacker can change what the database executes. section 1.2.2 section 6.3

This matters because APIs commonly pass query and path parameters into data-layer operations. Unconstrained strings can carry SQL injection payloads, disable intended filters, delay database responses, or expose behavior through errors. section 6.3

A malicious filter

A product endpoint accepting a free-form filter can receive a value such as ' OR 1=1; --, which attempts to bypass query constraints. A time-delay payload using PG_SLEEP(10) demonstrates another possible effect. Parameterize the query, constrain accepted values, and validate input independently of the client application. section 6.3

Use parameterized queries as part of a broader input-safety routine:

  • Validate and sanitize every input, including values received directly by the API rather than through a trusted web or mobile application. section 1.2.2 section 6.3
  • Constrain selectable fields with explicit values; for example, allow only price, review, or name for sortBy. section 6.3
  • Use established API frameworks, DTOs, and fuzz testers to support validation, safe data transfer, and implementation testing. section 1.2.2

How Secure APIs covers it

How deep it goes
Connects parameterization to unconstrained input and mitigation, but defers database-driver implementation details.
Examples
Uses product filters, time-delay payloads, and constrained sortBy values to demonstrate attacks and defenses.
What it assumes
Assumes familiarity with API inputs and database queries while treating zero-trust validation as a required practice.
What you can do after
Apply parameterization alongside input constraints and fuzz testing when implementing API database access.
How it connects
Connects SQL injection with input validation, zero trust, DTOs, API frameworks, and fuzz testing.

Also explained in

Compare how 8 books explain parameterized query →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secure APIs. The section links point to the parts of the book it draws on.