Validate referral invite email types - #142
Conversation
Greptile SummaryThis PR closes a gap in the
Confidence Score: 5/5Safe to merge — the change is a narrow, well-placed input guard with a matching regression test and no modifications to existing logic. The new type guard is inserted at exactly the right point in the validation chain, before any service client or database work begins. All non-string JSON types (numbers, booleans, null, objects) are correctly rejected by the typeof === string check. The regression test verifies the 400 path end-to-end and confirms no downstream side effects fire. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[POST /api/referrals] --> B{Auth valid?}
B -- No --> C[401 Unauthorized]
B -- Yes --> D{emails is non-empty array?}
D -- No --> E[400 Please provide an array]
D -- Yes --> F{All entries are strings?}
F -- No --> G[400 All invite emails must be strings]
F -- Yes --> H{emails.length > 20?}
H -- Yes --> I[400 Maximum 20 invites]
H -- No --> J[Throttle check: hourly/daily limits]
J --> K[Deduplicate against existing invites]
K --> L[Validate email format with regex]
L --> M[Insert referral rows to DB]
M --> N[Send invite emails]
N --> O[200 Response]
Reviews (1): Last reviewed commit: "Validate referral invite email types" | Re-trigger Greptile |
Summary
emailsarray with a 400 responseWhy
The endpoint already checks that
emailsis an array, but then callstrim().toLowerCase()on every entry. A malformed client payload with a non-string entry could throw and return a generic 500 instead of a validation error.Validation
pnpm test:run src/app/api/referrals/route.test.tspnpm exec eslint src/app/api/referrals/route.ts src/app/api/referrals/route.test.tspnpm type-checkgit diff --checkPayment for the active uGig affiliate testing bounty can go to SOL:
27sdMYXofqoM9qR13bZhccRNYeEgYn5EoHXTSJn4QWKP.Payment fallback: PayPal cultofrozen@gmail.com