Skip to content

[Backend] Fix off-by-one regex in isValidStellarAddress that rejects valid 56-char addresses #1011

@ogazboiz

Description

@ogazboiz

Telegram: https://t.me/+DOylgFv1jyJlNzM0

Why this matters

backend/src/utils/stellar.ts exposes isValidStellarAddress, but its regex is ^G[A-Z2-7]{54}$ — that only matches 55 characters total (G + 54). A real Stellar public key is 56 characters (G + 55). The preceding length check on line 33 correctly requires length === 56, so the regex can never match a valid address that passes the length check, making the function reject every valid address.

For comparison, both backend/src/services/remittanceService.ts and frontend/src/app/utils/stellar.ts correctly use {55}.

Verified locally:

G + 55 chars -> length 56
/^G[A-Z2-7]{54}$/.test(addr) === false   // util (wrong)
/^G[A-Z2-7]{55}$/.test(addr) === true    // service/frontend (correct)

Acceptance criteria

  • Change the regex in backend/src/utils/stellar.ts from {54} to {55}
  • Add a unit test asserting a real 56-char G... address returns true
  • Confirm assertValidStellarAddress no longer throws for valid input

Files to touch

  • backend/src/utils/stellar.ts

Out of scope

  • Refactoring the duplicate validators in other files (tracked separately)

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendIssues related to backend developmentbugSomething isn't workinggood first issueGood for newcomers

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions