secure-code-loop
Skill0 starsChanged 17 days agoMITView on GitHub
Use when the user types /secure-code-loop, when code written or changed must be secured, audited or hardened, when the user asks to run the security scanners, for a security review or for code without flaws, when Semgrep, Gitleaks, Trivy, SonarQube, Bandit, gosec, cargo audit, npm audit or OSV is named, when a secret or a vulnerable dependency turns up, or when the clean-code skill reports security findings.
- Reads credentials
In this repository17 other files it gives its agents.
- browser-bidiSkill
- claude-model-effortSkill
- clean-architectureSkill
- clean-codeSkill
- clean-commitsSkill
- code-mapSkill
- drive-projectSkill
- least-codeSkill
- limited-runSkill
- other-model-effortSkill
- progress-boardSkill
- resource-guardSkill
- stop-resume-agentsSkill
- strip-ai-tracesSkill
- terse-speechSkill
- using-git-worktreesSkill
- writing-skillsSkill
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
- Distinctive: line 36
Never delete, disable, edit or weaken a test that existed at start.
- Very specific: line 37
Never silence a finding to make it go away: no # nosemgrep, # nosec, // NOSONAR, @SuppressWarnings, gitleaks:allow, ignore file or rule …
- Very specific: line 49
Only manifest entries get deleted.
- Distinctive: line 87
Run all tests, old and temporary.
- Distinctive: line 153
No step-by-step story, no copy of JSON.
≈ “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.
Files
Secure code loop
Scan, fix, rescan until no serious finding is left in scope. Scanners run on this machine, tests end at least as green as they started, code does not swell, and no temporary file stays behind. The clean-code skill audits and tidies; this skill is the loop that gets code through the security scanners.
<skill> = this folder. Scripts need Python 3, standard library only, and never install anything:
python -I "<skill>/scripts/start.py" --root "<project>" [--base <revision> | --scope <path>...]
python -I "<skill>/scripts/scan.py" --work "<work>" --passed <n> --failed <n>
python -I "<skill>/scripts/finish.py" --work "<work>" [--close --passed <n> --failed <n>]start.py records files, uncommitted changes, test digests and line counts in a work folder under system temp
(nothing in the project or .git), prints work:, three ledger: paths, tool: lines (ready, missing, not
needed), stack: lines (manifests) and not covered: for a category without scanner. scan.py runs every
scanner present (two workers, below normal priority, JSON into work folder), merges duplicates, raises injection,
path, deserialisation, XXE, SSRF and hardcoded-secret CWEs to high, ends on stop: or continue:. finish.py
deletes what the manifest lists, puts old tests back, prints report material. Exit 2 = refused: lines, 1 =
failure. Other flags (--offline, --rules <folder>, --timeout): --help.
Scope: --base = files changed since that revision; --scope = files or folders named; neither = whole project;
files touched after start join it. --passed, --failed = counts of the test run just before the call, errors
as failed. Row = <label>: <level> <key> <path>[:<line>] <tools> <ids>: <message>, key stable across line shifts.
Rules
These hold on every run, whatever the scope.
- Never delete, disable, edit or weaken a test that existed at start; one red at start must not get worse.
- Never silence a finding to make it go away: no
# nosemgrep,# nosec,// NOSONAR,@SuppressWarnings,gitleaks:allow, ignore file or rule switched off. Proven false positive = line<key> <reason>infalse-positives.txt, reason drawn from real data flow ("internal code" is none); code stays as is. - Nothing about the code leaves the machine: no
semgrep login, no cloud option, no upload. Scanners reach only public rule and advisory sources; web queries hold public package names and versions, never code, paths, secrets, hosts or project names.scan.py --offlinecuts all downloads. - Fix the cause: swap the dangerous API for the safe one (bound parameters, argument list without shell,
yaml.safe_load,secrets), never a filter on top when a safe API exists. - Minimal change: touch only what a finding needs, rewrite nothing around it.
- Scanner missing: install only with user's consent; otherwise go on with what is present, report the gap.
- Secret found: move it to environment (sample entry in
.env.example), never print it, tell user to revoke it: it sits in git history once committed. Never rewrite history without consent. - Only manifest entries get deleted. Each temporary file goes into
manifest.txtthe moment it exists.
Heavy runs: guard.py wait of the resource-guard skill before scan.py and each test run (Claude Code hook does
it), start on exit 0. Long scan goes through the limited-run skill, so all scanners share one memory cap:
python -I "<limited-run>/scripts/run.py" start --name secure-scan -- python -I "<skill>/scripts/scan.py" ...SonarQube is used only when a server already answers on this machine with SONAR_TOKEN set; starting one
(docker with mem_limit and --cpus 1) is the user's call.
Procedure
Steps 4 to 10 repeat until scan.py prints stop:.
start.pywith scope.old temporary:line = leftover of an earlier run: ask before deleting it.- New code to write, or
not covered: code: readreference/checklist.mdand review scope files against it. Each flaw seen by hand becomesopen <level> review-<n> <file> : <flaw>inadvisories.txt, so loop counts it. - Baseline: run the project's tests once, note passed and failed.
scan.pywith baseline counts.- Known advisories, once after first scan and again after each dependency bump. Machine sources first:
osv,npm-audit,pnpm-audit,cargo-audit,trivyrows. Then web search for what they miss: runtime, framework, plugin and engine versions behindstack:lines, packages without lockfile pin, private registries. Query = public name plus version (<name> <version> CVE,<name> <version> security advisory); trust vendor advisory, GitHub Advisory Database or NVD; a forum, blog or unknown repository alone proves nothing (results hold fake trackers). Each hit that applies goes intoadvisories.txtasopen <level> <id> <file|-> : <note>; after the fix it turnsfixed, ornot-applicablewith its reason. - Triage in this order: secrets, blocker and critical, high, vulnerable dependency with fix, then medium and lower. Each row: read whole function, callers and callees, decide true or false positive.
- Fix in triage order, per the rules. Dependency: lowest fixed version compatible with the project, through its package manager so the lockfile follows, then build. Check the fix opens no new checklist hole (validation with ReDoS, lock held during I/O).
- Non-trivial fix gets a temporary test proving the hostile input is blocked, nothing more:
../../etc/passwdrefused, quote in SQL input kept as value, URL to127.0.0.1or169.254.169.254refused, fresh IV per encryption, archive entry with../refused. Names:test_secureloop_tmp_*.py,secureloop-tmp-*.test.ts,*_secureloop_tmp_test.go,SecureLoopTmp_*Test.javaor.php,secureloop_tmp_*.spec.luau. Path intomanifest.txtat once. - Run all tests, old and temporary. Old test passing before, failing now: fix is wrong or too broad, redo it. Temporary test failing: fix incomplete.
scan.pywith new counts; act on its last line (table below).- On
stop:: each temporary test passing now stays as regression test: rename it to project's test naming without thesecureloop_tmppart (test_secureloop_tmp_sql.py->test_security_sql.py), drop its line frommanifest.txt. Failing one stays listed and gets deleted. Thenfinish.py, then old tests once more, thenfinish.py --closewith those counts. - Report (last section).
Lines of scan.py
Last line decides; others say what to do before the next scan.
| Line | Do |
stop: clean | no blocking finding in scope, tests at least as green as iteration 1: step 11 |
stop: limit of 5 iterations | step 11, report what remains |
stop: stalled, ... | blocking count did not drop over two iterations: step 11, present remaining rows to user as design decisions |
stop: no scanner ran | step 2 by hand, then step 11; ask user before installing a scanner |
continue: <n> blocking in scope | fix fix: rows, step 9, rescan |
continue: ..., tests worse than iteration 1 | regression first: redo the fix, never the old test |
continue: ..., old tests touched | rule 1 broken: undo the change to old tests, rescan |
fix: | blocking in scope: fix |
also: | medium or lower in scope: fix when cheap, else report |
elsewhere: | blocking outside scope: report, fix only with user's consent |
revoke: | secret in git history: rule 7, never blocks |
more: <n> rows in findings.json | rest in <work>/iteration-<n>/findings.json |
tool: <name> <place> missing | rule 6 |
tool: <name> <place> failed: ... | rerun once; failing again, report it |
tool: <name> <place> skipped: ... | offline, no server or nothing to scan: report it |
not covered: code, secrets, dependencies | code: step 2; secrets: rg line of the checklist; dependencies: step 5 by web |
bad line: <ledger>: ... | that ledger line is not applied: fix it |
bloat: over 30%, ... | share one helper instead of copies, drop extra checks |
changed test:, missing test: | rule 1 broken: undo now |
Lines of finish.py
Cleanup lines come first, report material after.
| Line | Do |
deleted: <file> | nothing |
kept: <entry> (a folder: list its files) | put its files in the manifest, rerun finish.py |
kept: <entry> (<why>) | existed at start, ignored, tool folder or outside project: never delete it by hand |
restored: <file> | old test or file put back from git: rerun old tests |
changed test:, missing test:, gone: | could not be put back (uncommitted at start, no git): tell user |
left: <file> | temporary file missing from manifest: add it, rerun finish.py |
new since start: <file> | kept; name it in report so user sees it |
tool: <name> <place> skipped: ... or failed: ... | that place went unchecked at the last scan: report it as not covered |
closed: <work> deleted | done |
--close refuses while changed test:, missing test: or left: lines remain, or tests are worse than iteration 1.
Report
Short, in the user's language, from finish.py lines:
- tools used, tools missing, what was not covered;
- blocking findings at iteration 1 and at last scan, by level;
- each fix on one line: file, problem, fix;
- false positives with reason, advisories with state;
- what remains and why (out of scope, design decision, iteration limit);
- secrets to revoke;
- tests at start and at end;
- cleanup: security tests kept as regression tests, other temporary files deleted, no old test touched.
No step-by-step story, no copy of JSON.
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
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.

