Aalexbit-codemod

java-hardcoded-secrets-mining

Mine secret-like variables and fields assigned hard-coded string literals (java:S6418); read-only metrics for security review

miningmetricsjavasecurityvulnerabilitysecretshardcodedtokencwe-798
Public
0 executions

Run locally

npx codemod java-hardcoded-secrets-mining

java-hardcoded-secrets-mining

Read-only mining codemod for SonarSource rule java:S6418Secrets should not be hard-coded.

It scans Java source and emits metrics only; it never modifies code (return null).
Findings are high-signal review candidates surfaced by AST pattern matching — they are
not proven vulnerabilities. A static mining pass cannot prove an end-to-end taint flow
from an untrusted source to the sink, so confirm data flow before remediating.

FieldValue
Rule keyjava:S6418
TypeVulnerability
SeverityBlocker
Primary CWECWE-798 (Use of Hard-coded Credentials)
Tagscert, cwe, former-hotspot

What it detects

Secret-like variables and fields assigned a hard-coded string literal.

Sinks:

  • variable/field declarations and assignments whose name matches password/secret/token/apiKey/accessKey/privateKey/credential/…

Emission rule: Emits when a secret-named target is assigned a string literal of length ≥ 4. Values from env/config method calls are skipped.

Metric: java-hardcoded-secrets-mining

dimensionmeaning
ruleSonarSource rule key
cweprimary CWE identifier
severityalways blocker
sinkthe detected sink (method/constructor)
package_nameenclosing Java package
class_nameenclosing class/interface/enum/record
method_nameenclosing method/constructor (or <none>)
filefile path (relative to scan target)
line1-based line of the finding
arg_kindclassification of the relevant argument (literal, concatenation, variable, method_call, field, object_creation, expression, none)
secret_namename of the secret-like variable/field

Security standards

  • CWE-798 (Use of Hard-coded Credentials)
  • OWASP ASVS 4.0: 2.10.4, 3.5.2, 6.4.1
  • OWASP Mobile Top 10 2024: M1
  • OWASP Top 10 2021: A7
  • OWASP Top 10: A2
  • PCI DSS 3.2: 6.5.10
  • PCI DSS 4.0: 6.2.4

Run locally

bash

Part of the java-security-blocker-mining suite covering 19 blocker-severity
Java vulnerability rules. Each codemod is read-only and emits a single named metric.

Ready to contribute?

Build your own codemod and share it with the community.