Secret Hardcoded Setter
A credential is passed as a hardcoded string literal to a setter (setPassword/setApiKey/setToken/etc.), embedding the secret in the source and compiled artifact (CWE-798).
Standards mapping
- OWASP ASVS
- V6.4.1 (L2)V2.10.4 (L2)
Vulnerable vs. safe
config.setPassword("P@ssw0rd123");config.setPassword(System.getenv("DB_PASSWORD"));Why it matters & how to fix it
A credential is passed as a hardcoded string literal to a setter (setPassword/setApiKey/setToken/etc.), embedding the secret in the source and compiled artifact (CWE-798). Anyone with the JAR/WAR can extract it and rotation forces a redeploy. Inject the value at runtime from an environment variable, a Spring @Value/@ConfigurationProperties bound to an external secret, or a secrets manager (Vault / AWS Secrets Manager).
References
Rule ID integsec-java-secret-hardcoded-setter - engine: Opengrep - license: MIT - Copyright (c) IntegSec Inc.
TurboPentest runs this check automatically
Connect a GitHub repo and this check runs on every white-box pentest - AI-validated and reported with proof, from $99 per target.
Start a pentestRelated checks
- JavaScript / TypeScript - Hardcoded SecretsBasic Auth Credentials In URL
- JavaScript / TypeScript - Hardcoded SecretsDB Connection String With Credentials
- JavaScript / TypeScript - Hardcoded SecretsHardcoded Credential String
- JavaScript / TypeScript - Hardcoded SecretsHardcoded Crypto Key Or IV
- Python - Hardcoded SecretsBasic Auth Credentials In URL
- Python - Hardcoded SecretsDB Connection String Credentials