-
Notifications
You must be signed in to change notification settings - Fork 31
DART-259 Modify rule S6291: Add Dart language #4990
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The encryption password should not be hard-coded in the application. There are different approaches how the password can be provided to encrypt and decrypt the database. In the case of `EncryptedSharedPreferences` the Android Keystore can be used to store the password. Other databases can rely on `EncryptedSharedPreferences` to store passwords. The password can also be provided dynamically by the user of the application or it can be fetched from a remote server if the other methods are not feasible. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,62 @@ | ||||||
:example_libraries: sqflite and sqflite_sqlcipher | ||||||
|
||||||
include::../description.adoc[] | ||||||
|
||||||
include::../ask-yourself.adoc[] | ||||||
|
||||||
include::../recommended.adoc[] | ||||||
|
||||||
The encryption password should not be hard-coded in the application. There are different approaches how the password can be provided to encrypt and decrypt the database, such as using https://pub.dev/packages/flutter_secure_storage[`flutter_secure_storage`]. The password can also be provided dynamically by the user of the application or it can be fetched from a remote server if the other methods are not feasible. | ||||||
|
||||||
== Sensitive Code Example | ||||||
|
||||||
For the https://pub.dev/packages/sqflite[`sqflite` package]: | ||||||
|
||||||
[source,dart] | ||||||
---- | ||||||
import 'package:sqflite/sqflite.dart'; | ||||||
|
||||||
void openDb() async { | ||||||
final db = await openDatabase("test.db"); // Noncompliant: no password support | ||||||
await db.execute("CREATE TABLE Test (id INTEGER PRIMARY KEY, name TEXT)"); | ||||||
} | ||||||
---- | ||||||
|
||||||
For the https://pub.dev/packages/sqflite_sqlcipher[`sqflite_sqlcipher` package]: | ||||||
|
||||||
[source,dart] | ||||||
---- | ||||||
import 'package:sqflite_sqlcipher/sqflite.dart'; | ||||||
|
||||||
void openDb() async { | ||||||
final db = await openDatabase("test.db"); // Noncompliant: missing password | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
await db.execute("CREATE TABLE Test (id INTEGER PRIMARY KEY, name TEXT)"); | ||||||
} | ||||||
---- | ||||||
|
||||||
== Compliant Solution | ||||||
|
||||||
Instead of the `openDatabase` function of the `sqflite` package, you can use the equivalent function in the https://pub.dev/packages/sqflite_sqlcipher[`sqflite_sqlcipher` package], that comes with a `password` parameter to encrypt the database: | ||||||
|
||||||
[source,dart] | ||||||
---- | ||||||
import 'package:sqflite_sqlcipher/sqflite.dart'; | ||||||
|
||||||
void openDb() async { | ||||||
final db = await openDatabase("test.db", password: "password"); // Compliant | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
await db.execute("CREATE TABLE Test (id INTEGER PRIMARY KEY, name TEXT)"); | ||||||
} | ||||||
---- | ||||||
|
||||||
include::../see.adoc[] | ||||||
|
||||||
|
||||||
ifdef::env-github,rspecator-view[] | ||||||
|
||||||
''' | ||||||
== Implementation Specification | ||||||
(visible only on this page) | ||||||
|
||||||
include::../message.adoc[] | ||||||
|
||||||
endif::env-github,rspecator-view[] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
Storing data locally is a common task for mobile applications. Such data includes preferences or authentication tokens for external services, among other things. There are many convenient solutions that allow storing data persistently, for example SQLiteDatabase, SharedPreferences, and Realm. By default these systems store the data unencrypted, thus an attacker with physical access to the device can read them out easily. Access to sensitive data can be harmful for the user of the application, for example when the device gets stolen. | ||
Storing data locally is a common task for mobile applications. Such data includes preferences or authentication tokens for external services, among other things. There are many convenient solutions that allow storing data persistently, for example {example_libraries}. | ||
|
||
By default these systems store the data unencrypted, thus an attacker with physical access to the device can read them out easily. Access to sensitive data can be harmful for the user of the application, for example when the device gets stolen. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
== Recommended Secure Coding Practices | ||
|
||
It's recommended to password-encrypt local databases that contain sensitive information. Most systems provide secure alternatives to plain-text storage that should be used. If no secure alternative is available the data can also be encrypted manually before it is stored. | ||
|
||
The encryption password should not be hard-coded in the application. There are different approaches how the password can be provided to encrypt and decrypt the database. In the case of `EncryptedSharedPreferences` the Android Keystore can be used to store the password. Other databases can rely on `EncryptedSharedPreferences` to store passwords. The password can also be provided dynamically by the user of the application or it can be fetched from a remote server if the other methods are not feasible. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.