secrets-scanner
Skill0 starsChanged 48 days agoMITView on GitHub
Add an artisan command that fails when API keys, passwords, private keys or .env files are committed to git, bundled into public JavaScript, or exposed through VITE_ variables. Use when securing a Laravel repo, preventing leaked credentials, setting up secret scanning in CI or pre-push hooks, reviewing .env handling, or after a key was pasted somewhere it shouldn't be.
- Reads credentials
In this repository11 other files it gives its agents.
- bot-proof-formsSkill
- image-uploadsSkill
- inertia-admin-tablesSkill
- json-ld-structured-dataSkill
- mpesa-stk-pushSkill
- paypal-checkoutSkill
- pre-push-checksSkill
- seo-crawlabilitySkill
- shared-network-rate-limitsSkill
- social-share-previewsSkill
- wordpress-migrationSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 4 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 26
When it reports a finding, don't open the file to show the user the value, and don't copy it anywhere.
- Very specific: line 27
Never add a real secret to KNOWN_PUBLIC_VALUES to silence a finding.
- Very specific: line 32
Run php artisan app:scan-secrets and fix anything it reports.
- Very specific: line 33
Run it before every push and in CI.
- Distinctive: line 47
If it was pushed, remove it from history (git filter-repo) only after rotating.
- Distinctive: line 51
Never put realistic secrets in test files: GitHub push protection blocks the push, and your own scanner flags the file.
- Very specific: line 55
Read keys only in config/*.php via env(), and use config() everywhere else.
- Distinctive: line 56
Only public identifiers (a PayPal client ID, a Stripe publishable key) may reach the browser.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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
Secrets scanner
php artisan app:scan-secrets fails the build when a credential is about to be published. It has no dependencies: it's one artisan command.
It checks three places secrets actually leak from:
- Every file git tracks. It matches known key formats: Stripe, OpenAI, Anthropic, AWS, GitHub, Slack, Google, SendGrid, npm, private keys, Laravel
APP_KEY, and passwords inside database URLs. It also catches long values assigned to anything named secret, password, passkey, api_key, token or client_id. - The built JavaScript in
public/build/assets, which is usually git-ignored but downloaded by every visitor. VITE_variables in.env.examplewhose names look secret. Vite compiles everyVITE_value into public JavaScript.
It also fails if any .env file other than .env.example is tracked by git.
Findings show the file, line, kind, and a masked value (sk_l...(40 chars)), so CI logs never repeat the secret.
Agent safety
- The command runs locally and offline. It reads files only to detect secrets, never sends anything over the network, and prints only a masked hint (
sk_l...(40 chars)). - When it reports a finding, don't open the file to show the user the value, and don't copy it anywhere. Tell the user the file, line and kind, and let them rotate the credential.
- Never add a real secret to
KNOWN_PUBLIC_VALUESto silence a finding. That list is only for values the provider itself publishes, such as documented sandbox keys.
Install
- Copy
stubs/app/Console/Commands/ScanSecrets.php.stubtoapp/Console/Commands/ScanSecrets.php, and the test totests/Feature/ScanSecretsTest.php. - Run
php artisan app:scan-secretsand fix anything it reports. - Run it before every push and in CI. The
pre-push-checksskill wires both.
Scan specific files with php artisan app:scan-secrets path/one.php path/two.env.
What it deliberately ignores
- References rather than values:
env('X'),config('x.y'), and placeholders such assk_live_...,your-key-here,${DB_PASSWORD}. vendor/,node_modules/,storage/, lock files, and images, fonts and other binaries.- Values listed in
KNOWN_PUBLIC_VALUES, such as a provider's publicly documented sandbox key. Allow a value there, never with an inline "ignore" comment.
When it finds something
- Rotate the credential first. Anything that reached a remote, CI log, chat or ticket is compromised, and deleting the line doesn't un-publish it: git history and forks keep it.
- Move the value to
.env, read it throughconfig(), and leave an empty key in.env.example. - If it was pushed, remove it from history (
git filter-repo) only after rotating.
Writing tests for scanners
Never put realistic secrets in test files: GitHub push protection blocks the push, and your own scanner flags the file. Generate fake values at runtime (fakeToken() in the stub test) and build tell-tale prefixes from pieces ('sk_'.'live_', '-----BEGIN RSA '.'PRIVATE KEY-----').
Rules for keys in Laravel apps
- Read keys only in
config/*.phpviaenv(), and useconfig()everywhere else.env()returns null once config is cached. - Only public identifiers (a PayPal client ID, a Stripe publishable key) may reach the browser. Secrets stay server-side.
- One key per environment. Never reuse production keys in local or staging.
- Rotate keys shared in chat, screenshots or AI prompts.
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.

