Skip to content

feat: cap message field at 2000 chars with validation and tests (Closes #1504) - #1618

Open
waterWang wants to merge 1 commit into
Remitwise-Org:mainfrom
waterWang:feat/validate-message-field-1504
Open

feat: cap message field at 2000 chars with validation and tests (Closes #1504)#1618
waterWang wants to merge 1 commit into
Remitwise-Org:mainfrom
waterWang:feat/validate-message-field-1504

Conversation

@waterWang

Copy link
Copy Markdown
Contributor

Summary

Adds server-side validation for the optional message field used in remittance and emergency-transfer flows. The message is capped at 2000 characters to prevent abuse and ensure database consistency.

Changes

  • utils/validation.ts: Added validateMessage() function that checks character length (not byte length, since this is a user-facing message, not a Stellar memo)
  • app/api/remittance/build/route.ts: Wire message validation into the remittance build endpoint
  • app/api/v1/remittance/emergency/build/route.ts: Wire message validation into the emergency transfer build endpoint
  • types/emergency-transfer.ts: Added INVALID_MESSAGE error code and optional message field to EmergencyTransferRequest
  • tests/unit/remittance/build-validation.test.ts: Added comprehensive unit tests for validateMessage() covering:
    • Undefined/empty string (returns null — message is optional)
    • Message within 2000 chars (accepts)
    • Message exceeding 2000 chars (rejects with structured error)
    • Message exactly 2000 chars (boundary case)
    • Multi-byte characters (UTF-8 safety)
    • Emoji characters

Implementation Details

  • Rejects bad input at the API boundary (not deep in the call graph)
  • Errors returned as structured typed errors (EmergencyTransferErrorCode.INVALID_MESSAGE), never stringly-typed 400
  • Follows the same pattern as existing validateMemo() and validateAmount() functions

Closes #1504

Adds server-side validation for the optional message field used in
remittance and emergency-transfer flows. The message is capped at
2000 characters to prevent abuse and ensure database consistency.

- Add validateMessage() utility function in utils/validation.ts
- Wire validation into both remittance build API routes
- Add INVALID_MESSAGE error code to EmergencyTransferErrorCode
- Add typed message field to EmergencyTransferRequest interface
- Add comprehensive unit tests covering happy path, edge cases,
  and multi-byte/emoji input

Closes Remitwise-Org#1504
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate: cap message field at 2000 chars

1 participant