Registry
Aalexbit-codemod avatar

java-hardcoded-credentials-mining

Mine credential-setting APIs called with hard-coded string literals (java:S6437); read-only metrics for security review

alexbit-codemod0 executions

  • mining
  • metrics
  • java
  • security
  • vulnerability
  • credentials
  • password
  • hardcoded
  • cwe-798
Connect a repo
npx codemod java-hardcoded-credentials-mining

java-hardcoded-credentials-mining

Read-only mining codemod for SonarSource rule java:S6437 — Credentials 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:S6437
TypeVulnerability
SeverityBlocker
Primary CWECWE-798 (Use of Hard-coded Credentials)
Tagscwe

What it detects

Credential-setting APIs invoked with a hard-coded, non-empty string literal.

Sinks:

  • setPassword / setUser(name) / setSecret / setSecretKey / setAccessKey / setApiKey / setCredentials / setToken / withPassword / withUsername / basicAuthentication / setBasicAuth
  • new PasswordAuthentication / UsernamePasswordCredentials / BasicAWSCredentials / UsernamePasswordAuthenticationToken / NTCredentials

Emission rule: Emits when a credential argument is a non-empty string literal (including "...".toCharArray()). Values from env/config method calls are skipped.

Metric: java-hardcoded-credentials-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_kindalways literal

Security standards

  • CWE-259 (Use of Hard-coded Password)
  • CWE-798 (Use of Hard-coded Credentials)
  • OWASP Top 10 2021: A7
  • OWASP Top 10: A2

Run locally

bash
cd codemods/java-security-blocker-mining/java-hardcoded-credentials-mining
npm test

# Scan a target project (read-only; emits metrics, leaves source unchanged)
npx codemod@latest workflow run \
  -w codemods/java-security-blocker-mining/java-hardcoded-credentials-mining/workflow.yaml \
  --target /path/to/java/project

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 evolve your codebase?

Build tailored, compiler-aware skills to assess, plan, and automate complex codebase changes.