agentleFS
charanjit-singhcharanjit-singh/lovable-skills/skills/server-input-validation/SKILL.md

server-input-validation

Skill10 starsChanged 6 months agoMITView on GitHub

Use when validating request bodies in edge functions, RPC payloads, or any server endpoint — Zod (or similar) on the server, never trusting the client. Not for client-only forms (use typed-api-hooks-forms).

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Verify JWT / webhook signature.

    line 42
  2. Distinctive:

    Never import server secrets into shared files.

    line 50

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Server input validation

Client Zod (typed-api-hooks-forms) improves UX; server validation is mandatory for security.

Edge function pattern

import { z } from "npm:zod@3";

const createProjectSchema = z.object({
  name: z.string().min(1).max(80),
  organization_id: z.string().uuid(),
});

let body: unknown;
try {
  body = await req.json();
} catch {
  return jsonError(400, "invalid_input", "Body must be valid JSON");
}

const parsed = createProjectSchema.safeParse(body);
if (!parsed.success) {
  return new Response(
    JSON.stringify({ error: "invalid_input", details: parsed.error.flatten() }),
    { status: 400, headers: { "Content-Type": "application/json" } },
  );
}
const { name, organization_id } = parsed.data;

Auth + validation order

  1. Verify JWT / webhook signature.
  2. Parse and validate body with Zod.
  3. Authorize (membership, RLS via user-scoped client, or explicit check).
  4. Execute mutation.

Share schemas (optional)

  • shared/schemas/project.ts imported by Vite + edge via duplicate or npm workspace — keep shapes identical.
  • Never import server secrets into shared files.

RPC arguments

Validate inside SQL function with raise exception or validate in edge before rpc().

Avoid

  • const { name } = await req.json() without schema.
  • Trusting user_id from body — use auth.uid() from JWT.
  • Returning stack traces to clients in production.

Checklist

  • Every edge POST/PATCH has a Zod schema
  • 400 on validation failure with stable error code
  • Authorization after validation

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.