Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions java/ql/lib/semmle/code/java/dataflow/ExternalFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,16 @@ public void testSetSharedPrefs6(Context context, String name, String password)
.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
}
}