What if your Python app accidentally prints an API key? #1
Sam3360
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
While debugging, it's surprisingly easy to do something like:
The problem isn't necessarily that the secret was stored insecurely. The problem is that it just ended up in terminal output or logs.
That's the problem I built SecretShield to solve.
What is SecretShield?
SecretShield is a local Python security utility with both a Python library and CLI.
It detects likely secrets such as:
Then it can redact them before they appear in Python's terminal output or logging.
For example:
Instead of exposing the value:
It works with:
stdoutstderrloggingSo the protection happens while the program is actually running.
The CLI
SecretShield isn't only a library you import into your code.
It also comes with a CLI.
You can run an existing Python program through SecretShield without changing the application:
This makes it possible to add runtime protection to an existing development workflow without manually adding SecretShield calls everywhere.
There's also a static scanner:
secretshield scan .This scans project files for likely exposed secrets without executing them.
It can be useful for source code, configuration files,
.envfiles, scripts, and other project files.The scanner can also output machine-readable results and return appropriate exit codes, making it possible to use it as part of CI.
For example:
secretshield scan . --jsonA CI pipeline can then fail if potential secrets are detected.
Why build this when secret scanners already exist?
There are already excellent tools for scanning:
SecretShield isn't trying to replace those.
The part I wanted to focus on is runtime output.
A secret can be perfectly fine sitting in an environment variable and still accidentally get exposed five seconds later because someone wrote:
or because an exception/debug statement/logging call included it.
SecretShield is designed to catch that at the output layer.
So the idea is basically:
Static scanning → catch secrets in files
Runtime protection → catch secrets being printed/logged
And the CLI brings both workflows together.
How detection works
SecretShield uses a combination of detection approaches rather than relying on one pattern.
It can recognize known secret formats and also look for suspicious high-entropy strings and credential-shaped values.
The goal isn't to claim that every random string is a secret.
False positives are an important part of the problem, so the project includes tests for things like normal text, repeated values, entropy-based detection, multiline output, logging, and other edge cases.
Privacy / architecture
SecretShield is designed to run locally.
It:
The idea is to provide a small safety net, not another service that has to receive your secrets in order to protect them.
What SecretShield is NOT
It's not intended to replace:
It's another layer of protection for a very specific failure mode:
I'd love feedback from other Python developers, especially on:
If you try it against an actual project, I'd especially like to hear what it catches — or what it incorrectly flags.
GitHub: https://github.com/Sam3360/secretshield
PyPI: https://pypi.org/project/secretshield/
This started as a small Python experiment and grew into a full library + CLI. I'm interested in seeing whether the runtime-protection approach is actually useful in real Python development workflows.
All reactions