-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
bugSomething isn't workingSomething isn't workingsecuritySecurity related issues or improvementsSecurity related issues or improvements
Milestone
Description
Summary
Invite codes are generated client-side using Math.random(), which is not cryptographically secure.
Finding
File: app/(app)/(tabs)/profile/index.tsx:169
const code = Math.random().toString(36).substring(2, 10).toUpperCase();Risk
- Math.random() produces approximately 41 bits of entropy
- An attacker could enumerate or predict valid invite codes
- Invite codes grant ability to link sponsor-sponsee relationships
- No server-side uniqueness or rate-limiting controls
Recommended Fix
Option 1: Server-side generation (preferred)
Move invite code generation to a Supabase Edge Function or PostgreSQL function:
encode(gen_random_bytes(6), 'hex')Option 2: Client-side with crypto API
Use expo-crypto or crypto.getRandomValues():
import * as Crypto from 'expo-crypto';
const randomBytes = await Crypto.getRandomBytesAsync(6);
const code = Array.from(randomBytes)
.map(b => b.toString(16).padStart(2, '0'))
.join('')
.toUpperCase()
.slice(0, 8);Impact
HIGH - Weak invite codes could allow unauthorized sponsor-sponsee relationship creation.
References
- Related to 📋 Daily Codebase Review - 2026-02-24 #390 (Daily Codebase Review)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingsecuritySecurity related issues or improvementsSecurity related issues or improvements
Type
Projects
Status
Todo