-
-
-
-
Secret Leak Guard web interface showing a sample code snippet ready to be scanned for hardcoded secrets and high-entropy tokens..
-
Secret Leak Guard scan results showing 4 detected and replaced secrets with line-by-line alerts for exposed keys and credentials.
-
Side-by-side auto-fix result showing os.getenv() code replacement, generated .env variables, and one-click download buttons.
-
Browser download history confirming one-click export of the generated .env file and cleaned_code.py after auto-fix.
-
Contents of the generated .env file containing extracted demo variables for the OpenAI key, database password, and service token.
-
Refactored cleaned_code.py showing import os and secrets replaced with os.getenv() calls while keeping safe config untouched.
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.envfile with the extracted entries, and lets users download bothcleaned_code.pyand.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.envoutput. - Web UI & Export Routes: Provides an interactive form to scan snippets, inspect results, and download
cleaned_code.pyand.envdirectly.
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
.envoutput 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.envfile. - 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.gitignoreverification so.envfiles are never exposed by mistake.