Home / Learn Secure SQL / Validating Search Input

Validating Search Input

A free-text field with the loosest shape, and how to still bound it.

The gistA free-text field with the loosest shape, and how to still bound it.

The idea, explained simply

Loose but still boundedfree-text search termlength-limited,control characters…bound as an ordinaryparameter, same as…
Loose but still bounded

The basic idea

A search box deliberately accepts almost any text, so "validation" here means length limits and perhaps stripping control characters, not rejecting most input the way a structured field would.

Why this comes up

It is tempting to think a search box needs no validation because "it's supposed to accept anything"; it still needs a length limit, and the search term is still bound as an ordinary parameter, never string-joined for "flexibility".

The mechanics

Apply a generous but finite length limit, optionally strip non-printable control characters, and always bind the term as a parameter, using LIKE wildcards or full-text search as covered earlier.

Where it is used

  • Web application code review
  • Backend development
  • Database administration
A length-aware search querySQL: edit and run

The search term is still one bound value, concatenated with wildcards using SQL's own || operator on the server side, not joined into the SQL text by the application.

Quick check

1. A search box's "loose" validation mainly means...