fix(referrals): reject non-string email entries in invite API (#141) - #166
Merged
ralyodio merged 1 commit intoMay 23, 2026
Merged
Conversation
…lstack#141) POST /api/referrals crashes when emails array contains non-string entries (e.g. numbers, null, objects) because .trim().toLowerCase() is called on each entry without type checking. Changes: - Add emails.every() guard to reject non-string entries with 400 error - 3 regression tests: number in array, null, object Fixes profullstack#141
Greptile SummaryAdds an element-level type guard to the
Confidence Score: 5/5Minimal, targeted fix; safe to merge. The change is a single well-placed guard that closes the crash path without touching any surrounding logic. The new tests directly exercise the added branch, and the rest of the validation pipeline (length cap, spam throttle, format regex) is unaffected. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[POST /api/referrals] --> B{Auth check}
B -- Unauthorized --> C[401 Unauthorized]
B -- OK --> D{emails is non-empty array?}
D -- No --> E[400 Please provide an array of emails]
D -- Yes --> F{All entries are strings?}
F -- No --> G[400 All email entries must be strings]
F -- Yes --> H{emails.length > 20?}
H -- Yes --> I[400 Maximum 20 invites]
H -- No --> J[Spam throttle checks]
J -- Exceeded --> K[429 Too many invites]
J -- OK --> L[Normalize & deduplicate emails]
L --> M{Any new emails?}
M -- No --> N[400 All already invited]
M -- Yes --> O[Validate email format with regex]
O --> P{Any valid emails?}
P -- No --> Q[400 No valid email addresses]
P -- Yes --> R[Insert referral rows & send emails]
R --> S[200 invite created response]
Reviews (1): Last reviewed commit: "fix(referrals): reject non-string email ..." | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix for #141 — Referral invite API crashes on non-string email entries
Bug
POST /api/referralsvalidatesemailsis an array but assumes every entry is a string before calling.trim().toLowerCase(). A request like{ "emails": ["friend@test.com", 42] }throwsTypeError: e.trim is not a functionand falls through to the generic 500 handler.Root Cause
No type guard on individual array elements. The
.map((e: string) => e.trim().toLowerCase())call crashes wheneis not a string.Fix
Added
emails.every((email) => typeof email === "string")guard immediately after the array check, returning a clear400error: "All email entries must be strings"Test Evidence
All 11 tests pass (8 existing + 3 new regression tests).
Bounty
💎 uGig Affiliate Testing Bounty
SOL payment address:
0xadf380b5048e9730af0957fd39d5ef1de374475d⭐ Starred profullstack/ugig.net ✅