An encrypted mobile database is opened with a key written into the code, which anyone with the app can read
What it finds
The key of an encrypted SQLCipher or Realm database protects the data only while it is secret. A key in a string literal ships inside the app and is one decompilation away.
Reported is a string literal passed as the key to getWritableDatabase, getReadableDatabase or openOrCreateDatabase, or turned into bytes for Realm's encryptionKey.
From the rule's source, hardcoded_database_key.rs.
class Store { void run(Helper helper, String key) { helper.getWritableDatabase("s3cret");tx0 reports: written into the code helper.getWritableDatabase(key); } interface Helper { Object getWritableDatabase(String key); }} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/java:hardcoded-database-key" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/java:hardcoded-database-key] reason="..."tx0 explain tx0/java:hardcoded-database-key shows the same in the terminal. Found a false positive? Report it.