The CI rules in my PowerShell standards for AI agents had a line about security scanning. It said “credential scanning” and stopped there. A project that took the standards seriously had to build its own scan, and the hard parts are the same in every project: pinning a scanner that ships as a release archive, reading the history as well as the files, proving the scan can find anything at all, and keeping PowerShell expressions from being reported as passwords.
I’d already done that work once in the OrphanedSid module. Its scan became the betterleaks path of a script that ai-powershell-standards now ships, with the same version and hash, the same two scans and probe, and both PowerShell exceptions. Then I added gitleaks and trufflehog beside it and measured all three on Linux, macOS and Windows.
There was a gap of my own to close, too. The standards asked every project for a credential scan, and the standards repository had none. It does now, and it runs the script it ships.
This post covers what gets installed, how the scan decides it can be trusted, and the bugs that showed up between the first commit and the merge.
Opt-in, by naming a scanner
Nothing about the scan installs by default. You turn it on by naming a scanner:
| |
The reason is CI time. The workflow runs on every pull request and every push to main, and those are your minutes to spend. If you already have a working scan, you keep it.
No scanner is the default either. The powershell-credential-scan skill tells an agent to ask you which one, and gives you this table, measured with betterleaks 1.10.1, gitleaks 8.30.1 and trufflehog 3.100.1:
| betterleaks | gitleaks | trufflehog | |
|---|---|---|---|
A quoted word after such a name, as in $password = 'qwerty' | Reported | Not reported | Not reported |
| A quoted random value after such a name | Reported | Reported for some values and not for others | Not reported |
$password = [System.Security.SecureString]::new() | Reported without the installed configuration | Not reported | Not reported |
| A key in the form of a known service | Reported | Reported | Reported |
| Leaving out one finding | Fingerprint in .betterleaksignore | Fingerprint in .gitleaksignore | Fingerprint in .trufflehogignore, which the scan script reads |
betterleaks is the newest of the three. It’s from Zach Rice, who wrote gitleaks, and it reads gitleaks configurations. In my testing it was the only one that reported a plain quoted password, which is the shape a hard-coded password usually takes in a PowerShell script.
I’m not a dev by trade, so I did about 30 seconds’ worth of research. betterleaks seems to win on the local scanning, with a trufflehog scan recommended on a scheduled cadence. So that’s how I implemented them in OrphanedSid. gitleaks seemed to be more established than betterleaks so I added that option as well.
Three files, two owners
The installer writes a script, a workflow and a configuration file:
| File | Who owns it |
|---|---|
.github/scripts/Invoke-CredentialScan.ps1 | The standards. A later installation or sync replaces it. |
.github/workflows/credential-scan.yml | The project. It is never replaced. |
.betterleaks.toml, .gitleaks.toml, or .trufflehog-exclude.txt | The project. It is never replaced. |
The split is the design. The script holds the hard work, so fixes to it should reach every project on the next sync. The workflow and the configuration are your decisions: which scanner, which version, what to leave out. An update that overwrote them would undo your choices.
The workflow pins the scanner itself, by version and by the SHA-256 of its release archive:
The installer fills those in from the values the script holds for a Linux runner. Because they live in your workflow, you decide when your scanner changes. A new version brings new built-in rules, and new rules can report things the old version didn’t. The workflow’s header says to change the version and the hash together and read the new findings in the same change.
Download, hash, then unpack
The script holds a version and six hashes for each scanner, one for each system and processor:
| |
It downloads the archive and checks the hash before it unpacks anything:
| |
A release tag can be moved to point at other content. A version number alone doesn’t stop that. The hash does.
Unpacking uses .NET directly, ZipFile for the Windows zips and TarFile through a GZipStream for everything else. trufflehog ships a .tar.gz even on Windows, so the script keeps a per-scanner extension for Windows. You can also pass -Version and -Sha256 together for another release, as long as it has the same major version. The options the script passes belong to the major version.
Proving the scan works
A scan that reports nothing proves nothing by itself. betterleaks and trufflehog both end with exit code 0 for a folder that doesn’t exist, and a configuration can leave out more than anyone meant. Before the script reads the repository, it plants values in a folder outside it and requires the scanner to find them:
| |
The values are put together from parts, so no file in the repo holds one, the script included. Each scanner has a list of rules the probe must trigger: generic-password and stripe-access-token for betterleaks, github-pat and stripe-access-token for gitleaks, Github and Stripe for trufflehog. If any is missing, the scan fails before it looks at the repo:
The betterleaks probe includes generic-password because the installed configuration adds its PowerShell exceptions to that rule. The probe shows they didn’t switch it off.
Why four of each
The first probe had one value of each form. trufflehog then failed a clean repository at random, about once in 200 runs, with “The scan of the probe reported Github. It has to report Github, Stripe”.
When it doesn’t verify a key with the service, trufflehog doesn’t report every value. On a hosted Linux runner it left out 6 of 1,500 random values in the Stripe form and 1 of 1,500 in the GitHub form. Every one of them showed up once filtered_unverified was among its results. trufflehog 3.100.1 does the same: in four runs on Linux, macOS and Windows it left out 2 to 7 of 1,500 Stripe-form values and 1 to 4 of 1,500 GitHub-form values, all of them in filtered_unverified. With four values of each form, one hit per rule is enough to show the rule works.
Later, the test fixtures hit the same thing from another side. One Linux job failed because trufflehog left out a planted Stripe-form value in the history. Measured with trufflehog 3.99.9: of 100 values that held a common word like code, user or hash in any letter case, none were reported. Of 3,000 values where every third character was a digit, all were. The fixtures build their values that way now.
It seems counterintuitive to me to skip words when looking for secrets, maybe someone missed a space? I don’t know, I’m sure it’s a rule for a reason.
History and files, both
With the probe passed, the script scans twice. The history scan reads what every commit on every branch and tag added, because a credential stays in a repository after the commit that removes it. All three scanners find it there, on a branch that was never merged and on a commit only a tag holds.
The file scan reads the checkout, because none of the three scanners’ history scans reads what a merge commit itself added.
That seemed odd to me at first, again I’m no dev. I just masquerade in their space.
The history scan needs the whole history, so the script refuses a shallow clone:
actions/checkout fetches one commit by default, so the workflow sets fetch-depth: 0, along with persist-credentials: false.
A finding comes back as its place: scanner, history or files, rule, file, line, commit and fingerprint. betterleaks and gitleaks run with --redact, so no value reaches their reports. trufflehog runs with --no-verification, so nothing it finds is sent to the service it seems to belong to, and its JSON output, which does hold values, is never written anywhere.
Telling a finding from a failure
Exit codes take some care. Both betterleaks and gitleaks end with 1 when they can’t run, so the script passes --exit-code 3 to tell a finding apart. trufflehog gets --fail for exit code 183 on a finding, and --fail-on-scan-errors, because without it a source it can’t read ends with 0.
One case failed open in the first version. A scanner could end with the exit code for a finding and the report could hold none, because it wasn’t written or wasn’t read. The scan passed. It now fails:
And one the other way around. A scan that passes can still end with a scanner that reported something the script then handled: trufflehog exits 183 for a finding the ignore list leaves out. The script acted on it and returned cleanly, but the 183 stayed in $LASTEXITCODE. A pwsh step in GitHub Actions ends with that value, so the step failed with exit code 1 and no message at all. The last line of the script is there for that:
| |
What a configuration leaves out
Any scan in CI has the same weak spot. On a pull request, the job runs the pull request’s own copy of the script, the configuration and the ignore file. You can add a credential and its fingerprint in the same commit, and the scan passes. The workflow header says so: the scan guards against an accident, not against an author who means to get past it.
What the script can do is make it visible to you. Every run that completes writes one warning that says how much is left out, and says nothing when that’s the case:
The nothing came later. The first version only wrote the warning when something was left out. A clean run produced an empty log, and you couldn’t tell a scan that left nothing out from a step that did nothing. A run where a scan fails writes no count at all, because it would miss whatever the failed scan should have reported. The error says why instead.
Counting fingerprints in an ignore file is easy. Counting what a betterleaks or gitleaks configuration leaves out took three tries.
My first version counted [[allowlists]] entries. Then I found the other ways a configuration hides a value: disabledRules switches a built-in rule off, a rule the file defines replaces the built-in rule of the same name, an extended file brings exceptions of its own, and betterleaks drops whatever a filter or prefilter matches. Measured with gitleaks 8.30.1 and betterleaks 1.10.1, each of those let a scan pass over a value it reports without the setting. The probe doesn’t notice unless the setting touches one of its own rules.
Next I counted those settings by name. That broke on TOML, which spells one setting several ways: a quoted key, a dotted key, an inline table, a table header with spaces. gitleaks honored each spelling, switched the rule off, and the scan passed without a warning.
In the end the script stopped reading the configuration. With a betterleaks or gitleaks configuration that does anything beyond the defaults, the script scans the history and the files a second time with the built-in rules alone. A place that only the second scan reports is a place the configuration leaves out:
Places are compared by commit, file and line, whatever rule reported them, because with a specific rule switched off a generic rule can still catch the same line. The warning gives you the count by rule, and -Verbose names every place.
The second scan uses its own configuration file holding only [extend] and useDefault = true. Without --config, gitleaks reads .gitleaks.toml from the folder it scans, and the “plain” scan would have been the first scan again. A configuration with nothing but comments, a title and those two lines leaves nothing out, so if you run gitleaks with its default configuration, your repo is scanned once.
If your repo has more than one maintainer, the skill offers CODEOWNERS entries for the four files that decide what the scan reports, and says they require nothing until the branch rule “Require review from Code Owners” is on. If you’re the only maintainer, it says no such rule binds you as the author, and that the warning is the check to read.
Two exceptions for PowerShell
betterleaks has a generic-password rule that reports a value assigned to a name ending in “password”. For languages it knows, it skips an unquoted value as an expression. PowerShell isn’t one of those languages. Without help, you get a finding for this:
| |
The installed .betterleaks.toml adds two exceptions to that one rule. The first covers PowerShell files:
| |
The second covers a static member of a .NET type in any file, because PowerShell in a Markdown code block has no file extension to go by.
That first regex had a bug when I copied it in from the module’s configuration. One backslash went missing, and the pattern then matched every value. Measured with betterleaks 1.10.1, no password in a .ps1 file was reported with that configuration, quoted or not. The scan was green and blind for PowerShell files, the exact files it exists for. A test that ran the real scanner on the hosted runners caught it. With the backslash back, the empty secure string is left out in a script and in a Markdown code block, and seventeen forms of a quoted password are reported as they are without any configuration. A test that needs no scanner now runs the pattern against the text betterleaks gives as the match of its rule.
gitleaks needs no exceptions. It doesn’t report an expression after $password in a PowerShell file, so its configuration only extends the defaults.
A hash that looked like a key
The comment on the workflow’s env names comes from this. The first template stored the hash under CREDENTIAL_SCANNER_SHA256. betterleaks 1.10.1 reported that line as generic-api-key: a long value beside a name with the word “credential” in it. If you’d installed the scan from that version, your first run would’ve reported your own workflow.
It showed up when this repo ran the scan on itself. The names are now SCANNER, SCANNER_VERSION and SCANNER_SHA256, and a test installs the standards with the scan into a fresh repository for each scanner and scans it with that scanner. The rules, the skills, the script, the workflow with its pin and the configuration must hold nothing it reports.
The tests had their own bug on the way. Each scanner was downloaded into Pester’s $TestDrive by the first test that needed it, and Pester removes what a Context wrote there when the Context ends. Later contexts started a scanner that wasn’t there anymore and found nothing, which looked like a pass. The scanners are downloaded once, before the first test, and a scan that can’t run fails its test with the scan’s own message.
Reading the first findings
The first run in an existing repository nearly always reports something, and you’ll want to read every place. The skill tells an agent to look at each place with git show <commit>:<file> and sort it:
- A real credential: the agent tells you at once, and that it has to be revoked at the service that issued it before anything else. Removing it from the file leaves it in the history.
- A placeholder in a file, like a password in a test: change the value so the scanner doesn’t report it.
- A placeholder in the history: a commit doesn’t change, so its fingerprint goes into the ignore file under a comment that says what it is.
- A form that’s never a credential, reported in many places: an
[[allowlists]]entry for betterleaks or gitleaks, or a path in.trufflehog-exclude.txtonly when nothing in that path can be a credential.
An ignore entry or an exception never gets added to make the scan pass, and you see the list before it’s committed. Rewriting history is your call, and the skill leaves it to you.
This repo’s own first run
When the repo started scanning itself, betterleaks reported eight places and trufflehog one. All nine were in commits from 2025 and August 2026, and none were in the current files. Each got read and listed with a comment. From .betterleaksignore:
| |
The rest were test account passwords in an early security test template, a regular expression that looked for hard-coded passwords in an old quality gate workflow, a compliance test fixture, and a made-up connection string with the server secret.db.com.
I was amused finding the hits on my old commits and remembering the logic/shape of the script at that time.
The repo runs betterleaks on every pull request and push to main, with the same configuration the standards install. trufflehog runs on the first of every month at 04:17 UTC as a second reader, since its detectors aren’t betterleaks’ rules. Nobody watches a scheduled run, so a failed monthly scan opens an issue that links to the run, or comments on the one that’s already open. Only the run log names the places.
The betterleaks job is a required check on main, and its header carries a warning for whoever edits it next. Don’t add a paths or branches filter to the pull_request trigger, or an if: to the job. A pull request that a filter leaves out never gets the check and can’t merge, and a skipped job counts as passed, so the pull request merges without the scan.
Other scanners
I picked these three after that bit of research, so there’s plenty here I haven’t looked at. If you run a credential scan on your own projects, I’d like to hear which scanner you use and how it’s held up. And if there’s a scanner or a CI setup I should be adopting in place of betterleaks, gitleaks and trufflehog, I want to know before more projects install this one. The comments below are open, and so are the repo’s issues if it’s something the skill should offer.
