Story #37 Input Injection · Semantic Validation · Secure API Design

The Search Parameter That Became a Database Command

"The filter looked like a search term. The database treated it as an instruction"

A procurement platform interpolated free-form sort expressions and filter strings into database queries. During a security assessment, crafted input changed the query structure and exposed supplier records outside the intended search scope.

What happened

A procurement platform exposed a supplier search API. To support flexible filtering, an implementation change allowed clients to submit a free-form sort expression and filter string. The service interpolated these values into a database query instead of mapping them to an allowlisted set of fields and operators.

Most users supplied ordinary values, so functional testing showed no obvious issue. During a security assessment, a tester discovered that specially crafted filter input changed the query structure and exposed records outside the intended search scope. A related export endpoint accepted the same filter expression and returned more supplier data than the caller was entitled to view.

The team had validated that requests were syntactically valid JSON and that common search terms worked. It had not tested how untrusted input was interpreted by the query builder. Logs also lacked safe request correlation, making it difficult to distinguish malformed input from ordinary searches during the investigation.

Root cause

Validation focused on JSON shape and happy-path searches rather than safe interpretation of attacker-controlled values. Untrusted filter and sort input was treated as executable query syntax.

The fix

The service was redesigned around parameterized queries and an allowlisted query language. Sort fields and operators are validated against explicit metadata, and field-level authorization is applied after query construction. Security tests now use harmless injection probes in an isolated environment and verify both response contents and database state.

Testing gaps and preventive tests

Injection probes, allowlist validation, authorization checks on search results, and regression tests against parameterized query behavior. Every value that influences query or command construction needs explicit interpretation rules.

Business impact

Supplier information was exposed beyond the intended search scope, prompting a security review and customer notifications.

Lesson learned

Valid JSON is not necessarily safe input. Every value that influences query or command construction needs explicit interpretation rules.

The Search Parameter That Became a Database Command