Skip to content

Add request body schema validation for POST /api/streams (rate, recipient, schedule) #235

@greatest0fallt1me

Description

@greatest0fallt1me

Description

app/api/streams/route.ts and app/api/v2/streams/route.ts only check that recipient, rate, and schedule are present, then store them as raw strings — no Stellar address validation, no numeric/precision validation on rate, no allowed-values check on schedule. Add strict server-side schema validation so malformed streams cannot be created. This is a backend input-validation task.

Requirements and Context

  • Validate recipient as a Stellar public key using isValidStellarPublicKey from app/lib/wallet-link.ts.
  • Validate rate against the money/precision rules in app/lib/amount.ts (positive, bounded decimals).
  • Validate schedule against the supported set in app/lib/schedules.ts.
  • Return 422 VALIDATION_ERROR with per-field detail; share validation between v1 and v2 handlers.
  • Must be secure, tested, and documented
  • Should be efficient and easy to review

Suggested Execution

  1. Fork the repo and create a branch
    git checkout -b task/streams-create-validation
  2. Implement changes
    • app/api/streams/route.ts, app/api/v2/streams/route.ts
    • app/lib/stream-validation.ts (new) — shared validator using amount.ts, schedules.ts, wallet-link.ts
  3. Test and commit
    • npm test -- app/api/streams
    • Cover edge cases: bad public key, negative/over-precision rate, unknown schedule
    • Include test output and notes in the PR

Example commit message

task: add strict schema validation to stream creation

Acceptance Criteria

  • Invalid Stellar recipient rejected with 422
  • Invalid rate precision/sign rejected with field detail
  • Unknown schedule rejected
  • Coverage ≥ 90% for the validator and both routes

Guidelines

  • Minimum 90% test coverage including each invalid-field case
  • Clear documentation and inline comments
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programapiAPI endpoint/contract workbackendBackend service worksecuritySecurity hardening

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions