Skip to content

feat(backend): add category allowlist and price_usdc format validation#187

Open
leocagli wants to merge 1 commit into
Stellar-Ecosystem:mainfrom
leocagli:feat/category-allowlist-validation
Open

feat(backend): add category allowlist and price_usdc format validation#187
leocagli wants to merge 1 commit into
Stellar-Ecosystem:mainfrom
leocagli:feat/category-allowlist-validation

Conversation

@leocagli

Copy link
Copy Markdown
Contributor

Fixes #4
Fixes #5

Problem

#4 — The GET /api/services?category= route forwarded any category string directly to listServices() 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.

#5registerServiceOnChain() in contract.js accepted priceUsdc as 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.js

  • Exported ALLOWED_CATEGORIES set (mirrors frontend/lib/types.ts)
  • Added validation to GET /api/services?category=: unknown categories return 400 INVALID_CATEGORY with the allowed list in the error body

backend/src/lib/contract.js

  • Added PRICE_USDC_RE = /^\d+(\.\d+)?$/ and ALLOWED_REGISTER_CATEGORIES set
  • registerServiceOnChain() now validates before any on-chain write:
    • price_usdc must match the regex AND be positive → INVALID_PRICE_USDC
    • category must be in the allowlist → INVALID_CATEGORY

🤖 Generated with Claude Code

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
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@leocagli, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3d9288ab-7785-4878-bcf0-e598a6706df7

📥 Commits

Reviewing files that changed from the base of the PR and between 6fb6da9 and 31b8b51.

📒 Files selected for processing (2)
  • backend/src/lib/contract.js
  • backend/src/routes/registry.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant