Skip to content

test(web): regression guards for medicine search hardening - #4210

Merged
dipexplorer merged 1 commit into
RatLoopz:mainfrom
Kirtan-pc:fix/4201-harden-medicine-search-rate-limit-main
Aug 8, 2026
Merged

test(web): regression guards for medicine search hardening#4210
dipexplorer merged 1 commit into
RatLoopz:mainfrom
Kirtan-pc:fix/4201-harden-medicine-search-rate-limit-main

Conversation

@Kirtan-pc

Copy link
Copy Markdown
Contributor

🛑 STOP: Assignment & File Scope Check

  • I am assigned to this issue.
  • I verified that this PR ONLY touches the required files.

Warning

PRs with unrelated files will not be reviewed and may be closed.

📋 PR Summary & Link

  • Closes [BUG] /api/medicines/search/route.ts — unclosed function → web build failure + shadowed imports reintroduce rate-limit bypass #4201
  • Summary:
    What changed: Added apps/web/tests/medicine-search-route.test.ts (1 file, 131 insertions). This is the same fix from the earlier branch, re-based cleanly onto main.
    Why (the "better way"): Issue [BUG] /api/medicines/search/route.ts — unclosed function → web build failure + shadowed imports reintroduce rate-limit bypass #4201's literal bug — an unclosed { in the local getClientIp shadowing the hardened helpers, causing TS1005 and a rate-limit/cache-poisoning bypass — was already fixed upstream by commit 2dc6e6a. But the route had no runnable test coverage: the pre-existing app/api/medicines/search/route.test.ts sits outside jest's roots: ["/tests"], so it never executed. This PR adds real coverage that pins the security properties that broken inline reimplementation would have silently undone:
  • Rate limiting uses the hardened getClientIp — forged X-Forwarded-For/X-Real-IP are ignored (loopback default), so an attacker can't mint a fresh rate-limit bucket per request.
  • ILIKE wildcards (%/_) are escaped before PostgREST, preventing wildcard shaping / med_search:* cache poisoning.
  • Comma/paren queries reach the DB without throwing.
  • Short (<2 char) and oversized (>100 char) queries short-circuit before touching Redis/DB.
    Verification: all 5 tests pass; no type errors; no circular deps. The 5 unrelated pre-existing suite failures (api, upload-route, voice-page-a11y, i18n-locales, compare-interactions) were confirmed identical on main.

🏷️ PR Type

  • 🐛 type: bug
  • type: feature
  • 📖 type: docs
  • 🧪 type: testing
  • 🔒 type: security
  • type: performance
  • 🎨 type: design
  • ♻️ type: refactor
  • 🛠️ type: devops
  • type: accessibility

✅ Checklist

  • My PR has a linked issue (Closes #4201)
  • I have pulled the latest main and resolved any conflicts

…Loopz#4201)

The brace-imbalance bug (unclosed local getClientIp declaration shadowing
the hardened helpers) was removed upstream in 2dc6e6a, but the route had
no runnable coverage: the existing route.test.ts lives under app/api and is
excluded by jest.config.cjs (roots: tests/), so it never executed.

Add a runnable test in tests/ that pins the security behavior the broken
inline reimplementation would have silently undone:

- rate limiting uses the hardened getClientIp: forged X-Forwarded-For /
  X-Real-IP are ignored (loopback default), so an attacker cannot mint a
  fresh rate-limit bucket per request.
- LIKE wildcards (% / _) are escaped before reaching PostgREST, preventing
  wildcard shaping / cache poisoning of med_search:* entries.
- comma/paren queries reach the DB without throwing.
- short (<2 char) and oversized (>100 char) queries short-circuit before
  touching Redis or the DB.
@github-project-automation github-project-automation Bot moved this to 📥 Backlog in SahiDawa Workflow Aug 7, 2026
@github-actions github-actions Bot added gssoc:approved Approved for gssoc type:bug Something isn't working labels Aug 7, 2026
@sonarqubecloud

sonarqubecloud Bot commented Aug 7, 2026

Copy link
Copy Markdown

@dipexplorer dipexplorer added level:intermediate 35 pts quality:clean multiplier x1.2 type:testing Unit tests, integration tests labels Aug 8, 2026
@dipexplorer
dipexplorer merged commit 9de02ca into RatLoopz:main Aug 8, 2026
22 of 27 checks passed
@github-project-automation github-project-automation Bot moved this from 📥 Backlog to 🎉 Merged in SahiDawa Workflow Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved for gssoc level:intermediate 35 pts quality:clean multiplier x1.2 type:bug Something isn't working type:testing Unit tests, integration tests

Projects

Status: 🎉 Merged

Development

Successfully merging this pull request may close these issues.

[BUG] /api/medicines/search/route.ts — unclosed function → web build failure + shadowed imports reintroduce rate-limit bypass

2 participants