mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Merge pull request #8817 from atorralba/atorralba/cleartext-storage-sharedprefs-improvs
Java: Add value-preserving flow steps for Android's SharedPreferences
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: minorAnalysis
|
||||
---
|
||||
Improved the data flow support for the Android class `SharedPreferences$Editor`. Specifically, the fluent logic of some of its methods is now taken into account when calculating data flow.
|
||||
@@ -82,6 +82,7 @@ private module Frameworks {
|
||||
private import semmle.code.java.frameworks.android.ContentProviders
|
||||
private import semmle.code.java.frameworks.android.Intent
|
||||
private import semmle.code.java.frameworks.android.Notifications
|
||||
private import semmle.code.java.frameworks.android.SharedPreferences
|
||||
private import semmle.code.java.frameworks.android.Slice
|
||||
private import semmle.code.java.frameworks.android.SQLite
|
||||
private import semmle.code.java.frameworks.android.Widget
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/** Provides classes related to `android.content.SharedPreferences`. */
|
||||
|
||||
import java
|
||||
private import semmle.code.java.dataflow.ExternalFlow
|
||||
|
||||
/** The interface `android.content.SharedPreferences`. */
|
||||
class SharedPreferences extends Interface {
|
||||
@@ -55,3 +56,19 @@ class StoreSharedPreferenceMethod extends Method {
|
||||
this.hasName(["commit", "apply"])
|
||||
}
|
||||
}
|
||||
|
||||
private class SharedPreferencesSummaries extends SummaryModelCsv {
|
||||
override predicate row(string row) {
|
||||
row =
|
||||
[
|
||||
"android.content;SharedPreferences$Editor;true;clear;;;Argument[-1];ReturnValue;value",
|
||||
"android.content;SharedPreferences$Editor;true;putBoolean;;;Argument[-1];ReturnValue;value",
|
||||
"android.content;SharedPreferences$Editor;true;putFloat;;;Argument[-1];ReturnValue;value",
|
||||
"android.content;SharedPreferences$Editor;true;putInt;;;Argument[-1];ReturnValue;value",
|
||||
"android.content;SharedPreferences$Editor;true;putLong;;;Argument[-1];ReturnValue;value",
|
||||
"android.content;SharedPreferences$Editor;true;putString;;;Argument[-1];ReturnValue;value",
|
||||
"android.content;SharedPreferences$Editor;true;putStringSet;;;Argument[-1];ReturnValue;value",
|
||||
"android.content;SharedPreferences$Editor;true;remove;;;Argument[-1];ReturnValue;value"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,9 +89,16 @@ public class CleartextStorageSharedPrefsTest extends Activity {
|
||||
.create(context, "secret_shared_prefs", masterKey,
|
||||
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
|
||||
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM)
|
||||
.edit().putString("name", name) /// Safe
|
||||
.edit().putString("name", name) // Safe
|
||||
.putString("password", password); // Safe
|
||||
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public void testSetSharedPrefs7(Context context, String name, String password) {
|
||||
SharedPreferences sharedPrefs =
|
||||
context.getSharedPreferences("user_prefs", Context.MODE_PRIVATE);
|
||||
sharedPrefs.edit().putString("name", name).apply(); // Safe
|
||||
sharedPrefs.edit().putString("password", password).apply(); // $hasCleartextStorageSharedPrefs
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user