VNX-766: Critical Data Element Declared Public
Reports Java fields declared public that hold secret material: non-final public password, secret, API key, private key, token or credential fields of a string-like type, public PrivateKey/SecretKey/KeyPair/KeyStore fields, and public final char[]/byte[] secrets.
| Field | Value |
|---|---|
| Rule ID | VNX-766 |
| Severity | Low |
| SARIF level | note |
| Kind | sast |
| Languages | Java |
| CWE | CWE-766 |
| CAPEC | CAPEC-66 |
| ATT&CK | T1190 |
| CWSS vector | CWSS:1.0/TI:L/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:L/DI:H/EX:L/EC:N/P:L |
| Tags | critical-data-elem-declared-public cwe-766 |
| Source | internal/sast/rules/vnx-766.rego |
Overview
VNX-766 maps to CWE-766: Critical Data Element Declared Public. It reports a Java class field that is declared public and holds secret material:
- a non-final public field of type
String,char[],byte[],CharSequence, aMap/Propertiesor a*Credentialstype whose name says it is a password, secret, API key, private/signing/encryption/master key, token or credential; - any public field typed
PrivateKey,SecretKey,KeyPair,KeyStoreorSecretKeySpec; - a
public final char[]orbyte[]secret:finalfreezes the reference, not the contents.
Not reported: private, protected and package-private fields, public static final String constants (these are nearly always parameter or header names such as PASSWORD_PARAM), non-secret types (boolean passwordExpired, int tokenCount), names that describe metadata about a secret (passwordHint, tokenUrl, tokenType), local variables, comments, string literals and test sources.
Why This Matters
A public field has no access control at all: any class in the process, including a plugin, a deserialisation gadget or a logging helper that reflects over objects, can read the secret or overwrite it. A public mutable buffer also cannot be wiped reliably, because the owning class does not know who else holds it.
What Gets Flagged
public class MailSettings {
public String password; // flagged
public static String apiKey = System.getenv("MAIL_API_KEY"); // flagged
public PrivateKey signingKey; // flagged
public static final char[] MASTER_PASSWORD = {'c', 'h'}; // flagged: contents are mutable
}
Not flagged:
public static final String PASSWORD_PARAM = "password";
private String password;
public boolean passwordExpired;
Remediation
- Make the field
privateand expose only what callers need: a method that uses the secret, or an accessor that returns a copy. - Keep keys in a
KeyStoreor secret manager and pass them to the code that uses them rather than publishing them on a settings object. - Hold passwords in
char[]owned by one class and clear them withArrays.fillafter use.
References
Suppressing this rule
Put a nosec comment on the line, or on line 1 to cover the whole file. Use the comment marker of the file’s language (#, //, -- or ;):
# nosec vnx-766
// nosec vnx-766
Or record an ignore rule: vulnetix ignore add --rule vnx-766 --reason "...". See Suppressing findings.