Why "Check This for Security Issues" Isn't Enough: Turning an Audit Workflow into a Skill
2026-11-27
|
12 mins to read
|
Share article
It starts with one sentence
Before opening a merge request you want the agent to look over your changes. The cheapest way to ask is:
Can you check whether this change has any security issues?
The model reads the code carefully and hands back a professional-looking list. The trouble is that you cannot tell how far to trust it. Spelled out, that one sentence can go wrong in seven ways:
- It doesn't find every secret, and it repeats the ones it does find into the conversation.
- Broken access control only shows up when you follow the call chain, and reading a few files won't get you there.
- Even with scanners wired in, hundreds of raw results dumped into context are more than the model can digest.
- The "findings" have no attack path, so the real ones get buried.
- It fixes things on its own initiative, breaks legitimate callers, and then reports the issue as fixed.
- Halfway through a full-repo audit, earlier findings are lost to context compaction.
- All of the rules above have to be explained again in every new session.
Let's take them one at a time.
Problem 1: the model misses secrets, and repeats them
Finding hardcoded secrets is an exhaustive job. The rules are fixed and nothing may be skipped. That is the opposite of how a model reads code: it samples and understands, it does not match byte by byte. Worse is what it does after finding one. It quotes the line to show you. Now the secret is in the conversation log and then in the report, and the exposure has grown.
The fix is to hand this kind of work to deterministic tools. The skill uses two open-source scanners: gitleaks for secrets and semgrep for injection and dangerous functions. gitleaks is called with its redaction flag, so the output carries a rule name and a location and never the secret itself.
In full-repo mode it also scans git history. The reason is in a comment in the script: a secret that has been removed from the working tree but still sits in an old commit is just as leaked. Those results get their own "history only" label.
Problem 2: a scanner can't tell who is allowed to call an endpoint
Scanners have a blind spot. No scanner will flag this:
@router.get("/orders/{order_id}")
def get_order(order_id: int, user = Depends(current_user)):
return order_repo.get(order_id) # logged in, but is this order yours?
There is no string concatenation, no dangerous function, and the auth dependency is in place. Change order_id and you are reading someone else's order. In business systems the most damaging issues tend to be of this kind: broken access control, missing tenant isolation, a hardcoded verification code left as a backdoor. What they share is the question "who can call this, and whose data can they see?", and the answer is spread across the entry point, the auth layer and the data access layer.
This half has to go to the model, but not as a free-form exercise. The skill supplies a review checklist and prescribes the method: list every entry point in scope (HTTP routes, message consumers, callbacks, scheduled jobs, agent tools) and trace each one down to data access, until "who can get in" and "what data is read or written" are both clear.
The checklist is organized by problem type, and each type says two things: how to look for it and how to fix it. The item on where identity comes from reads roughly like this:
For each entry point, find where the tenant ID and user ID come from. If they come from request parameters, the body or headers instead of the session, that is an access control lead.
So the work splits into two halves:
One sentence in the instructions ties the halves together: the scan is only complete when both are done, and a report based on one half must say so. It is there to stop the model from seeing "0 results" from the scanners and declaring the code safe.
Problem 3: how scanner results reach the model
Wiring in scanners creates a new problem. Their raw output is made for people and CI: a large JSON file in which one rule may match hundreds of times. Give that to the model directly and the context fills up first.
So a script sits in between and rewrites the output into something a model can read. The scan script in this skill is a little over a hundred lines, and four of its choices are worth copying:
Scope: changes relative to origin/main (merge base a1b2c3d4), 12 files. Raw results: ~/.sec-audit/my-repo/diff
gitleaks: 1 finding
semgrep: 12 files actually scanned
semgrep: 2 findings
gitleaks | high | generic-api-key | config/settings.py:14
semgrep | high | formatted-sql-query | api/user.py:21
semgrep | medium | avoid-v-html | src/views/Detail.vue:88
- One finding per line, four fields: tool, severity, rule, file and line. The model takes the location and reads the code itself. The script does not paste code for it.
- A cap: at most 300 lines are printed, and the rest are left in the raw JSON file.
- It prints how many files were actually scanned: zero results can mean nothing is wrong, or that nothing was scanned. This line lets the model tell them apart. Files that failed to parse are listed separately with a note that they were effectively not scanned.
- The exit code carries meaning: 0 means every scanner finished, 2 means at least one did not run.
That last point is a single line in the script:
sys.exit(2 if skipped else 0)
And the instructions say the matching thing: on exit code 2, install the tool or resolve the error and rerun, and never conclude "no issues" while a scanner has not finished. The script reports the state clearly, the instructions say which conclusions that state permits, and the two are written as a pair.
Problem 4: a pile of "findings", and which ones are real
An unconstrained model is happy to over-report. "This endpoint may be vulnerable to unauthorized access" and "consider strengthening input validation" will fill twenty rows. None of them is wrong, and none of them can be prioritized.
The skill sets a bar. Every finding must state four things:
| Element | The question it answers |
|---|---|
| File and line | Where is the problem |
| Reachable from which entry point | How does an outside request get to this line |
| Who the attacker is | Unauthenticated, regular user, another tenant, sub-account |
| What they can read or change | The consequence |
Anything that can't fill all four is not a finding. It goes into a separate "open questions" list for a person to judge. The instructions also say why: findings without an attack path bury the real ones and can't be prioritized.
The same rule drives severity. Severity is not decided by vulnerability type. It is decided by what identity the attacker needs: reading or writing other people's data with no login is critical, needing another provisioned business identity is high, needing a specific precondition is medium. Every cell in the severity table is a value of the "who the attacker is" column, so a finding that is missing that element can't even be graded.
Scanner results get a similar requirement: open the code for each one and decide whether it is real, and count false positives only at the end of the report. When one rule matches a hundred times, skipping the whole rule is not allowed. Each match's data source has to be checked and the ones fed by user input pulled out.
Problem 5: it fixes things unasked, then says "fixed"
A model that sees a problem wants to fix it, which is normally a strength. But some security fixes hurt legitimate users: add authentication to an old endpoint and every existing caller may fail at once.
The skill draws three lines here.
First, when it may act. If the user asked for a scan or a check, stop at the report and ask which items to fix. Continue only when the user asked for fixes or remediation.
Second, what it may fix. Each finding is classified first:
- Safe to fix directly: the change stays inside the implementation, doesn't alter the interface contract, and doesn't change what legitimate callers see. Examples are parameterizing concatenated SQL, taking identity from the session, adding an ownership check before reading or writing by ID, and masking logs.
- Needs a human decision: list it and don't touch it. Examples are endpoints where adding auth would break current callers, legacy endpoints due for removal, cases where nobody has defined the permission rules, anything involving money, and every finding about secrets.
Secrets get an extra sentence: any secret that has been in the repository is treated as leaked, deleting it from code does not resolve it, and rotation has to be done by a person. The report may only say "removed from code, rotation pending".
Third, what counts as fixed. After fixing, rerun the scan, confirm the entries are gone and nothing new appeared, then run the project's own tests. The instruction is blunt: nothing may be marked fixed without a rescan.
One more constraint targets a shortcut: don't add ignore rules to make the scanner go quiet. There are two ways to make a warning disappear. You can fix it, or you can add an ignore comment on that line. If all the model is told is "make the scan pass", the second is the shorter path.
Problem 6: halfway through, the early findings are gone
A full-repo audit reads a lot of code. As the session grows, earlier content gets compacted or truncated. If findings live only in the conversation, the conclusions from batch one may be incomplete by batch eight.
The fix is to keep state outside the context:
- In full-repo mode, list every entry point first, review in batches, and write the findings to the report file after each batch before moving on.
- The report and the raw scanner output live in a fixed location under the user's home directory, one folder per repository. Keeping them outside the repo is deliberate. The report describes unfixed vulnerabilities and must not get committed by accident.
- Before each scan, check that folder for earlier reports. Issues already reported are marked as pre-existing and not reported again as new.
That last point gives the report an "origin" column: introduced by this change, widened by this change, or pre-existing. For a pre-merge check, the ones introduced by this change come first, because those are what this merge request is responsible for.
Problem 7: explaining the rules again every time
At this point each of the first six problems has an answer, and together they make a long briefing: which script to run first, how to triage results, where the checklist is, what the report looks like, what must not be changed. Pasting that into every session is not realistic. Putting it all in the project's always-loaded instruction file is too heavy, because most sessions never do a security audit and would still pay context for those hundreds of lines.
This is the problem a skill solves: store a workflow as files and load it only when it is needed.
Physically it is a directory:
sec-audit/
├── SKILL.md # required: trigger description + workflow instructions
├── references/
│ └── checklist.md # the review checklist, read when needed
└── scripts/
├── scan.py # the scan script, executed and never read in
└── selftest.py # self-test
Placed under ~/.claude/skills/ it applies to all of your projects. Placed under a repository's .claude/skills/ it travels with the project.
Loading happens in three levels, and this is the core mechanism:
| Level | Content | When it costs context |
|---|---|---|
| 1 | Name and description | Every session |
| 2 | SKILL.md body | After the skill triggers |
| 3 | Reference files, scripts | When the body says to read or run them |
In frontend terms, level one is the route table, level two is a lazy-loaded page component, and level three is the modules that page imports on demand. The analogy fails in one place: route matching is deterministic, while a skill triggers because the model read the description and made a judgment. A vague description means the skill may not trigger when it should.
That explains why the description reads like a list of trigger phrases:
---
name: sec-audit
description: Code security scanning and remediation. Runs scanners for a
deterministic pass, then reviews access control, tenant isolation and similar
issues against a checklist, writes a report, fixes and rescans. Use when the
user says "security scan", "pre-MR security check", "full-repo security
audit", "any broken access control", "fix the security issues". Also use it
to confirm a change introduced no security problems before an MR. Do not read
the code and conclude from intuition.
---
It has three parts: what the skill does, the phrases users will actually say, and one negative constraint. That final sentence addresses the scenario this post opened with, where the model believes it can answer directly and bypasses the skill.
The three levels also decide where content goes. The twelve categories of review items run to a hundred lines and sit in references/, and a frontend project needs to read only two of those sections. The scan script sits in scripts/, where the model executes it and its source never enters context. The body keeps only the workflow and constraints, at just over a hundred lines.
The last step: knowing the install works
The skill depends on two external scanners. Whether they are installed, whether the version is right, whether rules can be downloaded: any of these can fail. And the worst way for a scanner to fail is to quietly return zero results.
So the directory includes a self-test script of under forty lines that does something very direct:
SAMPLE = '''
GITHUB_TOKEN = "<a correctly formatted fake token>"
@app.route("/user")
def user():
return str(conn.execute("select * from t where id = '%s'" % request.args["id"]).fetchall())
'''
# create a repo in a temp directory, write the sample above, run a full scan
assert proc.returncode == 0, "a scanner did not finish"
assert "gitleaks | " in proc.stdout, "the fake secret was not reported"
assert "semgrep | " in proc.stdout, "the SQL concatenation was not reported"
assert FAKE_TOKEN not in proc.stdout, "a secret value appeared in the output"
It builds a sample with known problems, asserts that both scanners report them, and asserts that the output contains no secret value. The last assertion verifies the redaction promise from problem one.
One detail: the fake token in the script is assembled from two string pieces. Otherwise the self-test file would itself be flagged by the secret scanner.
Principles to take with you
This skill is about security audits, but its structure fits anything you want an agent to do repeatedly and reliably:
- Divide the work first. What can be written as rules and must have zero misses goes to code. What needs an understanding of context goes to the model.
- Script output is written for the model. Short, fixed in structure, able to prove it covered everything, and explicit about failure through the exit code.
- Set an evidence bar for conclusions. What doesn't meet it is listed separately and kept out of the conclusions.
- Write down the stopping points. When to report without acting, and which changes a person must decide.
- Completion needs a verification step. Without a rerun, nothing is marked done.
- Persist state. Intermediate results of long tasks go into a file, not into conversational memory.
- Give the reason with the rule. A model that knows what a rule is guarding against can handle cases the checklist didn't cover in the same spirit.
- Write the description as trigger phrases. List what users will actually say, and add a sentence that stops the model from bypassing the skill.
A minimal skeleton to start from:
---
name: <skill name>
description: <what it does>. Use when the user says "<phrase 1>" or "<phrase 2>". Also use it when <the case where it tends to get bypassed>.
---
# <Title>
## Workflow
### 1. Set scope
### 2. Run the script
`python scripts/<script>.py`. Draw no conclusion on a non-zero exit code.
### 3. Judge
Read `references/<checklist>.md` and go through every item.
### 4. Output
Write to <fixed location> using this template...
### 5. Verify
## Constraints
- <what must not be done, and why>
Look back at the opening request, "can you check whether this change has any security issues?" What it lacked was not a stronger model. The same model, given a division of labor, an evidence bar, stopping points and a verification step, produces something you can schedule and review. A skill fixes those instructions in place so they are present every time.