agentleFS
DariuszDuszaDariuszDusza/agentic-workflow-foundry/.agents/skills/secure-api-endpoint/SKILL.md

secure-api-endpoint

Skill1 starsChanged 26 days agoApache-2.0View on GitHub

Use when adding or modifying an API endpoint by hand (route, handler, serializer, validation, authorization policy). Applies the two-layer auth model, public-identifier-only exposure, tenant-safe persistence and the input, query, upload and log checklist.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 6 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Expose public identifiers only: Never the internal sequential or sortable id (it leaks volume and enables enumeration), never tokens, …

    line 31
  2. Distinctive:

    Uploads: check type against an allowlist.

    line 39
  3. Distinctive:

    Throttle public mutations: Every unauthenticated write route carries a rate limit.

    line 41
  4. Distinctive:

    Log without secrets: No password, token or key in a new log line.

    line 42
  5. Very specific:

    If it touches tenant data, follow .agents/skills/tenant-safe-change/SKILL.md first.

    line 49
  6. Distinctive:

    Write handler, serializer, validation, policy and route following the sibling's shape.

    line 50
  7. Distinctive:

    Write tests that assert authorization denial for the wrong role, validation failure, and the happy path, using the same URL prefix clients …

    line 51

≈ “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

Required context

  1. .agents/areas.json: the area the endpoint lives in, its guardrail and its verify command. For service code the guardrail is .agents/guardrails/code-style.md until the adopter adds a dedicated API rulebook; if one is declared, it wins.
  2. .agents/guardrails/data-handling.md: logs, PII, exposure.
  3. .agents/skills/tenant-safe-change/SKILL.md: when the endpoint reads or writes tenant data.
  4. The sibling endpoint closest to yours: its route, handler, serializer, validation and tests. The sibling is the convention in force.

For an endpoint generated from a schema, use .agents/skills/api-code-generation/SKILL.md instead; for its tests, .agents/skills/api-test-generation/SKILL.md.

The rules that bite

  • Two layers, both present. Authentication middleware establishes identity; the handler authorizes the action as its first step, before any query with side effects. A route being authenticated is not the same as the caller being allowed, and the gap is where cross-account access lives.
  • One authorization source. Register the new permission in the permission matrix the codebase already uses. An inline role check is a second mechanism that drifts from the first.
  • List endpoints scope the query to what the caller may see, rather than checking a blanket "may list everything" permission and returning the table.
  • Expose public identifiers only. Never the internal sequential or sortable id (it leaks volume and enables enumeration), never tokens, password hashes or secrets.
  • One versioned route prefix, identical in routes, tests and clients. Register a literal segment before a parameter route of the same prefix, or the parameter swallows it.
  • Validate every writable field. Clamp every page-size parameter to a hard maximum, because an unbounded page is a denial-of-service parameter.
  • Escape pattern-matching input (LIKE wildcards), and bind raw SQL parameters, never concatenate.
  • Uploads check type against an allowlist; never allow active content (SVG, HTML) without a reviewed reason, because it executes in the browser of whoever opens it.
  • Throttle public mutations. Every unauthenticated write route carries a rate limit.
  • Log without secrets. No password, token or key in a new log line.
  • Errors use the shared envelope. A new ad-hoc error shape breaks every client that parses errors generically.

Steps

  1. Confirm the resource's database connection and tenancy from the sibling model.
  2. If it touches tenant data, follow .agents/skills/tenant-safe-change/SKILL.md first.
  3. Write handler, serializer, validation, policy and route following the sibling's shape.
  4. Write tests that assert authorization denial for the wrong role, validation failure, and the happy path, using the same URL prefix clients use.

Verify

<the area's test runner, filtered to the new test class>   # fastest proof first
make verify                                                 # every gate, including tools/check-secrets.sh

Then the area's verify command exactly as .agents/areas.json declares it. Reviewers: api-standards-reviewer, security-data-reviewer, and tenant-safety-reviewer for tenant data.

Escalate when

  • The change alters the authentication or authorization model itself, not just a permission.
  • A public contract breaks: a field removed or renamed that clients read, a status code changed.
  • A new dependency is needed (.agents/policy/model-policy.md treats it as an escalation).
  • The endpoint exposes confidential data classes (.agents/policy/data-classification.yml) to a caller class that did not see them before.

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.