|
| 1 | +# Coindrop.to Security Audit Report |
| 2 | + |
| 3 | +## 🚨 CRITICAL SECURITY ISSUES |
| 4 | +(Issues requiring immediate attention) |
| 5 | + |
| 6 | +**Issue:** Stored Cross-Site Scripting (XSS) |
| 7 | +**Location:** `pages/api/createPiggybank.ts` and `components/PublicPiggybankPage/PublicPiggybankPage.tsx` |
| 8 | +**Risk:** An attacker can create a piggybank with a malicious `website` URL (e.g., `javascript:alert(cookies)`). When a user visits the piggybank page and clicks the website link, the malicious script executes. This could lead to account takeover or data theft. |
| 9 | +**Fix:** Validate the `website` field in `createPiggybank.ts` using `validator.isURL` and ensure it uses `http` or `https`. Additionally, sanitize the link in the frontend. |
| 10 | +**Effort:** Low (< 1 hour) |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +### ⚠️ SECURITY RECOMMENDATIONS |
| 15 | +(Important but not critical) |
| 16 | + |
| 17 | +**Issue:** Weak Admin Authentication |
| 18 | +**Location:** `server/middleware/requireAdminPassword.ts` |
| 19 | +**Impact:** The admin endpoints rely on a shared password sent in the request body. If the `ADMIN_PASSWORD` env var is weak or leaked, all admin functions are compromised. It also lacks accountability. |
| 20 | +**Fix:** Implement role-based access control (RBAC) using Firebase Auth (e.g., set custom claims for admins) instead of a shared password. |
| 21 | +**Effort:** Medium (2-4 hours) |
| 22 | + |
| 23 | +**Issue:** Missing Security Headers |
| 24 | +**Location:** `next.config.js` |
| 25 | +**Impact:** The application is missing standard HTTP security headers (HSTS, X-Frame-Options, X-XSS-Protection, etc.), making it more susceptible to clickjacking, MITM attacks, and XSS. |
| 26 | +**Fix:** Configure `headers` in `next.config.js` to return appropriate security headers. |
| 27 | +**Effort:** Low (< 1 hour) |
| 28 | + |
| 29 | +**Issue:** Missing Rate Limiting |
| 30 | +**Location:** API Routes |
| 31 | +**Impact:** API endpoints are vulnerable to abuse (spam creation of piggybanks, brute force). |
| 32 | +**Fix:** Implement rate limiting middleware (e.g., `rate-limiter-flexible` with Redis or memory) for sensitive endpoints. |
| 33 | +**Effort:** Medium (2-4 hours) |
| 34 | + |
| 35 | +--- |
| 36 | + |
| 37 | +### 💡 HIGH-VALUE IMPROVEMENTS |
| 38 | +(Ranked by impact-to-effort ratio) |
| 39 | + |
| 40 | +**#1: Add Input Validation** |
| 41 | +**Impact:** Prevents bad data from entering the database and reduces runtime errors. |
| 42 | +**Implementation:** Use `zod` schema validation in API routes (already installed). Validate `piggybankData` structure fully. |
| 43 | +**Effort:** Low |
| 44 | +**Priority:** High |
| 45 | + |
| 46 | +**#2: Upgrade Dependencies** |
| 47 | +**Impact:** access to security fixes and performance improvements. |
| 48 | +**Implementation:** Update `firebase` to v9 modular SDK completely (some parts seem mixed), and `next` to a newer version (carefully). |
| 49 | +**Effort:** Medium |
| 50 | +**Priority:** Medium |
| 51 | + |
| 52 | +--- |
| 53 | + |
| 54 | +### 📊 SUMMARY |
| 55 | +- Total critical issues: 1 |
| 56 | +- Total security recommendations: 3 |
| 57 | +- Total quick wins identified: 1 |
| 58 | +- Estimated total time for all quick wins: 2 hours |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +### 🎯 RECOMMENDED ACTION PLAN |
| 63 | + |
| 64 | +1. Fix the Stored XSS in `createPiggybank.ts`. |
| 65 | +2. Add Security Headers in `next.config.js`. |
| 66 | +3. Implement `zod` validation for API inputs. |
| 67 | +4. Replace shared admin password with Firebase Custom Claims. |
0 commit comments