This week on X, a post about leaked GitHub secrets was going around: 28.6 million API keys and passwords showed up in public repositories last year, and code written with AI leaks them about twice as often. The source is GitGuardian's State of Secrets Sprawl 2026: 28.65 million new hardcoded secrets in public GitHub commits in 2025, a 34% jump from 2024. Commits co-authored by Claude Code leaked a secret 3.2% of the time, against a 1.5% baseline for all public commits they scanned.
That is not only an app-backend problem. It shows up on marketing sites too.
The coding agent needs a contact form to email the owner, so it pastes a Resend key into src/contact.js. It adds an "AI gift ideas" box, so an OpenAI key goes in a browser script. It wires a "buy a print" button and uses the Stripe secret key because that is the snippet in the docs sidebar. Then it writes a .env for "best practice," runs git init && git add ., and pushes the tree to a public repo because that is how the preview deploy works. The homepage looks finished. The keys are in the zip.
It does not matter whether the site came from Cursor, Claude Code, Lovable, or an AI website builder. If a secret that can send mail, charge a card, or call a model is in the files you are about to deploy or push, this applies.
So I wrote the kind of site a coding agent produces for "a screen-print shop in Providence with hours, a contact form that emails the owner, a map, and an AI gift-idea helper." The HTML is prerendered on purpose. There is a real title, a real H1, hours, and an address — this is not an empty #root. Then I wrote a short scanner, secret_scan.py, that reads the local tree and reports leftover secrets. I ran it on the finished-looking repo, on the same repo after I only deleted .env, and on a version where the keys stay off the client and .gitignore actually excludes .env. All the numbers below come from those three runs.
The fixture
The business is fictional. It is called Harbor Line Prints, and it sells screen prints and short-run posters on Ballast Street in Providence. The "before" tree is a finished-looking marketing site: a title, an H1, hours, a contact form, and JSON-LD. The leftovers are a committed .env and three browser scripts.
Here is the contact form that actually got deployed, trimmed to the part that matters. The values are fake, labeled as a fixture, and will not authenticate anywhere.
// Contact form: emails the shop from the browser.
// Fixture only — this value is fake and will not authenticate anywhere.
const RESEND_API_KEY = "re_harborLinePrintsFixtureAAA111";
const TO = "owner@harborline.example";
export async function sendContact(form) {
return fetch("https://api.resend.com/emails", {
method: "POST",
headers: {
Authorization: "Bearer " + RESEND_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify(/* ... */),
});
}
If you open the site, the form looks ordinary. If you open src/contact.js, src/gift.js, or src/checkout.js, the mail key, the model key, and the Stripe secret key are in the files the browser will download. .env has the same three values, and .gitignore only lists node_modules, dist, and .DS_Store.
The scanner
secret_scan.py reads a local directory: env files, HTML, and JS/TS/Vue/Svelte sources. It does not call Resend, Stripe, OpenAI, or GitHub. It does not validate a key, and it does not try to use one. Values in the output are redacted.
It reports:
- a
.env(or.env.local,.env.production, and similar) that assigns a secret-looking name or value, and is not ignored - a hardcoded assignment such as
RESEND_API_KEY,OPENAI_API_KEY,STRIPE_SECRET_KEY, or a service-role key in a client source file - known key prefixes in those files:
re_,sk-proj-,sk_live_,sk_test_,SG.,ghp_,AKIA, Slackxox* - a PEM private key block
- a
VITE_orNEXT_PUBLIC_prefix on a secret-named variable (that prefix puts the value in the browser bundle) - a missing
.gitignorerule for.env(warning if the file is not present; a fail if it is)
It does not flag a Stripe publishable key, and it does not treat re_your_api_key_here or an empty value in .env.example as a secret. It also does not scan node_modules, dist, or .git. A clean run is not a promise that git history is clean, or that a host-level scan would be. It is a check of the files you are about to ship.
secret_scan.py (about 640 lines, 13 tests)
#!/usr/bin/env python3
"""secret_scan.py — local leftover-secret scanner for a marketing-site repo.
Reads files already on disk. It does not call any vendor API, does not
validate keys, does not fetch URLs, and does not try to use a value it
finds. Printouts redact secret-looking values. Run it on a tree you own.
"""
from __future__ import annotations
import argparse
import os
import re
import sys
import unittest
from dataclasses import dataclass, field
from pathlib import Path
SKIP_DIRS = {
".git",
"node_modules",
"dist",
"build",
"out",
"coverage",
"target",
".next",
".cache",
".venv",
"venv",
"__pycache__",
"vendor",
}
ENV_NAMES = {
".env",
".env.local",
".env.development",
".env.production",
".env.development.local",
".env.production.local",
".env.test",
".env.test.local",
}
ENV_EXAMPLE_NAMES = {
".env.example",
".env.sample",
".env.template",
".env.placeholder",
}
CLIENT_SUFFIXES = {
".js",
".jsx",
".ts",
".tsx",
".mjs",
".cjs",
".html",
".htm",
".vue",
".svelte",
}
# Names that should never appear as assigned values in a client bundle
# or in a committed env file, unless the value is an obvious placeholder.
SECRET_NAMES = {
"RESEND_API_KEY",
"SENDGRID_API_KEY",
"MAILGUN_API_KEY",
"POSTMARK_API_TOKEN",
"POSTMARK_SERVER_TOKEN",
"OPENAI_API_KEY",
"ANTHROPIC_API_KEY",
"STRIPE_SECRET_KEY",
"STRIPE_SECRET",
"AWS_SECRET_ACCESS_KEY",
"AWS_SECRET_KEY",
"GITHUB_TOKEN",
"GH_TOKEN",
"GH_PAT",
"NPM_TOKEN",
"DATABASE_URL",
"POSTGRES_PASSWORD",
"SUPABASE_SERVICE_ROLE_KEY",
"SERVICE_ROLE_KEY",
}
PUBLIC_OK_NAMES = {
"STRIPE_PUBLISHABLE_KEY",
"NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY",
"VITE_STRIPE_PUBLISHABLE_KEY",
}
# Prefixes that usually mean a live credential, not a documentation stub.
PREFIX_RULES = (
("openai-key", re.compile(r"\bsk-proj-[A-Za-z0-9_-]{12,}\b")),
("openai-key", re.compile(r"\bsk-svcacct-[A-Za-z0-9_-]{12,}\b")),
("openai-key", re.compile(r"\bsk-(?!test_|live_|proj-|svcacct-)[A-Za-z0-9_-]{20,}\b")),
("stripe-secret", re.compile(r"\bsk_live_[A-Za-z0-9]{8,}\b")),
("stripe-secret", re.compile(r"\bsk_test_[A-Za-z0-9]{8,}\b")),
("resend-key", re.compile(r"\bre_[A-Za-z0-9]{8,}\b")),
("sendgrid-key", re.compile(r"\bSG\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b")),
("github-pat", re.compile(r"\bghp_[A-Za-z0-9]{20,}\b")),
("github-pat", re.compile(r"\bgithub_pat_[A-Za-z0-9_]{20,}\b")),
("aws-access-key-id", re.compile(r"\bAKIA[0-9A-Z]{16}\b")),
("slack-token", re.compile(r"\bxox[baprs]-[A-Za-z0-9-]{10,}\b")),
)
PEM_RE = re.compile(
r"-----BEGIN (?:RSA |OPENSSH |EC |DSA |ENCRYPTED )?PRIVATE KEY-----"
)
ASSIGN_RE = re.compile(
r"(?:(?:const|let|var|export\s+const)\s+)?(?P<name>[A-Z][A-Z0-9_]{2,})"
r"\s*(?:=|:)\s*(?P<quote>['\"])(?P<value>[^'\"]{4,})(?P=quote)",
re.MULTILINE,
)
ENV_ASSIGN_RE = re.compile(
r"^(?:export\s+)?(?P<name>[A-Z][A-Z0-9_]{2,})[ \t]*=[ \t]*(?P<value>[^\n]*)$",
re.MULTILINE,
)
PLACEHOLDER_RE = re.compile(
r"(?i)^(your[_-]?|changeme|change_me|placeholder|example|xxx+|\*+|<.*>|"
r"re_your|sk_test_your|pk_test_your|pk_live_your|insert[_-]?|todo|"
r"replace[_-]?me|dummy|not_a_real|n/a)?$",
)
PLACEHOLDER_SUB = re.compile(
r"(?i)(your[_-]?api[_-]?key|your[_-]?key(?:[_-]?here)?|replace[_-]?me|"
r"changeme|placeholder|example[_-]?key|xxx{3,}|<.*>|not_a_real_key_here|"
r"sk_test_your|sk_live_your|re_your_|sk-proj-your|pk_test_your|pk_live_your)"
)
def is_placeholder(value: str) -> bool:
v = value.strip().strip("'\"").strip()
if not v:
return True
if PLACEHOLDER_RE.match(v):
return True
if PLACEHOLDER_SUB.search(v) and len(v) < 80:
return True
# Common env-example shapes: re_xxxxxxxxxxxx, sk_test_xxxx
if re.fullmatch(r"(re_|sk_test_|sk_live_|sk-proj-|pk_test_|pk_live_|ghp_)x{6,}", v):
return True
return False
def redact(value: str) -> str:
v = value.strip().strip("'\"")
if len(v) <= 6:
return "…"
return v[:4] + "…" + v[-2:]
def iter_files(root: Path):
for dirpath, dirnames, filenames in os.walk(root):
dirnames[:] = [d for d in dirnames if d not in SKIP_DIRS and not d.startswith(".git")]
for name in filenames:
yield Path(dirpath) / name
def rel(root: Path, path: Path) -> str:
try:
return path.relative_to(root).as_posix()
except ValueError:
return str(path)
def gitignore_excludes_env(root: Path) -> bool | None:
gi = root / ".gitignore"
if not gi.is_file():
return False
text = gi.read_text(errors="replace")
for raw in text.splitlines():
line = raw.strip()
if not line or line.startswith("#"):
continue
if line in {".env", ".env.*", "*.env", "**/.env", "/.env"}:
return True
if line.startswith("!.env"):
continue
if line in {".env.local", ".env*.local"}:
# partial; still look for a general .env rule
continue
# ".env*" covers .env and .env.local, but also .env.example — still a yes
for raw in text.splitlines():
line = raw.strip()
if line in {".env*", ".env.local", ".env*.local"}:
return True
return False
@dataclass
class Finding:
code: str
severity: str # "fail" or "warn"
path: str
detail: str
@dataclass
class Report:
root: Path
title: str = ""
files: list[str] = field(default_factory=list)
findings: list[Finding] = field(default_factory=list)
env_files: list[str] = field(default_factory=list)
gitignore_has_env: bool | None = None
def add(self, code: str, severity: str, path: str, detail: str) -> None:
self.findings.append(Finding(code, severity, path, detail))
@property
def fails(self) -> list[Finding]:
return [f for f in self.findings if f.severity == "fail"]
@property
def warns(self) -> list[Finding]:
return [f for f in self.findings if f.severity == "warn"]
def looks_like_secret_name(name: str) -> bool:
n = name.upper()
if n in PUBLIC_OK_NAMES:
return False
if n in SECRET_NAMES:
return True
if n.startswith("VITE_") or n.startswith("NEXT_PUBLIC_"):
bare = n.split("_", 1)[1] if n.startswith("VITE_") else n[len("NEXT_PUBLIC_"):]
if bare in SECRET_NAMES or bare.endswith("SECRET_KEY") or bare.endswith("API_KEY") and "PUBLISHABLE" not in bare:
# public prefix on a secret-named variable is itself a finding
return True
return bare in SECRET_NAMES
if n.endswith("SECRET_KEY") or n.endswith("_SECRET") or n.endswith("SERVICE_ROLE_KEY"):
return True
if n.endswith("API_KEY") and "PUBLISHABLE" not in n and "PUBLIC" not in n:
return True
return False
def public_prefix_on_secret(name: str) -> bool:
n = name.upper()
if n.startswith("VITE_") or n.startswith("NEXT_PUBLIC_"):
return looks_like_secret_name(n)
return False
def scan_text(report: Report, path: Path, text: str, *, in_env: bool, in_client: bool, example: bool) -> None:
relpath = rel(report.root, path)
if PEM_RE.search(text):
report.add("private-key", "fail", relpath, "PEM private key block in " + relpath)
assigns = []
if in_env or path.suffix in {".env"} or path.name in ENV_NAMES | ENV_EXAMPLE_NAMES:
for m in ENV_ASSIGN_RE.finditer(text):
assigns.append((m.group("name"), m.group("value").strip().strip("'\"")))
for m in ASSIGN_RE.finditer(text):
assigns.append((m.group("name"), m.group("value")))
seen = set()
for name, value in assigns:
key = (name, value, relpath)
if key in seen:
continue
seen.add(key)
if is_placeholder(value):
continue
if looks_like_secret_name(name):
sev = "warn" if example else "fail"
if public_prefix_on_secret(name):
report.add(
"public-prefix-secret",
sev,
relpath,
f"{name} is a public-bundle prefix on a secret-looking name, value {redact(value)} in {relpath}",
)
else:
kind = "env-secret" if in_env else "hardcoded-secret"
report.add(
kind,
sev,
relpath,
f"{name}={redact(value)} in {relpath}",
)
# Prefix scan for values that were not caught by name (inline strings).
# Skip obvious placeholders.
for code, rx in PREFIX_RULES:
for m in rx.finditer(text):
val = m.group(0)
if is_placeholder(val):
continue
# Avoid double-counting the same value already reported by name.
if any(val in f.detail or redact(val) in f.detail for f in report.findings if f.path == relpath):
continue
# If this exact raw value was already an assign we reported, skip
already = False
for n, v in assigns:
if v == val and looks_like_secret_name(n):
already = True
break
if already:
continue
sev = "warn" if example else "fail"
where = "client bundle" if in_client else ("env file" if in_env else "file")
report.add(
code,
sev,
relpath,
f"{code} {redact(val)} in {where} {relpath}",
)
def scan(root: Path) -> Report:
root = root.resolve()
report = Report(root=root)
report.gitignore_has_env = gitignore_excludes_env(root)
# title from first HTML if present
for path in iter_files(root):
report.files.append(rel(root, path))
if path.name in ENV_NAMES:
report.env_files.append(rel(root, path))
if path.suffix in {".html", ".htm"} and not report.title:
text = path.read_text(errors="replace")
m = re.search(r"<title[^>]*>(.*?)</title>", text, re.I | re.S)
if m:
report.title = re.sub(r"\s+", " ", m.group(1)).strip()
for path in iter_files(root):
name = path.name
try:
text = path.read_text(errors="replace")
except OSError:
continue
in_env = name in ENV_NAMES
example = name in ENV_EXAMPLE_NAMES
in_client = path.suffix.lower() in CLIENT_SUFFIXES
if in_env or example or in_client or PEM_RE.search(text) or path.suffix in {".pem", ".key"}:
scan_text(report, path, text, in_env=in_env, in_client=in_client, example=example)
if report.env_files and report.gitignore_has_env is False:
for envp in report.env_files:
report.add(
"env-not-ignored",
"fail",
envp,
f"{envp} is in the tree and .gitignore does not exclude .env",
)
elif report.env_files is not None and not report.gitignore_has_env and not report.env_files:
report.add(
"gitignore-missing-env",
"warn",
".gitignore",
".gitignore does not exclude .env (no .env present in the tree)",
)
elif not (root / ".gitignore").is_file():
report.add(
"gitignore-missing-env",
"warn",
".gitignore",
"no .gitignore; a later git add . will stage .env if one is created",
)
# de-dup identical codes+paths+details
uniq = []
seen = set()
for f in report.findings:
k = (f.code, f.path, f.detail)
if k in seen:
continue
seen.add(k)
uniq.append(f)
report.findings = uniq
return report
def verdict_lines(report: Report) -> list[str]:
if report.fails:
return [
"Secrets are present in the tree or the client bundle.",
"Treat every value you found as burned if this tree was ever",
"pushed or deployed. Rotate first, then remove the leftovers.",
]
if report.warns:
return [
"No high-severity leftovers, but there are warnings to clear",
"before you push or deploy.",
]
return [
"No leftover secrets found in local env files or client sources.",
"This is not a substitute for git history or host-level scans.",
]
def format_report(report: Report) -> str:
lines = [
"secret_scan.py (local files only; values redacted)",
f"root: {report.root}",
"",
"TREE",
f" title {report.title or '—'}",
f" files {len(report.files)}",
f" env files {', '.join(report.env_files) if report.env_files else 'none'}",
f" gitignore has .env {'yes' if report.gitignore_has_env else 'no'}",
"",
"FINDINGS",
]
if not report.findings:
lines.append(" (none)")
else:
for f in report.findings:
lines.append(f" - {f.code:<24} {f.detail}")
lines.append("")
lines.append("VERDICT")
for v in verdict_lines(report):
lines.append(f" {v}")
fails = len(report.fails)
warns = len(report.warns)
lines.append("")
lines.append(f" {fails} fail, {warns} warning")
return "\n".join(lines) + "\n"
# ------------------------- tests -------------------------
class SecretScanTests(unittest.TestCase):
def _write(self, root: Path, relpath: str, content: str) -> None:
p = root / relpath
p.parent.mkdir(parents=True, exist_ok=True)
p.write_text(content)
def test_flags_env_and_missing_gitignore(self):
import tempfile
with tempfile.TemporaryDirectory() as td:
root = Path(td)
self._write(root, "index.html", "<title>Harbor Line Prints</title>")
self._write(root, ".env", "RESEND_API_KEY=re_abcDEF1234567890\n")
r = scan(root)
codes = {f.code for f in r.fails}
self.assertIn("env-secret", codes)
self.assertIn("env-not-ignored", codes)
self.assertIn("Harbor Line Prints", r.title)
def test_flags_hardcoded_resend_in_js(self):
import tempfile
with tempfile.TemporaryDirectory() as td:
root = Path(td)
self._write(root, ".gitignore", "node_modules\n")
self._write(
root,
"src/contact.js",
"const RESEND_API_KEY = 're_abcDEF1234567890';\n",
)
r = scan(root)
codes = {f.code for f in r.fails}
self.assertIn("hardcoded-secret", codes)
def test_flags_stripe_secret_and_openai_prefixes(self):
import tempfile
with tempfile.TemporaryDirectory() as td:
root = Path(td)
self._write(root, ".gitignore", ".env\n")
self._write(
root,
"src/checkout.js",
"const key = 'sk_test_51HarborLineFixtureAAA111';\n",
)
self._write(
root,
"src/gift.js",
"fetch('https://api.openai.com/v1/chat/completions', {headers: {Authorization: 'Bearer sk-proj-HarborLineFixtureKey1234'}})\n",
)
r = scan(root)
codes = {f.code for f in r.fails}
self.assertIn("stripe-secret", codes)
self.assertIn("openai-key", codes)
def test_flags_private_key_block(self):
import tempfile
with tempfile.TemporaryDirectory() as td:
root = Path(td)
self._write(root, ".gitignore", ".env\n")
self._write(
root,
"deploy.pem",
"-----BEGIN RSA PRIVATE KEY-----\nMIIFAKE\n-----END RSA PRIVATE KEY-----\n",
)
r = scan(root)
self.assertTrue(any(f.code == "private-key" for f in r.fails))
def test_flags_vite_prefix_on_secret(self):
import tempfile
with tempfile.TemporaryDirectory() as td:
root = Path(td)
self._write(root, ".gitignore", ".env\n")
self._write(root, ".env.example", "VITE_RESEND_API_KEY=re_abcdefghijklmnop\n")
r = scan(root)
# example file: warning, not fail
self.assertFalse(r.fails)
self.assertTrue(any(f.code == "public-prefix-secret" for f in r.warns))
def test_placeholder_env_example_is_clean(self):
import tempfile
with tempfile.TemporaryDirectory() as td:
root = Path(td)
self._write(root, ".gitignore", "node_modules\n.env\n")
self._write(
root,
".env.example",
"RESEND_API_KEY=re_your_api_key_here\n"
"OPENAI_API_KEY=sk-proj-your_api_key_here\n"
"STRIPE_SECRET_KEY=sk_test_your_key_here\n",
)
self._write(
root,
"src/contact.js",
"export async function send(body) { return fetch('/api/contact', {method:'POST', body}); }\n",
)
r = scan(root)
self.assertEqual(r.fails, [])
self.assertEqual(r.warns, [])
def test_empty_env_example_is_clean(self):
import tempfile
with tempfile.TemporaryDirectory() as td:
root = Path(td)
self._write(root, ".gitignore", ".env\n")
self._write(root, ".env.example", "RESEND_API_KEY=\nOPENAI_API_KEY=\n")
r = scan(root)
self.assertEqual(r.findings, [])
def test_publishable_stripe_key_is_not_a_fail(self):
import tempfile
with tempfile.TemporaryDirectory() as td:
root = Path(td)
self._write(root, ".gitignore", ".env\n")
self._write(
root,
"src/checkout.js",
"const STRIPE_PUBLISHABLE_KEY = 'pk_test_51HarborLinePublicOnly';\n",
)
r = scan(root)
self.assertEqual(r.fails, [])
def test_redacts_values_in_output(self):
import tempfile
with tempfile.TemporaryDirectory() as td:
root = Path(td)
secret = "re_abcDEF1234567890ZZ"
self._write(root, ".gitignore", "node_modules\n")
self._write(root, "src/contact.js", f"const RESEND_API_KEY = '{secret}';\n")
text = format_report(scan(root))
self.assertNotIn(secret, text)
self.assertIn("re_a…ZZ", text)
def test_skips_node_modules(self):
import tempfile
with tempfile.TemporaryDirectory() as td:
root = Path(td)
self._write(root, ".gitignore", ".env\n")
self._write(
root,
"node_modules/pkg/index.js",
"const OPENAI_API_KEY = 'sk-proj-ShouldBeIgnored1234';\n",
)
r = scan(root)
self.assertEqual(r.fails, [])
def test_gitignore_env_star(self):
import tempfile
with tempfile.TemporaryDirectory() as td:
root = Path(td)
self._write(root, ".gitignore", ".env*\n")
self.assertTrue(gitignore_excludes_env(root))
def test_no_false_positive_on_marketing_copy(self):
import tempfile
with tempfile.TemporaryDirectory() as td:
root = Path(td)
self._write(root, ".gitignore", ".env\n")
self._write(
root,
"index.html",
"<title>Harbor Line Prints</title><p>Ask us about API print runs.</p>\n",
)
r = scan(root)
self.assertEqual(r.findings, [])
def test_format_contains_counts(self):
import tempfile
with tempfile.TemporaryDirectory() as td:
root = Path(td)
self._write(root, "src/a.js", "const RESEND_API_KEY = 're_abcDEF12345678';\n")
text = format_report(scan(root))
self.assertIn("fail", text)
self.assertIn("VERDICT", text)
def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description="Scan a local marketing-site tree for leftover secrets.")
parser.add_argument("root", nargs="?", default=".", help="directory to scan")
parser.add_argument("--self-test", action="store_true", help="run unit tests and exit")
args = parser.parse_args(argv)
if args.self_test:
suite = unittest.defaultTestLoader.loadTestsFromTestCase(SecretScanTests)
result = unittest.TextTestRunner(verbosity=2).run(suite)
return 0 if result.wasSuccessful() else 1
root = Path(args.root)
if not root.exists():
print(f"secret_scan.py: no such path: {root}", file=sys.stderr)
return 2
report = scan(root)
sys.stdout.write(format_report(report))
return 1 if report.fails else 0
if __name__ == "__main__":
sys.exit(main())
Run 1: the committed .env and the frontend keys
$ python3 secret_scan.py fixtures/before
secret_scan.py (local files only; values redacted)
root: fixtures/before
TREE
title Harbor Line Prints | Screen prints in Providence
files 6
env files .env
gitignore has .env no
FINDINGS
- env-secret RESEND_API_KEY=re_h…11 in .env
- env-secret OPENAI_API_KEY=sk-p…56 in .env
- env-secret STRIPE_SECRET_KEY=sk_t…22 in .env
- hardcoded-secret STRIPE_SECRET_KEY=sk_t…22 in src/checkout.js
- openai-key openai-key sk-p…56 in client bundle src/gift.js
- hardcoded-secret RESEND_API_KEY=re_h…11 in src/contact.js
- env-not-ignored .env is in the tree and .gitignore does not exclude .env
VERDICT
Secrets are present in the tree or the client bundle.
Treat every value you found as burned if this tree was ever
pushed or deployed. Rotate first, then remove the leftovers.
7 fail, 0 warning
Seven findings, all fails. Three of them are the same keys sitting in .env with no ignore rule. The other three are those keys, or a prefix that matches them, in JavaScript the browser can download. The last one is the ignore rule itself. The shop pages still look finished.
Run 2: deleting .env is not enough
The first follow-up prompt I usually see is "remove the .env from the repo." I did only that. I left the three scripts and the .gitignore alone.
$ python3 secret_scan.py fixtures/mid
secret_scan.py (local files only; values redacted)
root: fixtures/mid
TREE
title Harbor Line Prints | Screen prints in Providence
files 5
env files none
gitignore has .env no
FINDINGS
- hardcoded-secret STRIPE_SECRET_KEY=sk_t…22 in src/checkout.js
- openai-key openai-key sk-p…56 in client bundle src/gift.js
- hardcoded-secret RESEND_API_KEY=re_h…11 in src/contact.js
- gitignore-missing-env .gitignore does not exclude .env (no .env present in the tree)
VERDICT
Secrets are present in the tree or the client bundle.
Treat every value you found as burned if this tree was ever
pushed or deployed. Rotate first, then remove the leftovers.
3 fail, 1 warning
Three fails remain, all in the client sources, plus a warning that the next git add . will stage a new .env if someone creates one. Deleting the env file hides the problem from a casual directory listing. It does not take the keys out of the bundle.
Run 3: keys off the client, .env ignored
For the third tree I changed the code, not just the files on disk. The contact form posts to a same-origin /api/contact endpoint. There is no gift-idea script with a model key in the browser. The checkout file, if you keep one, may hold a Stripe publishable key, not the secret. .gitignore excludes .env, and .env.example has placeholders only.
export async function sendContact(form) {
return fetch("/api/contact", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(form),
});
}
$ python3 secret_scan.py fixtures/after
secret_scan.py (local files only; values redacted)
root: fixtures/after
TREE
title Harbor Line Prints | Screen prints in Providence
files 5
env files none
gitignore has .env yes
FINDINGS
(none)
VERDICT
No leftover secrets found in local env files or client sources.
This is not a substitute for git history or host-level scans.
0 fail, 0 warning
Zero findings. The publishable key in src/checkout.js is left alone, which is the right call: that key is designed for the browser, and it is not a secret. The scanner still would have failed a VITE_RESEND_API_KEY or a STRIPE_SECRET_KEY in the same file.
What the findings actually mean
A committed .env is the obvious one, and it is not the sharpest. If the repo was ever public, or if a preview deploy packed the tree, treat those values as burned even after you delete the file. Rotate them at the vendor first. Then remove the leftovers from the tree. Rewriting git history is optional cleanup, not a substitute for rotation, and it does nothing if a crawl or a teammate already copied the commit.
A secret in a client script is sharper. src/contact.js is not a server. Anyone who loads the page can read the Resend key and send mail as the shop. The OpenAI key in src/gift.js is the same shape: it is a billed credential in a file the browser downloads. The Stripe secret key in src/checkout.js is worse. The publishable key is the one that belongs in the browser; the secret key is not.
A missing ignore rule is the slow leak. The mid run had no .env, and still warned. The next prompt that "adds production env" will write a new file, and git add . will stage it again.
This is also why "just export the code" is not a complete answer when you pick a builder, which is one of the questions in how to evaluate an AI website builder. An export is useful. It is also a zip of whatever the agent committed. If that zip includes .env or a secret in src/, you now have a portable copy of the leak. The same caution applies when you move a prototype between tools — the Lovable vs Claude Code comparison is mostly about price, hosting, and GitHub sync, but the repo you sync is only safe if the secrets never went into it.
What I would do with a real repo
If I were handed a vibe-coded marketing site tomorrow, I would check this before I pointed a domain at it, or pushed the repo:
- Search the tree you are about to deploy for
.env,RESEND_API_KEY,OPENAI_API_KEY,STRIPE_SECRET_KEY,sk-proj-,sk_live_,re_, andBEGINprivate key headers. Look in client source, not only at the repo root. - Confirm
.gitignoreexcludes.env, and that.env.examplehas placeholders, not real values. - Run
python3 secret_scan.py .against the files you are shipping. It redacts values; read the paths, not the suffixes. - If anything was ever pushed to a public remote, or bundled into a preview, rotate those keys at the vendor before you do anything else. Then remove them from the tree and run the scanner again. A scan you run once is a scan that is out of date after the next prompt "adds a contact form."
A site built with an AI website builder still has to pass this test. The builder is doing the right kind of work if the published document does not contain a mail key, a model key, or a Stripe secret, and if the project ignores .env by default. Generating the first version of the site is the cheap part. Knowing whether the keys left the building is the part that decides whether the contact form is a form or an open relay with a billed credential attached.
What we do in PolyDraft, and what we do not claim
PolyDraft is the AI website builder we work on. It publishes server-rendered HTML to your own Cloudflare account, so the document a visitor fetches is the document you can view-source. That makes a check like this easy to run. It does not make it unnecessary. An agent can still paste a key into a client script, or start a repo with .env already in the first commit. We still run checks like these on what we ship, and you should run them on anything with your name on the domain, whoever or whatever built it.
Before you push the repo
- Read the client sources, not just the homepage. If you see a mail key, a model key, a Stripe secret, or a PEM block, stop there.
- If the tree was ever public, rotate every value you found. Deleting the file is not enough.
- Move remaining secrets to a server-side env, ignore
.env, and leave only placeholders in.env.example. - Save the files and run
python3 secret_scan.py .again after the next change.
Ten minutes, most of it against files you already have, all of it on a tree you own. Cheaper than finding out a preview URL was also a key dump.



Top comments (0)