Inspiration

Accidental secret exposure—such as committing API keys, access tokens, or passwords to shared or public codebases—is one of the most common security mistakes in software development. Even hackathon submission guidelines explicitly warn participants not to upload private credentials or API keys. We built Secret Leak Guard to help developers and students detect hardcoded secrets early and remediate them automatically before they leak.

What it does

Secret Leak Guard analyzes code or configuration snippets line by line to identify exposed credentials and high-risk tokens, then offers one-click auto-remediation:

  • Pattern Matching (Regex): Detects recognizable credential formats (such as AWS access keys, GitHub tokens, and OpenAI API keys) as well as hardcoded password or secret assignments.
  • Shannon Entropy Analysis: Flags long, high-randomness strings that may represent secrets or tokens even when they do not match a known prefix.
  • Line-by-Line Findings: Displays exact line numbers, leak categories, and detection reasons.
  • One-Click Auto-Fix & Download: Replaces exposed values with os.getenv(...) in the cleaned code, generates a .env file with the extracted entries, and lets users download both cleaned_code.py and .env.

How we built it

We built the prototype using Python and Flask with a clean side-by-side web interface:

  • Detection Engine: Combines regular expressions for known credential patterns with a Shannon entropy calculation to measure character randomness.
  • Auto-Fix Engine: Maps detected secrets to normalized environment variable names, rewrites assignments to use os.getenv(...), and builds the corresponding .env output.
  • Web UI & Export Routes: Provides an interactive form to scan snippets, inspect results, and download cleaned_code.py and .env directly.

Challenges we ran into

  • Tuning the Shannon entropy threshold so high-randomness tokens are caught reliably without unnecessarily flagging normal strings or identifiers.
  • Handling both explicit secret assignments and standalone random tokens cleanly while keeping the rewritten code and .env output clear and accurate.

Accomplishments that we're proud of

  • Building a working end-to-end tool that goes beyond alerting on leaks by automatically refactoring the code into os.getenv(...) and generating a ready-to-use .env file.
  • Making secret detection visual, fast, and practical with direct file downloads.

What we learned

  • How combining deterministic pattern matching (Regex) with statistical randomness (Shannon entropy) improves secret detection coverage.
  • Practical ways to structure automated remediation so developers adopt safer secret-management habits with minimal friction.

What's next for Secret Leak Guard

  • Add Git pre-commit hooks and CI/CD (GitHub Actions) integration to block leaks automatically before code is committed or pushed.
  • Expand support for additional languages and environment patterns (such as JavaScript/TypeScript process.env) along with .gitignore verification so .env files are never exposed by mistake.

Built With

Share this project:

Updates

Submission history