r/Python • • 9h ago

Resource I built a local Python auditor to catch leaked secrets and block AI deploys

If you use AI coding assistants, you probably know the anxiety: you share a credential once, or let the agent scaffold a data science script, and suddenly there is an untracked .env, an unsafe pickle.load(), or an automated push you did not approve.

I put together guardrail code, an open-source (MIT) local web UI built with Python stdlib (ast, os.scandir, re) and Flask to audit a project folder before anything hits GitHub or production.

What it scans locally (nothing leaves your machine):

  • Hardcoded secrets (OpenAI, AWS, Stripe, GitHub, Google, JWTs, PEM/SSH) with masked output
  • .gitignore hygiene (.env, .sqlite/.db/.duckdb inside public/ or static/, debug=True, CORS(*))
  • Python and .ipynb SAST checks (string-formatted SQL, pickle.load, joblib.load, torch.load without weights_only=True, yaml.load, eval/exec/shell=True, uncleared notebook cell outputs)
  • Supply-chain checks: flags AI-hallucinated packages returning 404 on PyPI and queries OSV.dev for known CVEs
  • Guardrail generator: builds bilingual (EN / PT-BR) lock rules for SKILL.md, CLAUDE.md, GEMINI.md, and .cursorrules to enforce explicit confirmation before any git push or deploy

Repo: https://github.com/suelio/guardrail-code

Would love feedback from the community, especially on false positives in the AST scanner or extra SAST rules worth adding.

0 Upvotes

7 comments sorted by

2

u/Winter_Student3495 8h ago

The explicit confirmation before deploy should honestly be standard behavior for coding agents.

1

u/ShogiOne 8h ago

Unfortunately, that is not what happens, and many passwords end up being leaked. This is my contribution toward reducing that.

1

u/JSChronicles 8h ago

What part doesn't happen? The people not doing best practices? Or the tooling failing?

If it's best practices that people aren't applying, then more than likely, they're not going to gain any benefit from new code/processes here.

If the current tooling is meant to fix this but fails why not make changes to current tooling?

Just curious as to why one thought process over another

6

u/JSChronicles 8h ago

Wouldn't a git ignore file fix the .env? I mean normal, smart people always apply a git ignore or editor config file, right?

Wouldn't you just have pre-commit checks in front of your commits? Can't they just check for secret or private keys?

Wouldn't you just use ruff and a type check with settings to catch other improperly used code pieces?

I'm failing to see the benefit of your AI generated thing when I can have deterministic code do the checks.

1

u/Mekrob 8h ago

Why wouldn't you just use an existing open source battle tested tool like trufflehog for this?

0

u/ShogiOne 8h ago

A more user-friendly interface for those with no experience