<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: rhussa02</title>
    <description>The latest articles on DEV Community by rhussa02 (@rhussa02).</description>
    <link>https://dev.to/rhussa02</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4265405%2F811c31da-7711-498d-b898-e0f04dbb4e0a.png</url>
      <title>DEV Community: rhussa02</title>
      <link>https://dev.to/rhussa02</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rhussa02"/>
    <language>en</language>
    <item>
      <title>Catch leaked API keys before git commit, with a 35-line Python hook</title>
      <dc:creator>rhussa02</dc:creator>
      <pubDate>Wed, 25 Nov 2026 19:25:37 +0000</pubDate>
      <link>https://dev.to/rhussa02/catch-leaked-api-keys-before-git-commit-with-a-35-line-python-hook-21ba</link>
      <guid>https://dev.to/rhussa02/catch-leaked-api-keys-before-git-commit-with-a-35-line-python-hook-21ba</guid>
      <description>&lt;p&gt;Deleting a leaked key in your next commit does not remove it. The key is still in history, and bots scrape public repos for new keys within minutes. The only reliable fix is to stop the commit before it happens.&lt;/p&gt;

&lt;p&gt;Git has a hook for that. A &lt;code&gt;pre-commit&lt;/code&gt; script runs before every commit, and a non-zero exit code cancels it. The script below scans only the staged lines, so it stays fast on large repos.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it looks for
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;AWS access key IDs (&lt;code&gt;AKIA&lt;/code&gt; or &lt;code&gt;ASIA&lt;/code&gt; plus 16 characters)&lt;/li&gt;
&lt;li&gt;Private key blocks&lt;/li&gt;
&lt;li&gt;GitHub, Slack, Stripe and Google tokens, which all have recognizable prefixes&lt;/li&gt;
&lt;li&gt;Assignments like &lt;code&gt;api_key = "..."&lt;/code&gt; with a long literal value&lt;/li&gt;
&lt;li&gt;Connection strings with a password in them, like &lt;code&gt;postgres://user:pass@host&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It skips lines containing words like &lt;code&gt;example&lt;/code&gt;, &lt;code&gt;placeholder&lt;/code&gt; or &lt;code&gt;changeme&lt;/code&gt;, so your README snippets do not trip it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The script
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;#!/usr/bin/env python3&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;

&lt;span class="no"&gt;RULES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"AWS access key id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"\b(AKIA|ASIA)[0-9A-Z]{16}\b"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Private key block"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"-----BEGIN (RSA |EC |OPENSSH |DSA |PGP )?PRIVATE KEY"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"GitHub token"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"\bgh[pousr]_[A-Za-z0-9]{36,}\b"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Slack token"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"\bxox[abprs]-[A-Za-z0-9-]{10,}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Stripe live key"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"\b(sk|rk)_live_[A-Za-z0-9]{16,}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Google API key"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"\bAIza[0-9A-Za-z_\-]{35}\b"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Generic secret assignment"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"""(?i)\b(api[_-]?key|secret|token|passw(or)?d)\b\s*[:=]\s*['"][^'"\s]{12,}['"]"""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Connection string with password"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"[a-z]+://[^:/\s]+:[^@/\s]{6,}@"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="no"&gt;SAFE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"(?i)example|placeholder|changeme|dummy|xxxx|&amp;lt;[^&amp;gt;]+&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;mask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"([A-Za-z0-9_\-/+=]{4})[A-Za-z0-9_\-/+=]{4,}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"\1****"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;diff&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"git"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"diff"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"--cached"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"-U0"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                      &lt;span class="n"&gt;capture_output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;check&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stdout&lt;/span&gt;
&lt;span class="n"&gt;hits&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splitlines&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startswith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"+++ b/"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startswith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"+"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startswith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"+++"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="no"&gt;SAFE&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;continue&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rx&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;RULES&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;rx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;hits&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
                &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"[{label}] {path}: {mask(text.strip())[:120]}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;break&lt;/span&gt;
&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;hits&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Install it
&lt;/h2&gt;

&lt;p&gt;Save the file as &lt;code&gt;.git/hooks/pre-commit&lt;/code&gt; and run &lt;code&gt;chmod +x .git/hooks/pre-commit&lt;/code&gt;. From now on, a commit with a match stops and prints the file and a masked version of the line.&lt;/p&gt;

&lt;p&gt;The masking matters. A scanner that prints the full secret to your terminal, your CI log or an AI agent's chat history has just leaked it a second time.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it will get wrong
&lt;/h2&gt;

&lt;p&gt;It is a regex scanner, so expect both kinds of error.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;False positives:&lt;/strong&gt; a test fixture with a fake token that looks real. Add a word like &lt;code&gt;example&lt;/code&gt; to that line, or skip the hook once with &lt;code&gt;git commit --no-verify&lt;/code&gt; after you have checked the line yourself.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;False negatives:&lt;/strong&gt; a secret with no known prefix and no &lt;code&gt;key =&lt;/code&gt; style name. Entropy-based tools like gitleaks or trufflehog catch more of these, and they are the better choice for a team. This script is the 35-line version for a solo project.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also remember that the hook lives in &lt;code&gt;.git/hooks&lt;/code&gt;, which is not committed. Teammates do not get it unless you share it through a tool like &lt;code&gt;pre-commit&lt;/code&gt; or a &lt;code&gt;core.hooksPath&lt;/code&gt; setting.&lt;/p&gt;

&lt;h2&gt;
  
  
  If it fires on a real key
&lt;/h2&gt;

&lt;p&gt;Do not just remove the line and recommit. Rotate the key first, at the provider, because anything you pasted into a chat or a screenshot is also exposed. Then remove it from the code and move it to an environment variable.&lt;/p&gt;

