GitHub Secret Scanning not detecting hardcoded API keys in Java String constants #191555
-
🏷️ Discussion TypeBug BodyGitHub Secret Scanning fails to detect API keys and passwords when hardcoded in Java source files as static constants, even with Advanced Security enabled. Secrets in plaintext configuration files (.properties, .env) are detected immediately, but identical secrets in Java source code go unnoticed. Example of Undetected Secrets (Java Code) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
💬 Your Product Feedback Has Been Submitted 🎉 Thank you for taking the time to share your insights with us! Your feedback is invaluable as we build a better GitHub experience for all our users. Here's what you can expect moving forward ⏩
Where to look to see what's shipping 👀
What you can do in the meantime 💻
As a member of the GitHub community, your participation is essential. While we can't promise that every suggestion will be implemented, we want to emphasize that your feedback is instrumental in guiding our decisions and priorities. Thank you once again for your contribution to making GitHub even better! We're grateful for your ongoing support and collaboration in shaping the future of our platform. ⭐ |
Beta Was this translation helpful? Give feedback.
-
|
This is actually a known limitation. GitHub Secret Scanning primarily targets specific file types and patterns like For catching hardcoded secrets inside 1. Use detect-secrets as a pre-commit hook pip install detect-secrets
detect-secrets scan > .secrets.baselineThis catches secrets in any file type including 2. Add Trufflehog to your GitHub Actions workflow - name: Scan for secrets
uses: trufflesecurity/trufflehog@main
with:
path: ./
base: main3. Use SpotBugs with Find Security Bugs in your Maven build <plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.8.3.1</version>
</plugin>But the real fix is to never store secrets in source code at all. Use Spring Boot's @Value("${API_KEY}")
private String apiKey;Then inject the actual value through GitHub Actions secrets at runtime. That way the secret never touches your codebase. |
Beta Was this translation helpful? Give feedback.
This is actually a known limitation. GitHub Secret Scanning primarily targets specific file types and patterns like
.env,.properties,.yaml,.jsonrather than scanning raw Java source code for string literals.For catching hardcoded secrets inside
.javafiles, here are your options:1. Use detect-secrets as a pre-commit hook
pip install detect-secrets detect-secrets scan > .secrets.baselineThis catches secrets in any file type including
.javabefore they even hit the repo.2. Add Trufflehog to your GitHub Actions workflow
3. Use SpotBugs with Find Security Bugs in your Maven build
<plugin>…