Skip to content

fix: Portfolio creation accepts arbitrary strings as userAddress — no Stellar address validation #63

Description

@grantfox-oss

Problem

In backend/src/api/validation.ts, createPortfolioSchema validates userAddress only as z.string().min(1). The codebase already has a working stellarAddressSchema (using the Stellar SDK's StrKey.isValidEd25519PublicKey) in the same file, but createPortfolioSchema does not use it.

This means any caller can create portfolios under arbitrary identifiers, which pollutes the database with unlinked records and could cause collisions if two different users happen to use the same string.

Proposed Fix

1. Use existing stellarAddressSchema

Change the userAddress field in createPortfolioSchema from z.string().min(1) to stellarAddressSchema.

2. Handle demo mode

The frontend falls back to "demo-user" when no wallet is connected. Options:

  • Add a separate demoAddress field for demo mode and validate userAddress only when in non-demo mode
  • Or require wallet connection before portfolio creation

3. Add validation tests

Test that invalid addresses are rejected and valid G... addresses are accepted.

Files to modify

  • backend/src/api/validation.ts — update createPortfolioSchema
  • backend/src/api/routes.ts — update POST /portfolio handler if needed
  • frontend/src/components/PortfolioSetup.tsx — send actual publicKey instead of "demo-user"
  • backend/src/api/__tests__/routes.test.ts — add validation tests

Acceptance Criteria

  • userAddress field uses stellarAddressSchema instead of z.string().min(1)
  • Frontend sends actual Stellar address instead of "demo-user" fallback
  • Test: POST /portfolio with userAddress: "not-a-valid-key" returns 400
  • Test: POST /portfolio with valid G... address returns 201
  • API documentation updated to reflect userAddress validation

Affected Area

Backend and Frontend

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendBackend relatedbugSomething isn't workingfrontendFrontend UIhelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions