feat(backend): add category allowlist and price_usdc format validation#187
feat(backend): add category allowlist and price_usdc format validation#187leocagli wants to merge 1 commit into
Conversation
Closes Stellar-Ecosystem#4 Closes Stellar-Ecosystem#5 Category strings were accepted unchecked in GET /api/services?category= and price_usdc was forwarded to the contract as a raw unvalidated string, allowing arbitrary category pollution and permanently broken price entries on-chain. Changes to backend/src/routes/registry.js: - Export ALLOWED_CATEGORIES set (search, weather, finance, ai, data, compute) - Validate category query param before calling listServices; unknown values return 400 INVALID_CATEGORY with the allowed list in the error message Changes to backend/src/lib/contract.js: - Added PRICE_USDC_RE regex and ALLOWED_REGISTER_CATEGORIES set - registerServiceOnChain() validates price_usdc is a positive decimal string (throws INVALID_PRICE_USDC) and category is in the allowlist (throws INVALID_CATEGORY) before any on-chain write
|
Warning Review limit reached
More reviews will be available in 1 minute and 47 seconds. Learn how PR review limits work. To continue reviewing without waiting, enable usage-based billing in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Fixes #4
Fixes #5
Problem
#4 — The
GET /api/services?category=route forwarded any category string directly tolistServices()with no validation. Frontend types define['search', 'weather', 'finance', 'ai', 'data', 'compute']but the backend never enforced this, allowing arbitrary category strings to pollute on-chain data.#5 —
registerServiceOnChain()incontract.jsacceptedpriceUsdcas a raw string with no format check. A malformed price like"abc","", or"-1"could be written permanently on-chain.Changes
backend/src/routes/registry.jsALLOWED_CATEGORIESset (mirrorsfrontend/lib/types.ts)GET /api/services?category=: unknown categories return400 INVALID_CATEGORYwith the allowed list in the error bodybackend/src/lib/contract.jsPRICE_USDC_RE = /^\d+(\.\d+)?$/andALLOWED_REGISTER_CATEGORIESsetregisterServiceOnChain()now validates before any on-chain write:price_usdcmust match the regex AND be positive →INVALID_PRICE_USDCcategorymust be in the allowlist →INVALID_CATEGORY🤖 Generated with Claude Code