agentleFS
blitzhash360-webblitzhash360-web/blitzhash-vibe-coding-rules/skills/secure-api-endpoint/SKILL.md

secure-api-endpoint

Skill0 starsChanged 23 days agoMITView on GitHub

Build or fix an API route, server action or backend function so it is secure by default - authentication, ownership checks, schema validation, safe errors, rate limits and tests for the unhappy paths. Use when the user asks to add an endpoint, form handler, server action, cloud function or "backend for this button", or asks whether an existing route is safe.

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. DariuszDusza/agentic-workflow-foundry★ 1same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository8 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Authenticate on the server: Use the project's existing auth helper (Auth.js auth(), Clerk, Supabase getUser(), Firebase verifyIdToken).

    line 22
  2. Very specific:

    Limit abuse: If public, auth-related or paid, add a rate limit with a shared store (see add-rate-limiting).

    line 26
  3. Distinctive:

    Test the unhappy paths: Add tests or a short manual script for: no session (401), other user's id (403/404), invalid body (400), over the …

    line 28
  4. Distinctive:

    Never weaken an existing check (auth, CSRF, RLS, CORS) to make a test pass.

    line 37
  5. Distinctive:

    Do not run migrations or call production APIs while building the endpoint.

    line 39

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 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

Secure API endpoint

AI tools write the happy path well. This skill makes sure the other paths exist: the stranger, the wrong user, the bad input, the script that calls it 10,000 times.

When to use

  • Adding a new API route, server action, Firebase or Supabase function, Express or FastAPI handler.
  • Reviewing an existing route before launch, or after "it works but is it safe?".

Steps

  1. Classify the endpoint. Who may call it (public, signed-in, owner, admin)? What does it read or write? Does it cost money (AI, SMS, email)? Write the answer as a one-line comment above the handler.
  2. Authenticate on the server. Use the project's existing auth helper (Auth.js auth(), Clerk, Supabase getUser(), Firebase verifyIdToken). Return 401 if missing. Never read identity from the body.
  3. Authorize the exact record. Load the record, compare its owner or org to the session user, return 403 (or 404 to avoid confirming it exists). For lists, filter by the user in the query itself.
  4. Validate input with a schema (zod, valibot, pydantic): strict object, lengths, enums, ranges. Pick fields explicitly before writing to the database.
  5. Access data safely. Parameterized queries or the ORM; least-privilege client; no admin key unless the operation truly needs it, and then still filter by user.
  6. Limit abuse. If public, auth-related or paid, add a rate limit with a shared store (see add-rate-limiting).
  7. Handle errors. Wrap in a boundary that logs the real error with a request id and returns a generic message. Fail closed.
  8. Test the unhappy paths. Add tests or a short manual script for: no session (401), other user's id (403/404), invalid body (400), over the limit (429), happy path (200).
  9. Summarize what the endpoint allows, for whom, and which checks you added.

Output format

The handler code, the tests, and a 5-line summary: caller, auth check, authorization rule, validation, rate limit.

Safety rules (always)

  1. Never weaken an existing check (auth, CSRF, RLS, CORS) to make a test pass. Ask first.
  2. Credentials only from environment variables. Never print, log or commit keys; use placeholders in examples.
  3. Do not run migrations or call production APIs while building the endpoint. Use local or staging resources, and show any command that changes data before running it.

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.