Skip to content

Fix backend search query hardening, deterministic ranking, flag cache TTL, and rollout stability - #2071

Merged
Olowodarey merged 1 commit into
Arena1X:mainfrom
ScriptedBro:feature/1953-1954-1955-1956-search-and-flags-fixes
Oct 20, 2026
Merged

Olowodarey merged 1 commit into
Arena1X:mainfrom
ScriptedBro:feature/1953-1954-1955-1956-search-and-flags-fixes

Conversation

@ScriptedBro

Copy link
Copy Markdown
Contributor

Description

This pull request addresses and fixes four backend issues across search services and feature flag management:

  1. Search Query Injection Hardening ([Backend] — Search Query Injection Hardening #1953):

    • Added sanitizeSearchInput to strip/neutralize query operators (&, |, !, :, *, <, >, ", ', \) that could manipulate full-text search structure or cause malformed tsquery errors.
    • Enhanced escapeLikeWildcards to escape backslashes (\) before % and _ with explicit ESCAPE '\\' clauses on LIKE/ILIKE statements across search suggestions and typeahead.
    • Guarded search(), fuzzySearch(), and searchCreatorEvents() to handle empty or whitespace-only queries safely without executing unneeded or invalid database queries.
    • Preserved search functionality for legitimate normal queries.
  2. Search Result Relevance Ranking Determinism ([Backend] — Search Result Relevance Ranking Determinism #1954):

    • Implemented deterministic secondary tie-breaking by entity title/username and ID for equal-relevance results across markets, users, competitions, suggestions, and fuzzy search.
    • Added explicit tie-breaker ordering (created_at DESC, id ASC) to searchCreatorEvents.
    • Guarantees identical ordering for repeated identical queries over unchanged data while preserving higher-relevance ranking.
  3. Feature Flag Evaluation Cache TTL & Invalidation ([Backend] — Feature Flag Evaluation Cache TTL #1955):

    • Bounded cached feature flag evaluations in FlagEvaluationCacheService to a documented default TTL (DEFAULT_FLAG_EVALUATION_CACHE_TTL_MS = 60,000ms).
    • Implemented automatic cache invalidation (invalidate(flagKey)) in FeatureFlagsService when feature flags are updated or deleted so changes reflect immediately.
    • Ensured cache misses and expired evaluations fall back to fresh evaluation from the database.
  4. Feature Flag Percentage Rollout Bucketing Stability ([Backend] — Feature Flag Percentage Rollout Bucketing Stability #1956):

    • Implemented deterministic bucketing (calculateRolloutBucket, isUserInRollout) using SHA-256 hash of (flag key, user id) to assign a stable 0–99 bucket per user.
    • Guaranteed monotonicity: 0% includes nobody, 100% includes everyone, and increasing the rollout percentage strictly adds users without flipping out previously-included users.
    • Made rollout bucketing methods accessible on FlagsService and integrated with FeatureFlagsService.

Related Issues

Closes #1953
Closes #1954
Closes #1955
Closes #1956

…he TTL, and stable rollout bucketing

- Search Query Injection Hardening (Arena1X#1953):
  - Neutralize search query operators and escape SQL LIKE wildcards (\, %, _)
  - Safely handle empty and whitespace-only queries in search(), searchCreatorEvents(), and fuzzySearch()
  - Preserve legitimate search query behavior for normal terms

- Search Result Relevance Ranking Determinism (Arena1X#1954):
  - Add deterministic secondary sorting by entity title/username and id for equal-relevance results across markets, users, competitions, fuzzy search, and suggestions
  - Ensure repeated identical queries over unchanged data return identical ordering while maintaining relevance hierarchy

- Feature Flag Evaluation Cache TTL & Invalidation (Arena1X#1955):
  - Bound cached flag evaluations to a documented 60-second TTL
  - Automatically invalidate evaluation cache entries on flag update and deletion
  - Ensure cache miss falls back to fresh evaluation

- Feature Flag Percentage Rollout Bucketing Stability (Arena1X#1956):
  - Implement deterministic SHA-256 bucketing across flag key and user ID
  - Guarantee stable and monotonic rollout evaluations (0% includes nobody, 100% includes everyone, higher percentages strictly preserve existing users)

Closes Arena1X#1953, Closes Arena1X#1954, Closes Arena1X#1955, Closes Arena1X#1956
@drips-wave

drips-wave Bot commented Oct 20, 2026

Copy link
Copy Markdown

@ScriptedBro Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@vercel

vercel Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
insight-arena-4rll Error Error Oct 20, 2026 7:32am UTC

@Olowodarey
Olowodarey merged commit c2514ed into Arena1X:main Oct 20, 2026
1 of 5 checks passed

This branch had an error being deployed

1 failed deployment
Preview — ab6e9816 Deployed Oct 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants