-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Java: Query to detect cleartext storage of sensitive information using Android SharedPreferences #4675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java: Query to detect cleartext storage of sensitive information using Android SharedPreferences #4675
Conversation
java/ql/src/Security/CWE/CWE-312/ClearTextStorageSharedPrefs.java
Outdated
Show resolved
Hide resolved
java/ql/src/Security/CWE/CWE-312/ClearTextStorageSharedPrefs.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/Security/CWE/CWE-312/ClearTextStorageSharedPrefs.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/Security/CWE/CWE-312/ClearTextStorageSharedPrefs.ql
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests are in experimental but the query itself is not?
Also check my understanding: the reason we can't simply say a setter call against a SharedPreferences.Editor is a sink is because we need to know that this instance of SharedPreferences is specifically not an EncryptedSharedPreferences, which is a subclass that uses the same Editor?
Thanks @smowton for reviewing this PR. Yes, your understanding is correct. We need to know that this instance of SharedPreferences is specifically not an EncryptedSharedPreferences, which is a subclass that uses the same Editor. Although there is no existing tests folder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some questions, many of which are perhaps best answered with negative tests (i.e. tests that show the relevant vulnerability, but the query cannot detect) -- what are this query's restrictions? Where can it tolerate arbitrary dataflow, and where only local dataflow or no intermediate flow at all?
java/ql/src/Security/CWE/CWE-312/ClearTextStorageSharedPrefs.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/Security/CWE/CWE-312/ClearTextStorageSharedPrefs.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/semmle/code/java/frameworks/android/SharedPreferences.qll
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could live in experimental, which will make the review process much easier -- as far as I can tell the only shared code with the existing SensitiveStorage file is your use of the SensitiveExpr class, which is already public so you should be able to use it from experimental?
java/ql/src/semmle/code/java/frameworks/android/SharedPreferences.qll
Outdated
Show resolved
Hide resolved
java/ql/src/semmle/code/java/frameworks/android/SharedPreferences.qll
Outdated
Show resolved
Hide resolved
I've started an evaluation of this -- one problem I noticed doing so: the |
I've changed the |
java/ql/src/experimental/Security/CWE/CWE-312/CleartextStorageSharedPrefs.ql
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-312/CleartextStorageSharedPrefs.ql
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-312/CleartextStorageSharedPrefs.ql
Outdated
Show resolved
Hide resolved
java/ql/src/semmle/code/java/frameworks/android/SharedPreferences.qll
Outdated
Show resolved
Hide resolved
java/ql/src/semmle/code/java/frameworks/android/SharedPreferences.qll
Outdated
Show resolved
Hide resolved
java/ql/src/semmle/code/java/frameworks/android/SharedPreferences.qll
Outdated
Show resolved
Hide resolved
java/ql/src/semmle/code/java/frameworks/android/SharedPreferences.qll
Outdated
Show resolved
Hide resolved
java/ql/src/semmle/code/java/frameworks/android/SharedPreferences.qll
Outdated
Show resolved
Hide resolved
java/ql/src/semmle/code/java/frameworks/android/SharedPreferences.qll
Outdated
Show resolved
Hide resolved
java/ql/src/semmle/code/java/frameworks/android/SharedPreferences.qll
Outdated
Show resolved
Hide resolved
java/ql/src/semmle/code/java/frameworks/android/SharedPreferences.qll
Outdated
Show resolved
Hide resolved
java/ql/src/semmle/code/java/frameworks/android/SharedPreferences.qll
Outdated
Show resolved
Hide resolved
java/ql/src/semmle/code/java/frameworks/android/SharedPreferences.qll
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more comments, otherwise it's looking good.
SharedPreferences
is an Android API that stores application preferences using simple sets of data values. Almost every Android application uses this API. It allows to easily save, alter, and retrieve the values stored inSharedPreferences
.However, sensitive information shall not be saved in cleartext. Otherwise it can be accessed by any process or user on rooted devices, or can be disclosed through chained vulnerabilities e.g. unexpected access to its private storage through exposed components.
This query detects storage of sensitive information in cleartext using
SharedPreferences
on Android devices.Please consider to merge the PR. Thanks.