{"slug": "a-10-minute-pre-merge-security-check-you-can-hand-to-your-ai-coding-agent", "title": "A 10-minute pre-merge security check you can hand to your AI coding agent", "summary": "A developer published a 10-minute pre-merge security checklist that scans a git diff for leaked credentials, injection patterns, missing authorization checks, CI/Docker misconfigurations and untested functions, then packaged it as a SKILL.md file so coding agents like Claude Code, Codex CLI and Cursor can run it automatically. The writeup stresses two guardrails for the agent version: requiring it to confirm or discard each grep hit before reporting a vulnerability, and forbidding it from printing full secrets into the chat log. The checklist returns a BLOCK, FIX or SHIP verdict with a ranked fix list.", "body_md": "Most leaked keys and injection bugs that reach main were not hard to find. Nobody looked. The reviewer read the logic, the tests passed, and the `.env` value pasted into a config file went out with the rest.\n\nHere is a check to run on every diff before it merges. It takes about ten minutes by hand. Further down, I show how to make an AI coding agent run it for you.\n\nReviewing the whole repo is how checks get skipped. Start from the diff:\n\n```\ngit diff -U0 origin/main...HEAD\n```\n\n`-U0` drops context lines, so every `+` line is new code. That is the code you are responsible for.\n\nSearch the added lines for anything that looks like a credential:\n\n```\ngit diff -U0 origin/main...HEAD | grep -E '^\\+' | \\\n  grep -Ei \"(api[_-]?key|secret|token|passw(or)?d)\\s*[:=]\\s*['\\\"][A-Za-z0-9_/+=-]{12,}['\\\"]|AKIA[0-9A-Z]{16}|BEGIN (RSA |EC |OPENSSH )?PRIVATE KEY\"\n```\n\nIf a real secret shows up, deleting it in the next commit is not enough. It is in the history. Rotate it.\n\nThree patterns cover most injection bugs in Python web code:\n\n| Pattern | Example | Fix | \n|---|---|---|\n| SQL built from strings | `f\"SELECT * FROM users WHERE id = {uid}\"` | Parameterized query: `cur.execute(\"... WHERE id = %s\", (uid,))` | \n| Shell with user input | `subprocess.run(cmd, shell=True)` | Pass a list, drop `shell=True` | \n| Unsafe deserialization | `pickle.loads(body)` ,`yaml.load(f)` | `json.loads` ,`yaml.safe_load` | \n\nA grep finds candidates. It does not find bugs. For each hit, trace where the input comes from. A query built from a constant is fine. A query built from `request.args` is not.\n\nGrep cannot do this one. For every new route or handler in the diff, answer two questions:\n\nThe second one is the one that gets missed. `GET /invoices/<id>` that checks login but not ownership lets any user read any invoice.\n\nIf the diff touches a `Dockerfile` or `.github/workflows/`, check these:\n\n`:latest`\n`USER` before `CMD`\n`curl ... | sh`\n`permissions:` block that starts at `contents: read`\n`${{ github.event.* }}` pasted straight into a `run:` step. Pass it through an env var instead:\n\n```\n- run: echo \"$TITLE\"\n  env:\n    TITLE: ${{ github.event.issue.title }}\n```\n\nList the functions the diff adds or changes, then check whether any test mentions them. A function that parses input, handles money or dates, or touches files and has no test is a FIX, not a SHIP.\n\nClaude Code, Codex CLI, Cursor and most other coding agents now read `SKILL.md` files: a folder with instructions and optional scripts that the agent loads when the task matches. A pre-merge skill looks like this:\n\n```\n---\nname: premerge-check\ndescription: Run before merging a branch. Checks the diff for secrets,\n  injection, missing auth, CI and Docker misconfig, and untested changes,\n  then returns BLOCK, FIX, or SHIP with a ranked fix list.\n---\n\n1. Run `git diff -U0 origin/main...HEAD`.\n2. Run the secret and injection greps on added lines. Treat hits as leads.\n3. Read each flagged file and confirm or discard the lead.\n4. For each new route, confirm identity and ownership checks.\n5. If Dockerfiles or workflows changed, check the CI list.\n6. List changed functions with no test.\n7. Verdict: BLOCK on any committed secret or exploitable injection,\n   FIX on high findings or untested input handling, otherwise SHIP.\n8. Never print a full secret. Do not edit files unless asked.\n```\n\nSave it as `~/.claude/skills/premerge-check/SKILL.md` (Codex reads `.agents/skills/`). Then ask the agent to \"check this branch before I merge\" and it follows the steps.\n\nThe parts that make this work are rule 3 and rule 8. Without \"confirm or discard the lead,\" agents report every grep hit as a vulnerability. Without \"never print a full secret,\" they paste your key into the chat log.\n\nWhat do you check before merging that is not on this list?\n\n*This post was written with help from an AI assistant. The commands were tested on a sample repo before posting.*", "url": "https://wpnews.pro/news/a-10-minute-pre-merge-security-check-you-can-hand-to-your-ai-coding-agent", "canonical_source": "https://dev.to/rhussa02/a-10-minute-pre-merge-security-check-you-can-hand-to-your-ai-coding-agent-10ah", "published_at": "2026-11-25 19:09:13+00:00", "updated_at": "2026-11-25 19:14:59.147884+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "ai-safety"], "entities": ["Claude Code", "Codex CLI", "Cursor", "GitHub Actions"], "also_reported_by": [], "takeaway": "Wrapping a diff-scoped secret and injection grep in a SKILL.md file lets a coding agent run pre-merge checks, but only if the skill requires it to confirm or discard each grep hit and never print full secrets.", "recommendation": {"advice": "Package pre-merge checks as a SKILL.md that greps the diff, requires the agent to confirm or discard each hit, and forbids printing full secrets.", "playbook": "coding-agents", "playbook_url": "https://wpnews.pro/playbooks/coding-agents"}, "alternates": {"html": "https://wpnews.pro/news/a-10-minute-pre-merge-security-check-you-can-hand-to-your-ai-coding-agent", "markdown": "https://wpnews.pro/news/a-10-minute-pre-merge-security-check-you-can-hand-to-your-ai-coding-agent.md", "text": "https://wpnews.pro/news/a-10-minute-pre-merge-security-check-you-can-hand-to-your-ai-coding-agent.txt", "jsonld": "https://wpnews.pro/news/a-10-minute-pre-merge-security-check-you-can-hand-to-your-ai-coding-agent.jsonld"}}