Filtering and sorting supported where appropriate
Why it matters
Without server-side filtering and sorting, clients must fetch all records and filter client-side — amplifying data transfer, memory use, and backend query cost at every call. Worse, if a sort field is passed unsanitized into an ORDER BY clause, it becomes a CWE-89 SQL injection vector (OWASP A03:2021): an attacker can supply a crafted field name to probe column structure or trigger errors that reveal schema. Even the low-severity label here understates the injection risk on the sort parameter.
Severity rationale
Low for the missing filter/sort feature itself, but the sort-field injection path elevates actual exploitability — an unsanitized ORDER BY is a direct injection vector.
Remediation
Add filter and sort query parameter support to primary list endpoints in app/api/. Always validate sort field against an explicit allowlist — never interpolate a query parameter directly into an ORDER BY clause:
const ALLOWED_SORT_FIELDS = ['created_at', 'updated_at', 'title'] as const
type SortField = typeof ALLOWED_SORT_FIELDS[number]
const sortParam = searchParams.get('sort') ?? 'created_at'
const sortField: SortField = ALLOWED_SORT_FIELDS.includes(sortParam as SortField)
? (sortParam as SortField)
: 'created_at'
const items = await db.post.findMany({
where: { status: searchParams.get('status') ?? undefined },
orderBy: { [sortField]: searchParams.get('order') === 'asc' ? 'asc' : 'desc' },
})
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 API Design Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-89 — SQL Injection (unsanitized sort field)
- owasp:2021 · A03 — Injection
Taxons
History
- 2026-04-18·v1.0.0·Initial import from saas-api-design·automated