&lt;p&gt;Which key format did I miss that you have seen leak?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This post was written with help from an AI assistant. The script was tested on staged files with planted fake keys before posting.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>python</category>
      <category>git</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A 10-minute pre-merge security check you can hand to your AI coding agent</title>
      <dc:creator>rhussa02</dc:creator>
      <pubDate>Wed, 25 Nov 2026 19:09:13 +0000</pubDate>
      <link>https://dev.to/rhussa02/a-10-minute-pre-merge-security-check-you-can-hand-to-your-ai-coding-agent-10ah</link>
      <guid>https://dev.to/rhussa02/a-10-minute-pre-merge-security-check-you-can-hand-to-your-ai-coding-agent-10ah</guid>
      <description>&lt;p&gt;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 &lt;code&gt;.env&lt;/code&gt; value pasted into a config file went out with the rest.&lt;/p&gt;

&lt;p&gt;Here 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Look only at what changed
&lt;/h2&gt;

&lt;p&gt;Reviewing the whole repo is how checks get skipped. Start from the diff:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git diff -U0 origin/main...HEAD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;-U0&lt;/code&gt; drops context lines, so every &lt;code&gt;+&lt;/code&gt; line is new code. That is the code you are responsible for.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Secrets
&lt;/h2&gt;

&lt;p&gt;Search the added lines for anything that looks like a credential:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git diff -U0 origin/main...HEAD &lt;span class="o"&gt;|&lt;/span&gt; grep -E &lt;span class="s1"&gt;'^\+'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; \
  grep -Ei &lt;span class="s2"&gt;"(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"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a real secret shows up, deleting it in the next commit is not enough. It is in the history. Rotate it.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Injection
&lt;/h2&gt;

&lt;p&gt;Three patterns cover most injection bugs in Python web code:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pattern&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Fix&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;SQL built from strings&lt;/td&gt;
&lt;td&gt;&lt;code&gt;f"SELECT * FROM users WHERE id = {uid}"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Parameterized query: &lt;code&gt;cur.execute("... WHERE id = %s", (uid,))&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Shell with user input&lt;/td&gt;
&lt;td&gt;&lt;code&gt;subprocess.run(cmd, shell=True)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Pass a list, drop &lt;code&gt;shell=True&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Unsafe deserialization&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;pickle.loads(body)&lt;/code&gt;, &lt;code&gt;yaml.load(f)&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;json.loads&lt;/code&gt;, &lt;code&gt;yaml.safe_load&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A 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 &lt;code&gt;request.args&lt;/code&gt; is not.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Auth on new routes
&lt;/h2&gt;

&lt;p&gt;Grep cannot do this one. For every new route or handler in the diff, answer two questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Does it check who the caller is?&lt;/li&gt;
&lt;li&gt;Does it check that this caller may touch this record?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The second one is the one that gets missed. &lt;code&gt;GET /invoices/&amp;lt;id&amp;gt;&lt;/code&gt; that checks login but not ownership lets any user read any invoice.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. CI and container changes
&lt;/h2&gt;

&lt;p&gt;If the diff touches a &lt;code&gt;Dockerfile&lt;/code&gt; or &lt;code&gt;.github/workflows/&lt;/code&gt;, check these:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Base images pinned to a version or digest, not &lt;code&gt;:latest&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;A non-root &lt;code&gt;USER&lt;/code&gt; before &lt;code&gt;CMD&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;No &lt;code&gt;curl ... | sh&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Actions pinned to a commit SHA, not a tag&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;permissions:&lt;/code&gt; block that starts at &lt;code&gt;contents: read&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;No &lt;code&gt;${{ github.event.* }}&lt;/code&gt; pasted straight into a &lt;code&gt;run:&lt;/code&gt; step. Pass it through an env var instead:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;echo "$TITLE"&lt;/span&gt;
  &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;TITLE&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ github.event.issue.title }}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Untested changes
&lt;/h2&gt;

&lt;p&gt;List 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make the agent do it
&lt;/h2&gt;

&lt;p&gt;Claude Code, Codex CLI, Cursor and most other coding agents now read &lt;code&gt;SKILL.md&lt;/code&gt; files: a folder with instructions and optional scripts that the agent loads when the task matches. A pre-merge skill looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;---
name: premerge-check
description: Run before merging a branch. Checks the diff for secrets,
  injection, missing auth, CI and Docker misconfig, and untested changes,
  then returns BLOCK, FIX, or SHIP with a ranked fix list.
---

1. Run &lt;span class="sb"&gt;`git diff -U0 origin/main...HEAD`&lt;/span&gt;.
2. Run the secret and injection greps on added lines. Treat hits as leads.
3. Read each flagged file and confirm or discard the lead.
4. For each new route, confirm identity and ownership checks.
5. If Dockerfiles or workflows changed, check the CI list.
6. List changed functions with no test.
7. Verdict: BLOCK on any committed secret or exploitable injection,
   FIX on high findings or untested input handling, otherwise SHIP.
8. Never print a full secret. Do not edit files unless asked.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save it as &lt;code&gt;~/.claude/skills/premerge-check/SKILL.md&lt;/code&gt; (Codex reads &lt;code&gt;.agents/skills/&lt;/code&gt;). Then ask the agent to "check this branch before I merge" and it follows the steps.&lt;/p&gt;

&lt;p&gt;The 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.&lt;/p&gt;

&lt;p&gt;What do you check before merging that is not on this list?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This post was written with help from an AI assistant. The commands were tested on a sample repo before posting.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>ai</category>
      <category>devops</category>
      <category>python</category>
    </item>
  </channel>
</rss>
