indexer: escape ILIKE wildcards in pair search (#459) #984
No reviewers
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:implement
agent:implement
agent:open_issues
agent:ready
agent:research
agent:security_audit
agent:verify
architecture
backend
blocker:hybrid
blocker:launch
blocker:limit-orders
blocker:v2
block:log_only
block:security
bug
ci
contracts
correctness
deploy
dev
devops
docs
documentation
duplicate
e2e
enhancement
epic
feature
frontend
functional-completion
gas
good first issue
governance
help wanted
high-risk
hooks
hybrid
indexer
infra
infrastructure
integrators
invalid
launch-blocker
limit-orders
localnet
localterra
low priority
missing-implementation
needs-design
ops
performance
priority
high
priority
medium
product
qa
QA
question
ready
ready
research
scripts
security
security-hardening
smartcontracts
tech-debt
testing
ux
UX
v2
verification
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
code/cl8y-dex-terraclassic!984
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "qa/459-ilike-escape"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
GET /api/v1/pairs?q= embedded the user query into ILIKE patterns via
format!("%{}%", q) with no metacharacter escaping. ?q=% produced ILIKE '%%%'
and matched every pair (and forced a sequential scan since leading-wildcard
ILIKE can't use the index); ?q=_ matched any single character. The 128-char
truncation didn't help — a burst of one-char/wildcard queries is a search
amplification vector against Postgres CPU (SEC-I04 F02).
Add escape_like_pattern() — escapes , %, _ (backslash first to avoid
double-escaping). Postgres' default LIKE/ILIKE escape char is backslash, so the
bound pattern needs no explicit ESCAPE clause. Applied at every pattern-building
site (relevance score, list filters, and the split pair-symbol sub-tokens).
Single-char symbol search still works (escaping, not a min-length reject).
Tests: 4 unit tests on the escaper + 1 Postgres integration test proving
?q=% and ?q=_ return empty while ?q=LUNC still matches; api_pairs suite 16/0
(incl relevance ordering).
assigned to @Brouie
mentioned in issue #459
Security review — MR !984
Commit reviewed:
ef0c850d75cca786472bc252fa0bde21ef947b6aScope:
escape_like_pattern()applied to allGET /api/v1/pairs?q=ILIKE pattern construction sites (push_pair_relevance_score,push_pair_list_filters, pair-symbol sub-tokens); unit + integration tests for%/_neutralization.Outcome:
FINDINGS: 0medium+Method
?q=fromlist_pairs(PAIR_LIST_Q_MAX_LEN=128truncation) throughcount_pairs_filtered/list_pairs_filteredintopush_pair_list_filtersandpush_pair_relevance_score.sqlx::QueryBuilder::push_bind(parameterized — no SQL injection sink).escape_like_patternneutralizes\,%,_(backslash first) before wrapping with%…%, closing SEC-I04 F02 search-amplification (?q=%→ match-all + sequential scan;?q=_→ single-char wildcard).Assessment
This diff remediates the reported vulnerability rather than introducing new attack surface. Escaping aligns with PostgreSQL’s default LIKE/ILIKE backslash escape semantics on bound parameter values; integration test
search_wildcard_query_does_not_match_all_pairsexercises the fix end-to-end.Residual leading-wildcard cost on normal substring searches (
%term%) is pre-existing intentional behavior and out of scope for this diff.Security review: no medium+ findings on this diff.
mentioned in commit
16cdb4336b