Your Convex mutations are public endpoints.
Updated 2026-10-14 · Plain English, written for founders who built with Lovable, Bolt, Cursor or similar.
In Convex, every function you export with query, mutation or action from ./_generated/server is public. Your deployment URL ships in your frontend so the client can connect, and anyone who has it can call those functions directly, with whatever arguments they choose. Your UI is not in the way. If a mutation does not check who is calling, anyone can run it.
Functions made with internalQuery, internalMutation or internalAction are different: they can only be called by your other Convex functions, the scheduler, crons, or you from the dashboard and CLI. They are not reachable from a browser.
Check your code
Search your convex/ folder for = mutation( and = action(. For each one, look at the handler. This is the unsafe pattern:
// UNSAFE: anyone can delete any todo, or post as any user
export const remove = mutation({
args: { id: v.id("todos") },
handler: async (ctx, { id }) => {
await ctx.db.delete(id);
},
});
export const send = mutation({
args: { userId: v.id("users"), text: v.string() },
handler: async (ctx, { userId, text }) => {
await ctx.db.insert("messages", { userId, text });
},
});
Neither handler reads ctx.auth. The first deletes whatever id it is given. The second trusts a userId argument, so a caller can send someone else's id and post as them.
Fix it: Convex Auth
Get the caller from the session, never from the arguments, and check they own the document before changing it:
import { mutation } from "./_generated/server";
import { v } from "convex/values";
import { getAuthUserId } from "@convex-dev/auth/server";
export const remove = mutation({
args: { id: v.id("todos") },
handler: async (ctx, { id }) => {
const userId = await getAuthUserId(ctx);
if (userId === null) throw new Error("Not signed in");
const todo = await ctx.db.get(id);
if (!todo || todo.userId !== userId) throw new Error("Not found");
await ctx.db.delete(id);
},
});
export const send = mutation({
args: { text: v.string() }, // no userId argument
handler: async (ctx, { text }) => {
const userId = await getAuthUserId(ctx);
if (userId === null) throw new Error("Not signed in");
await ctx.db.insert("messages", { userId, text });
},
});
Fix it: Clerk, Auth0 or another provider
With an external auth provider, ctx.auth.getUserIdentity() returns the verified identity, or null when nobody is signed in:
export const remove = mutation({
args: { id: v.id("todos") },
handler: async (ctx, { id }) => {
const identity = await ctx.auth.getUserIdentity();
if (identity === null) throw new Error("Not signed in");
const todo = await ctx.db.get(id);
if (!todo || todo.ownerToken !== identity.tokenIdentifier) throw new Error("Not found");
await ctx.db.delete(id);
},
});
Store identity.tokenIdentifier (or your own users-table id looked up from it) on each document when you create it, and compare against it later.
Get the details right
- Signed in is not the same as allowed. Most apps let anyone create an account, so after the login check you still need the ownership check.
- Make server-only work internal. If a mutation is only ever called from an action, a webhook handler or the scheduler, write it as
internalMutation. Call it withctx.runMutation(internal.file.name, args)from an action, orctx.scheduler.runAfter(0, internal.file.name, args). - Validate every argument. Use
argsvalidators such asv.id("todos"), so callers cannot pass ids from another table or values of the wrong type. - Queries need the same care. A public
querythat returns private data with no login check leaks it to anyone who calls it. - Actions can cost you money. A public action that calls an AI API or sends email, with no login check, lets strangers spend your quota.
What SecureIndie checks
This check reads your code only, when you connect your repo. It flags exported public mutation and action functions in convex/ whose handlers never read ctx.auth or call a known auth helper such as getAuthUserId. Internal functions are skipped. It does not call your deployment, and it cannot tell whether an ownership check that is there is correct, so review those by hand.
After the fix
- Sign out and call the mutation from your app's console. It should throw "Not signed in".
- Sign in as one test user and try to delete a second test user's document by its id. It should be refused.
- Look through your tables for records that were created or changed by the wrong user while the function was open.
Check your app
SecureIndie looks for this mistake. The free quick check covers the basics from outside (exposed files, keys in your site's code, headers) in about a minute. Database rules, payment webhooks and AI endpoints need the full audit, which also reads your code and proves what a visitor can actually reach.
Questions
Is my Convex deployment URL a secret?
No. The client needs it to connect, so it ships in your frontend. Each function has to decide for itself who is allowed to call it.
My UI only shows the delete button to the owner. Is that enough?
No. Anyone can call the mutation directly, without your UI, with any arguments they like. The check has to happen inside the handler.
Can I pass the user id from the client?
Not as proof of who is calling. Any caller can send any id. Get the user from ctx.auth.getUserIdentity() or getAuthUserId(ctx) inside the handler instead.
Related guides
Checks covered: CVX-AUTH-001 · If you think data already leaked