Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 5 min read

api-security-audit maps every endpoint in your API before it looks for a single bug

Why the inventory comes before the bug hunt Most security passes over an API are a pattern search. You grep for eval, for string-built SQL, for jwt.decode, and you get a list. That list will never contain the two bugs

api-security-audit maps every endpoint in your API before it looks for a single bug

Why the inventory comes before the bug hunt

Most security passes over an API are a pattern search. You grep for eval, for string-built SQL, for jwt.decode, and you get a list. That list will never contain the two bugs that actually leak an API: broken object level authorization and broken function level authorization. Nothing about findById(req.params.id) looks wrong on its own. It is wrong only next to the sibling handler that scopes the same query to the caller.

So the first thing api-security-audit does is build an endpoint inventory. One row per method and path, with the handler at file and line, whether authentication applies, which ownership or tenant check runs, which input the caller controls, and whether the operation is sensitive. It follows every use, include_router and mount on the way, including the /v1 router nobody remembers mounting, and notes middleware order, because a guard registered after a router does not protect it.

Then it reads the rows against each other. A GET /things that filters by the current user sitting next to a GET /things/:id that does not is the finding, and that finding only exists as a comparison.

// Detect dark theme var iframe = document.getElementById('tweet-2123268852196786589-695'); if (document.body.className.includes('dark-theme')) { iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=2123268852196786589&theme=dark" }

Install it, then ask for it by name

npx claude-code-templates@latest --agent security/api-security-audit

That writes .claude/agents/api-security-audit.md in your project. Project agents win over ~/.claude/agents/ on a name collision, so an installed copy overrides your personal one.

The frontmatter is four lines and both of the interesting ones are worth knowing:

tools: Read, Grep, Glob, Bash
model: inherit

tools is an allowlist. The agent gets those four and nothing else, no MCP tools unless you name them, which is how a security auditor stays unable to edit your code. model: inherit means it runs on whatever model the main conversation is on, so an audit does not silently drop to a cheaper model than the session you started.

Claude Code routes to it from the description field plus your request, so "audit the security of our API" usually lands. For a guarantee, name it: "use the api-security-audit subagent on src/routes". Worth knowing that /agents is no longer a creation wizard; it now prints a reminder to edit .claude/agents/ directly.

What comes back

The agent runs in its own context window and the main conversation only gets its final message, so you get a report, not a transcript of the search. The report has a fixed shape:

  1. One line: how many endpoints mapped, how many findings, by severity.
  2. Findings, most severe first. Each one carries the OWASP category (API1:2023 and friends), file:line plus variants, the exact request an attacker would send, the missing check in a sentence or two, and the fix as a specific code change.
  3. The condensed endpoint inventory, with the vulnerable rows marked.
  4. β€œChecked and fine”: the risky-looking places it examined and why they are safe.
  5. β€œWorth a look” and β€œNot checked”.

Items 4 and 5 are the ones I would not have thought to ask for. β€œChecked and fine” tells you what coverage you actually got, and β€œNot checked” is where gateways, WAFs and anything outside the repository go, instead of being quietly assumed away.

Before any of that, every candidate goes through a refutation step: trace the whole path to the sink, look for a global guard or an ORM default scope that already blocks it, confirm the route is really mounted, and name the attacker as unauthenticated, any logged-in user, or a user of another tenant. If an admin is needed to attack an admin feature, it is not a finding. The bar is 80% confidence that it is exploitable; weaker suspicions get one line under β€œWorth a look”.

What it will not do

The β€œdo not report” list is as much of the design as the checks are. It will not tell you to add rate limiting everywhere, add a WAF, or add security headers to a JSON API. It will not report outdated dependencies with no reachable vulnerable call, example secrets in .env.example, or MD5 used for an ETag. Regex and recursion denial of service is out, with the narrow exception of unbounded page sizes, uploads and paid-API calls per request.

It is also read-only by construction. Fixes come back as patches in the report, each with the regression test that fails while the hole is open, and the main conversation applies them if you say so.

// Detect dark theme var iframe = document.getElementById('tweet-2122012847958007962-202'); if (document.body.className.includes('dark-theme')) { iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=2122012847958007962&theme=dark" }

When it does run something, it is bounded: only localhost, only after checking that DATABASE_URL and the config point at a local or throwaway database, with outbound side effects such as email, SMS, payments and webhooks stubbed first. No traffic to production or staging, no brute force, no real credentials it finds in the repo. Each finding says whether it was proven by running it or by reading the code.

One caveat the install does not tell you: listing Bash in tools makes the tool available, it does not grant permission. Subagents inherit the parent conversation permission rules, so your settings.json deny rules still apply to everything this agent runs. If your project denies Bash broadly, the agent falls back to reading code and says so under "Not checked".

// Detect dark theme var iframe = document.getElementById('tweet-2115255736561234301-950'); if (document.body.className.includes('dark-theme')) { iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=2115255736561234301&theme=dark" }

A second caveat, on the agent file itself: its description carries three example blocks, and the combined descriptions of all your subagents have a 15,000 token budget before Claude Code warns you at startup. It is a warning, not a hard cap, but install a dozen agents with descriptions this long and that is where the startup message comes from.

Where the Agents live

You can follow me on my social media:

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.