VNX-1304: Security state restored from unprotected saved state
Detects Android Java/Kotlin code that restores a security decision (logged in, admin, role, PIN verified, unlocked, premium) from plain SharedPreferences or a saved-instance Bundle instead of re-establishing it. The software analogue of CWE-1304.
| Field | Value |
|---|---|
| Rule ID | VNX-1304 |
| Severity | Medium |
| SARIF level | warning |
| Kind | sast |
| Languages | Java, Kotlin |
| CWE | CWE-1304 |
| CAPEC | CAPEC-66 |
| ATT&CK | T1190 |
| CWSS vector | CWSS:1.0/TI:M/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:M/DI:H/EX:M/EC:N/P:C |
| Tags | saved-state-integrity android cwe-1304 |
| Source | internal/sast/rules/vnx-1304.rego |
Overview
VNX-1304 maps to CWE-1304: Improperly Preserved Integrity of Hardware Configuration State During a Power Save/Restore Operation. CWE-1304 is a hardware weakness: configuration saved before a low-power state is restored afterwards without an integrity check. Hardware save/restore is not visible in application source, so the rule reports the nearest software analogue: a security decision saved across a process stop and restored as trusted.
Reported: getBoolean, getString or getInt whose key names a security decision (logged in, authenticated, admin, role, PIN or biometric verified, unlocked, premium or licensed, access level), as a literal or as a constant of the same file, called on
- plain
SharedPreferences(a variable typedSharedPreferencesor assigned fromgetSharedPreferences/getDefaultSharedPreferences, or a call chained onto one), which a rooted device or a backup restore can edit; or - a saved-instance
Bundle(savedInstanceState, a variable typedBundle), restored after process death, which skips re-authentication.
Not reported: EncryptedSharedPreferences, keys that are not security decisions (theme, language, scroll position), the same getters on JSON objects or Intents, test code and comments.
What Gets Flagged
SharedPreferences prefs = getSharedPreferences("bank", MODE_PRIVATE);
boolean loggedIn = prefs.getBoolean("isLoggedIn", false); // FLAGGED
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
pinVerified = savedInstanceState.getBoolean("pin_verified"); // FLAGGED
}
What Is Not Flagged
boolean dark = prefs.getBoolean("dark_mode", false);
boolean authenticated = response.getBoolean("authenticated"); // a JSON response
Remediation
- Re-establish authentication and authorisation after a restart: ask the user again or confirm with the server.
- Keep any persisted security state in
EncryptedSharedPreferencesor the Android Keystore, and treat it as a hint, not a decision. - Do not restore a “PIN verified” or “unlocked” flag from
savedInstanceState.
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-1304
// nosec vnx-1304
Or record an ignore rule: vulnetix ignore add --rule vnx-1304 --reason "...". See Suppressing findings.