Example team scheduling SaaS
Verdict
Refactor parts
The product logic is reasonable and the data model is sound. Two areas need reshaping rather than patching: who may change what, which is split between middleware, the browser and the database with gaps between them, and billing, which trusts requests it cannot verify. Fixing those, starting with the leaked key and the unsigned webhook, makes the app safe to sell to paying teams. A rebuild is not needed.
Executive summary
- Two critical issues: the Supabase service-role key ships in the browser, and anyone can post a fake "paid" event to the Stripe webhook.
- Two high issues: users can upgrade their own plan through the profile endpoint, and any signed-in user can remove members from other teams.
- Signs of AI-built code: two Supabase auth libraries in use at once, and type errors hidden at the Stripe and database boundaries.
- Estimated fix effort: about 3 to 4 working days for the critical and high findings, and 5 to 6 days for everything.
| Severity | Count | Meaning |
|---|---|---|
| CRITICAL | 2 | Exploitable now. Fix before the next release. |
| HIGH | 2 | Serious risk. Fix within two weeks. |
| MEDIUM | 3 | Quality or scale risk. Plan into the next month. |
Findings
CRITICAL Service-role key in the browser bundle
src/lib/supabase.ts:4 · JS-SEC-03 · OWASP A02:2025 · CWE-798
What: the shared Supabase client is created with NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY, so the key is compiled into the JavaScript every visitor downloads.
Why it matters: the service-role key bypasses every row-level security policy. Anyone can read, change or delete all data, including other companies' bookings and customer emails.
Fix: rotate the key now. Use the public anon key in the browser, and the service-role key only in server code marked server-only.
- export const supabase = createClient(url, process.env.NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY!) + export const supabase = createBrowserClient(url, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!) + // src/lib/supabase-admin.ts (import "server-only"): createClient(url, process.env.SUPABASE_SERVICE_ROLE_KEY!)
Effort: 1 day, including moving the admin calls to the server.
CRITICAL Stripe webhook accepts unsigned events
app/api/stripe/webhook/route.ts:9 · JS-PAY-01 · OWASP A08:2025 · CWE-345
What: the handler parses await req.json() and acts on the event without checking the Stripe-Signature header.
Why it matters: anyone can post a fake checkout.session.completed event and get a paid plan for free.
Fix: read the raw body, verify it with stripe.webhooks.constructEvent and the endpoint secret, store processed event ids, and re-fetch the subscription from Stripe before granting access.
Effort: 1 day, including idempotency and a test.
HIGH Users can upgrade their own plan
app/api/profile/route.ts:18 · JS-INP-02 · API3:2023 · CWE-915
What: the profile update passes the request body straight into .update(body) on the profiles table, which also holds plan and seats.
Why it matters: a user can send {"plan": "pro", "seats": 500} and get a paid plan without paying.
Fix: validate the body with a zod schema that allows only name and time zone, and move billing fields to a table only the server can write.
Effort: half a day.
HIGH Any signed-in user can remove members of other teams
app/teams/actions.ts:31 · removeMember · JS-AUTH-01 · OWASP A01:2025 · CWE-862
What: the server action checks only that someone is signed in, which middleware already did. It never checks that the caller is an admin of the team that owns the member.
Why it matters: member ids appear in invite links, so a user from another company can remove people from your customer's team.
Fix: check team membership and role inside the action, and add a row-level security policy so the database enforces the same rule.
Effort: 1 day, covering all eight team actions.
MEDIUM Uploads have no size or type limit
app/api/upload/route.ts · JS-INP-08 · API4:2023 · CWE-400
Any file of any size is accepted and stored, so one request can fill your storage. Limit type and size on the server, and set the same limits on the storage bucket.
MEDIUM Two Supabase auth libraries in use at once
package.json, src/lib/auth/*.ts · JS-AI-04
Older pages use the deprecated @supabase/auth-helpers-nextjs and newer ones use @supabase/ssr. They refresh sessions differently, which explains the random sign-outs your users report. Move everything to @supabase/ssr.
MEDIUM Type errors hidden at the Stripe and database boundaries
next.config.ts, 23 files · JS-AI-03
typescript.ignoreBuildErrors is on, and 41 @ts-ignore or any uses sit where Stripe and Supabase data enter the app. Turn the build check back on, generate database types, and fix the errors it shows.
Risk register
| Risk | Likelihood | Impact | Rating | Owner | Due |
|---|---|---|---|---|---|
| All customer data read or deleted with the leaked key | Likely | Severe | CRITICAL | Engineering lead | Day 2 |
| Paid plans obtained without paying | Likely | Severe | CRITICAL | Billing owner | Day 5 |
| Customers' teams changed by outsiders | Possible | Moderate | HIGH | Engineering lead | Day 14 |
| Storage costs run up by large uploads | Possible | Minor | MEDIUM | Engineering lead | Day 30 |
| Users signed out at random, support load grows | Likely | Minor | MEDIUM | Engineering lead | Day 45 |
30/60/90-day roadmap
| When | What | Outcome |
|---|---|---|
| Days 1–30 | Rotate the service-role key and move admin calls to the server; verify and de-duplicate Stripe webhooks; lock down profile updates and team actions; add row-level security tests. | No way in without the right account, and no free plans. Re-check and letter. |
| Days 31–60 | One auth library; type checks back in the build; upload limits; CI runs tests, type checks and secret scanning on every pull request. | Fewer sign-out complaints; regressions caught before release. |
| Days 61–90 | MFA for team admins, an audit log of member and billing changes, protected preview deployments on a separate Supabase project. | Ready for larger customers' security reviews. |
Fix plan and quote
| Phase | Scope | Days | Fixed price |
|---|---|---|---|
| 1 | Critical and high findings, with tests and row-level security policies | 3–4 | $3,000 |
| 2 | Medium findings and CI checks, plus a re-audit | 2 | $1,500 |
| Fixes total | 5–6 | $4,500 | |
| With the $1,500 Full Audit, this is the $6,000 Audit + Fix Sprint. | $6,000 | ||
Example figures. A real quote is fixed after the audit and is valid for 14 days.
Security questionnaire answers (excerpt)
Included in the Enterprise readiness review. Written for after the phase 1 fixes.
| Question | Answer | Evidence |
|---|---|---|
| How is customer data separated between tenants? | Every table has row-level security tied to the signed-in user's team, and server actions check team membership and role. Policy tests run in CI. | JS-AUTH-01, JS-AUTH-02, JS-AUTH-03 |
| Are secrets kept out of client-side code? | Yes. Only the public anon key reaches the browser; admin keys live in server code and were rotated after the audit. | JS-SEC-01, JS-SEC-03; re-check letter |
| How do you verify payment events? | Every Stripe webhook is signature-verified and processed once, and access comes from the subscription stored on our server. | JS-PAY-01, JS-PAY-02 |
What was checked
All 52 points on the React and Node checklist, covering secrets, authorization and Supabase row-level security, input and API security, payments, the Node backend, frontend quality, signs of AI-built code, architecture and deployment. Every finding above was confirmed by hand. Tool output that turned out to be harmless is listed in an appendix, which is left out of this sample.
How each point was checked: 35 by reading the code, 7 from scanner output confirmed by hand, 7 from your answers and 2 in an isolated test environment (the type check and the production build). Not checked: 1 (JS-REL-06, hosting limits, because no traffic figures were available). It is not counted as a pass.