Search handles special characters without triggering errors
Why it matters
Unescaped special characters in search queries are a direct path to SQL injection (CWE-89) and OWASP A03:2021 Injection — apostrophes, quotes, and backslashes passed raw into a query string can terminate the intended SQL clause and execute attacker-controlled statements. Beyond active exploitation, the same bug silently breaks legitimate searches: John's Café, Fish & Chips, and Rock (n roll) are common real-world listing names that will surface 500 errors if input validation is absent. Every error response leaks backend implementation details and destroys user trust at the exact moment they're trying to find something.
Severity rationale
High because unescaped input enables SQL injection (CWE-89, OWASP A03) and crashes the search experience for ordinary user input containing apostrophes or special characters.
Remediation
Switch to parameterized ORM queries and URL-encode the query string on the client. String concatenation into raw SQL is never acceptable here.
// /api/listings/search — use ORM parameterization, never string concat
const results = await db.listings.findMany({
where: {
OR: [
{ name: { contains: q, mode: 'insensitive' } },
{ description: { contains: q, mode: 'insensitive' } }
]
}
})
On the client, always encode before appending to the URL: ?q=${encodeURIComponent(query)}. Test with Bob's Diner, Fish & Chips, and <script> to confirm no 500 responses or JS exceptions.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Search & Discovery UX Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-89 — SQL Injection
- cwe · CWE-20 — Improper Input Validation
- owasp:2021 · A03 — Injection
Taxons
History
- 2026-04-18·v1.0.0·Initial import from directory-search-discovery·automated