dart-decimate 0.0.29 → 0.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/Cargo.lock +1 -1
  2. package/Cargo.toml +1 -1
  3. package/README.md +36 -60
  4. package/npm/bin/runner.js +26 -14
  5. package/npm/scripts/postinstall.js +89 -63
  6. package/package.json +3 -2
  7. package/src/baseline.rs +38 -0
  8. package/src/cli/health_args.rs +36 -7
  9. package/src/cli/html_open.rs +4 -0
  10. package/src/cli/issue_filter_args.rs +1 -0
  11. package/src/cli/security_summary_run.rs +1 -0
  12. package/src/config/health.rs +22 -2
  13. package/src/config/rule_aliases.rs +43 -0
  14. package/src/config/rules.rs +46 -1
  15. package/src/config.rs +2 -1
  16. package/src/dart_parser/test_support.rs +51 -0
  17. package/src/dart_parser.rs +8 -0
  18. package/src/dependencies/analyze.rs +3 -1
  19. package/src/dependencies/tests.rs +111 -7
  20. package/src/dependencies/usage.rs +5 -1
  21. package/src/dependencies.rs +7 -3
  22. package/src/explain/flutter_style.rs +43 -0
  23. package/src/explain/misc.rs +72 -0
  24. package/src/explain.rs +23 -67
  25. package/src/flutter_style/scanner.rs +883 -0
  26. package/src/flutter_style/types.rs +90 -0
  27. package/src/flutter_style/usage.rs +349 -0
  28. package/src/flutter_style.rs +72 -0
  29. package/src/generated.rs +154 -0
  30. package/src/health/large_units.rs +49 -0
  31. package/src/health/tests.rs +212 -1
  32. package/src/health/threshold_types.rs +31 -1
  33. package/src/health/thresholds.rs +49 -0
  34. package/src/health/types.rs +35 -0
  35. package/src/health.rs +72 -6
  36. package/src/inspect.rs +8 -0
  37. package/src/lib.rs +17 -5
  38. package/src/manifest.rs +7 -3
  39. package/src/output/dependency_findings.rs +14 -1
  40. package/src/output/flutter_style.rs +189 -0
  41. package/src/output/health_findings.rs +93 -10
  42. package/src/output/health_inventory.rs +121 -0
  43. package/src/output/html/tests.rs +20 -0
  44. package/src/output/html.rs +10 -1
  45. package/src/output/human.rs +85 -1
  46. package/src/output/human_details.rs +93 -12
  47. package/src/output/scope.rs +62 -2
  48. package/src/output/security_findings.rs +101 -76
  49. package/src/output/security_sarif.rs +24 -13
  50. package/src/output/suppressions.rs +4 -0
  51. package/src/output/types.rs +38 -2
  52. package/src/output/verdict.rs +12 -0
  53. package/src/output.rs +77 -74
  54. package/src/report_schema/inventory.rs +268 -4
  55. package/src/report_schema.rs +94 -60
  56. package/src/security/catalogue.rs +103 -0
  57. package/src/security/detect/weak_randomness.rs +762 -0
  58. package/src/security/detect.rs +1535 -221
  59. package/src/security/security_matchers.toml +172 -0
  60. package/src/security/tests.rs +336 -2
  61. package/src/security.rs +292 -56
  62. package/src/security_gate.rs +28 -0
  63. package/src/semantic.rs +276 -0
  64. package/src/symbols/semantic_evidence.rs +342 -0
  65. package/src/symbols.rs +20 -10
  66. package/src/trace/rendering.rs +54 -0
  67. package/src/trace/semantic.rs +126 -0
  68. package/src/trace.rs +54 -62
  69. package/src/widgets/inheritance.rs +63 -0
  70. package/src/widgets.rs +33 -3
@@ -0,0 +1,172 @@
1
+ version = 1
2
+
3
+ [[matchers]]
4
+ category = "hardcoded-secret"
5
+ rule_id = "dart-decimate/security-hardcoded-secret"
6
+ detector = "hardcoded-secret"
7
+ sink_shape = "literal-or-binding"
8
+ argument_index = 0
9
+ literal_predicate = "secret-shaped-or-secret-context"
10
+ context_predicate = "secret-named-binding"
11
+ import_provenance = "dart:io-or-package:process"
12
+ callees = []
13
+ cwe = ["CWE-798"]
14
+ effect = "credential-disclosure"
15
+ evidence_template = "secret-shaped source literal or binding"
16
+ source = "source-code-literal"
17
+ boundary = "source-control"
18
+ trace_role = "source"
19
+ default_severity = "error"
20
+ verification_prompt = "Verify whether this literal is a real secret and rotate it if confirmed."
21
+
22
+ [[matchers]]
23
+ category = "firebase-api-key"
24
+ rule_id = "dart-decimate/security-firebase-api-key"
25
+ detector = "firebase-api-key"
26
+ sink_shape = "named-argument"
27
+ argument_index = 0
28
+ literal_predicate = "firebase-api-key"
29
+ context_predicate = "FirebaseOptions.apiKey"
30
+ import_provenance = "dart:io-or-package:process"
31
+ callees = ["FirebaseOptions"]
32
+ cwe = ["CWE-200"]
33
+ effect = "client-configuration-disclosure"
34
+ evidence_template = "FirebaseOptions apiKey literal"
35
+ source = "firebase-options-api-key"
36
+ boundary = "firebase-client-config"
37
+ trace_role = "source"
38
+ default_severity = "warning"
39
+ verification_prompt = "Verify it is Firebase-provisioned, restricted to Firebase APIs, and covered by Security Rules and App Check."
40
+
41
+ [[matchers]]
42
+ category = "insecure-transport"
43
+ rule_id = "dart-decimate/security-insecure-transport"
44
+ detector = "insecure-transport"
45
+ sink_shape = "network-url"
46
+ argument_index = 0
47
+ literal_predicate = "remote-http-url"
48
+ context_predicate = "network-call-or-oauth-endpoint"
49
+ import_provenance = "any"
50
+ callees = ["Uri.parse", "Uri.http", "http.get", "http.post", "Dio.get", "Dio.post"]
51
+ cwe = ["CWE-319"]
52
+ effect = "cleartext-network-disclosure"
53
+ evidence_template = "remote http URL in network context"
54
+ source = "http-url-literal"
55
+ boundary = "network-transport"
56
+ trace_role = "sink"
57
+ default_severity = "error"
58
+ verification_prompt = "Verify whether this remote HTTP endpoint can expose sensitive traffic."
59
+
60
+ [[matchers]]
61
+ category = "tls-bypass"
62
+ rule_id = "dart-decimate/security-tls-bypass"
63
+ detector = "tls-bypass"
64
+ sink_shape = "callback-assignment"
65
+ argument_index = 0
66
+ literal_predicate = "accepts-invalid-certificate"
67
+ context_predicate = "certificate-validation"
68
+ import_provenance = "any"
69
+ callees = ["badCertificateCallback", "validateCertificate"]
70
+ cwe = ["CWE-295"]
71
+ effect = "certificate-validation-bypass"
72
+ evidence_template = "TLS validation callback accepts an invalid certificate"
73
+ source = "tls-validation-callback"
74
+ boundary = "tls-validation"
75
+ trace_role = "boundary"
76
+ default_severity = "error"
77
+ verification_prompt = "Verify whether certificate validation can be bypassed outside trusted development code."
78
+
79
+ [[matchers]]
80
+ category = "web-view-risk"
81
+ rule_id = "dart-decimate/security-webview-risk"
82
+ detector = "webview-risk"
83
+ sink_shape = "configuration-or-call"
84
+ argument_index = 0
85
+ literal_predicate = "unrestricted-or-file-url"
86
+ context_predicate = "webview"
87
+ import_provenance = "any"
88
+ callees = ["JavaScriptMode.unrestricted", "javaScriptEnabled", "allowFileAccess", "allowFileAccessFromFileURLs", "allowUniversalAccessFromFileURLs", "loadUrl", "loadRequest"]
89
+ cwe = ["CWE-749"]
90
+ effect = "untrusted-web-content-capability"
91
+ evidence_template = "WebView capability or local-file exposure"
92
+ source = "webview-configuration"
93
+ boundary = "embedded-webview"
94
+ trace_role = "boundary"
95
+ default_severity = "error"
96
+ verification_prompt = "Verify whether untrusted content can execute JavaScript or access local files."
97
+
98
+ [[matchers]]
99
+ category = "process-execution"
100
+ rule_id = "dart-decimate/security-process-execution"
101
+ detector = "process-execution"
102
+ sink_shape = "call"
103
+ argument_index = 0
104
+ literal_predicate = "dynamic-command-or-shell"
105
+ context_predicate = "process-execution"
106
+ import_provenance = "any"
107
+ callees = ["Process.run", "Process.runSync", "Process.start", "processManager.run", "processManager.runSync", "processManager.start"]
108
+ cwe = ["CWE-78"]
109
+ effect = "operating-system-command-execution"
110
+ evidence_template = "process call arguments or shell configuration"
111
+ source = "process-call-arguments"
112
+ boundary = "operating-system-process"
113
+ trace_role = "sink"
114
+ default_severity = "error"
115
+ verification_prompt = "Verify whether attacker-controlled input can influence the executable, arguments, or shell."
116
+
117
+ [[matchers]]
118
+ category = "raw-sql"
119
+ rule_id = "dart-decimate/security-raw-sql"
120
+ detector = "raw-sql"
121
+ sink_shape = "call"
122
+ argument_index = 0
123
+ literal_predicate = "dynamic-query-text"
124
+ context_predicate = "sql-call-or-where"
125
+ import_provenance = "any"
126
+ callees = [".rawQuery", ".rawInsert", ".rawUpdate", ".rawDelete", ".execute", ".customSelect", ".customStatement", "where:"]
127
+ cwe = ["CWE-89"]
128
+ effect = "query-text-injection"
129
+ evidence_template = "dynamic SQL text without parameter evidence"
130
+ source = "query-text"
131
+ boundary = "database"
132
+ trace_role = "sink"
133
+ default_severity = "error"
134
+ verification_prompt = "Verify whether untrusted input can alter SQL text instead of using parameters."
135
+
136
+ [[matchers]]
137
+ category = "plain-secret-storage"
138
+ rule_id = "dart-decimate/security-plain-secret-storage"
139
+ detector = "plain-secret-storage"
140
+ sink_shape = "call"
141
+ argument_index = 1
142
+ literal_predicate = "secret-named-value"
143
+ context_predicate = "plain-local-storage"
144
+ import_provenance = "any"
145
+ callees = [".setString", ".setStringList", ".put", ".writeAsString", ".writeAsBytes"]
146
+ cwe = ["CWE-922"]
147
+ effect = "plaintext-secret-persistence"
148
+ evidence_template = "secret-shaped value written to non-secure local storage"
149
+ source = "secret-named-value"
150
+ boundary = "local-storage"
151
+ trace_role = "sink"
152
+ default_severity = "error"
153
+ verification_prompt = "Verify whether secret material is persisted outside secure storage."
154
+
155
+ [[matchers]]
156
+ category = "weak-randomness"
157
+ rule_id = "dart-decimate/security-weak-randomness"
158
+ detector = "weak-randomness"
159
+ sink_shape = "initializer-or-call-argument"
160
+ argument_index = 0
161
+ literal_predicate = "non-secure-random-constructor"
162
+ context_predicate = "security-shaped-name"
163
+ import_provenance = "dart:math"
164
+ callees = ["Random", "Random.secure"]
165
+ cwe = ["CWE-338"]
166
+ effect = "predictable-security-material"
167
+ evidence_template = "dart:math Random() directly feeds a security-shaped declaration or call"
168
+ source = "dart-math-random"
169
+ boundary = "security-token-generation"
170
+ trace_role = "source"
171
+ default_severity = "error"
172
+ verification_prompt = "Verify whether predictable pseudo-random output can become authentication or secret material; use Random.secure when cryptographic unpredictability is required."
@@ -2,7 +2,9 @@ use std::fs;
2
2
 
3
3
  use tempfile::TempDir;
4
4
 
5
- use crate::{SecurityOptions, analyze_security, scan_project};
5
+ use crate::{
6
+ SecurityBlindSpotReason, SecurityCategory, SecurityOptions, analyze_security, scan_project,
7
+ };
6
8
 
7
9
  #[test]
8
10
  fn detects_dart_and_flutter_security_candidate_patterns() -> Result<(), Box<dyn std::error::Error>>
@@ -46,7 +48,7 @@ Future<void> main(dynamic db, dynamic prefs, dynamic controller, String command,
46
48
  .collect::<Vec<_>>();
47
49
 
48
50
  assert_eq!(report.analyzed_files, 1);
49
- assert_eq!(report.total_occurrences, 7);
51
+ assert_eq!(report.total_occurrences, 7, "rules={rules:?}");
50
52
  assert_eq!(report.attack_surface.len(), 7);
51
53
  assert!(rules.contains(&"dart-decimate/security-hardcoded-secret"));
52
54
  assert!(rules.contains(&"dart-decimate/security-insecure-transport"));
@@ -695,6 +697,338 @@ final uri = Uri.parse('http://api.example.com/login');
695
697
  Ok(())
696
698
  }
697
699
 
700
+ #[test]
701
+ fn skips_production_corpus_security_lookalikes() -> Result<(), Box<dyn std::error::Error>> {
702
+ let fixture = tempfile::tempdir()?;
703
+ write(&fixture, "pubspec.yaml", "name: app\n")?;
704
+ write(
705
+ &fixture,
706
+ "lib/main.dart",
707
+ r#"
708
+ import 'dart:io';
709
+ import 'dart:math';
710
+
711
+ const locale = 'sk_SK';
712
+ const modelSha256 =
713
+ 'e047647409403d52696035ecd445792173e50d7fbdcccac97b958a585db9aa3d';
714
+ const streamError = 'crypto_secretstream_xchacha20poly1305_pull';
715
+ const tableName = 'records';
716
+ const oauthToken =
717
+ 'https://api.example.com/oauth2/token';
718
+
719
+ void configure(dynamic prefs, dynamic db, dynamic tokenType) {
720
+ final json = File('script/Primitive.Mode 1.tokens.json').readAsStringSync();
721
+ final authHeader = tokenType.startsWith('Bearer ')
722
+ ? tokenType
723
+ : 'Bearer $tokenType';
724
+ final widget = ValueKey(Random().nextDouble());
725
+ final page = PageStorageKey(Random().nextDouble());
726
+ final key = Key.fromSecureRandom(32);
727
+ prefs.setString('show_token', const Uuid().v4());
728
+ prefs.setString('token_type', AuthTokenType.headlessJwt.name);
729
+ db.rawQuery('SELECT 1');
730
+ db.rawQuery('SELECT * FROM $tableName');
731
+ db.execute(
732
+ 'CREATE INDEX idx '
733
+ 'ON records(value)',
734
+ );
735
+ db.query(
736
+ 'records',
737
+ where: 'id IN ($placeholders)',
738
+ whereArgs: ids,
739
+ );
740
+ db.query(
741
+ 'records',
742
+ where: "json_extract(data, '\$.registeredAt') IS NOT NULL",
743
+ );
744
+ db.rawQuery(r'SELECT json_extract(data, "$.registeredAt") FROM records');
745
+ print([locale, modelSha256, streamError, json, authHeader, widget, page, key]);
746
+ }
747
+ "#,
748
+ )?;
749
+
750
+ let project = scan_project(fixture.path())?;
751
+ let report = analyze_security(&project, &SecurityOptions::default(), None)?;
752
+
753
+ assert!(report.candidates.is_empty(), "{report:#?}");
754
+ assert!(report.blind_spots.is_empty(), "{report:#?}");
755
+
756
+ Ok(())
757
+ }
758
+
759
+ #[test]
760
+ fn reports_split_production_secret_bindings() -> Result<(), Box<dyn std::error::Error>> {
761
+ let fixture = tempfile::tempdir()?;
762
+ write(&fixture, "pubspec.yaml", "name: app\n")?;
763
+ write(
764
+ &fixture,
765
+ "lib/main.dart",
766
+ r"
767
+ const _secretKeyA = 'fixtureSecretValueAlpha123';
768
+ const _secretKeyB =
769
+ 'fixtureSecretValueBeta456';
770
+ ",
771
+ )?;
772
+
773
+ let project = scan_project(fixture.path())?;
774
+ let report = analyze_security(&project, &SecurityOptions::default(), None)?;
775
+ let hardcoded = report
776
+ .candidates
777
+ .iter()
778
+ .find(|candidate| candidate.rule_id == "dart-decimate/security-hardcoded-secret")
779
+ .ok_or("hardcoded secret candidate")?;
780
+
781
+ assert_eq!(hardcoded.occurrences.len(), 2, "{report:#?}");
782
+
783
+ Ok(())
784
+ }
785
+
786
+ #[test]
787
+ fn distinguishes_tls_configuration_from_certificate_bypass()
788
+ -> Result<(), Box<dyn std::error::Error>> {
789
+ let fixture = tempfile::tempdir()?;
790
+ write(&fixture, "pubspec.yaml", "name: app\n")?;
791
+ write(
792
+ &fixture,
793
+ "lib/main.dart",
794
+ r"
795
+ import 'dart:io';
796
+
797
+ final customRoots = SecurityContext(withTrustedRoots: false);
798
+
799
+ bool rejectCertificate(X509Certificate cert, String host, int port) => false;
800
+
801
+ bool configuredCertificate(
802
+ X509Certificate cert,
803
+ String host,
804
+ int port,
805
+ ) {
806
+ if (host.isEmpty) return false;
807
+ return allowInsecureConnections;
808
+ }
809
+
810
+ bool badCertificateCallback(
811
+ X509Certificate cert,
812
+ String host,
813
+ int port,
814
+ ) => allowInsecureConnections;
815
+
816
+ HttpClient configuredClient() {
817
+ return HttpClient()
818
+ ..badCertificateCallback = configuredCertificate;
819
+ }
820
+
821
+ HttpClient sameNamedClient() {
822
+ return HttpClient()
823
+ ..badCertificateCallback = badCertificateCallback;
824
+ }
825
+
826
+ HttpClient rejectingClient() {
827
+ return HttpClient()
828
+ ..badCertificateCallback = rejectCertificate;
829
+ }
830
+
831
+ class ScopedClientFactory {
832
+ static bool badCertificateCallback(
833
+ X509Certificate cert,
834
+ String host,
835
+ int port,
836
+ ) => allowInsecureConnections;
837
+
838
+ HttpClient create() {
839
+ return HttpClient()
840
+ ..badCertificateCallback = badCertificateCallback;
841
+ }
842
+ }
843
+
844
+ class UnrelatedFactory {
845
+ static bool badCertificateCallback(
846
+ X509Certificate cert,
847
+ String host,
848
+ int port,
849
+ ) => false;
850
+ }
851
+
852
+ void configure() {
853
+ HttpOverrides.global = ProxyOnlyOverrides();
854
+ final client = HttpClient();
855
+ client.badCertificateCallback = (_, _, _) => true;
856
+ client.badCertificateCallback = (_, host, _) => host.endsWith('.example');
857
+ client.badCertificateCallback = configuredCertificate;
858
+ client.badCertificateCallback = rejectCertificate;
859
+ client.badCertificateCallback = importedCertificateCallback;
860
+ Adapter(
861
+ validateCertificate:
862
+ allowInsecureConnections ? (_, _, _) => true : null,
863
+ );
864
+ }
865
+ ",
866
+ )?;
867
+
868
+ let project = scan_project(fixture.path())?;
869
+ let report = analyze_security(&project, &SecurityOptions::default(), None)?;
870
+ let tls = report
871
+ .candidates
872
+ .iter()
873
+ .find(|candidate| candidate.rule_id == "dart-decimate/security-tls-bypass")
874
+ .ok_or("TLS candidate")?;
875
+
876
+ assert_eq!(tls.occurrences.len(), 6, "{report:#?}");
877
+ assert_eq!(report.total_occurrences, 7, "{report:#?}");
878
+ assert_eq!(
879
+ report
880
+ .blind_spots
881
+ .iter()
882
+ .filter(|spot| {
883
+ spot.category == SecurityCategory::TlsBypass
884
+ && spot.reason == SecurityBlindSpotReason::AmbiguousTlsCallback
885
+ })
886
+ .count(),
887
+ 1,
888
+ "{report:#?}"
889
+ );
890
+
891
+ Ok(())
892
+ }
893
+
894
+ #[test]
895
+ fn reports_dynamic_sql_without_parameter_evidence_but_not_wrappers()
896
+ -> Result<(), Box<dyn std::error::Error>> {
897
+ let fixture = tempfile::tempdir()?;
898
+ write(&fixture, "pubspec.yaml", "name: app\n")?;
899
+ write(
900
+ &fixture,
901
+ "lib/main.dart",
902
+ r"
903
+ Future<void> query(dynamic db, String sql, List<Object?> arguments, String id) async {
904
+ await db.rawQuery(sql, arguments);
905
+ await db.rawQuery('SELECT * FROM users WHERE id = $id');
906
+ }
907
+
908
+ void log(dynamic l10n) {
909
+ print('${l10n.execute}: Shell');
910
+ }
911
+
912
+ class Schema {
913
+ static const table = 'users';
914
+ }
915
+
916
+ const topTable = 'users';
917
+
918
+ class Store {
919
+ static const table = Schema.table;
920
+
921
+ Future<void> safeQueries(dynamic db, int count, bool oldest) async {
922
+ const column = 'id';
923
+ final placeholders = List.filled(count, '?').join(',');
924
+ final aggregate = oldest ? 'MIN' : 'MAX';
925
+ await db.rawQuery(
926
+ 'SELECT $column, $aggregate(created_at) FROM $table '
927
+ 'WHERE id IN ($placeholders)',
928
+ List.filled(count, 1),
929
+ );
930
+ await db.transaction((transaction) async {
931
+ await transaction.rawQuery(
932
+ '''
933
+ SELECT id FROM $topTable
934
+ WHERE id = ?
935
+ ''',
936
+ [1],
937
+ );
938
+ });
939
+ }
940
+ }
941
+ ",
942
+ )?;
943
+
944
+ let project = scan_project(fixture.path())?;
945
+ let report = analyze_security(&project, &SecurityOptions::default(), None)?;
946
+ let sql = report
947
+ .candidates
948
+ .iter()
949
+ .find(|candidate| candidate.rule_id == "dart-decimate/security-raw-sql")
950
+ .ok_or("raw SQL candidate")?;
951
+
952
+ assert_eq!(sql.occurrences.len(), 1, "{report:#?}");
953
+ assert_eq!(sql.occurrences[0].location.line, 4);
954
+ assert!(report.blind_spots.is_empty(), "{report:#?}");
955
+
956
+ Ok(())
957
+ }
958
+
959
+ #[test]
960
+ fn detects_documented_cleartext_uri_constructors() -> Result<(), Box<dyn std::error::Error>> {
961
+ let fixture = tempfile::tempdir()?;
962
+ write(&fixture, "pubspec.yaml", "name: app\n")?;
963
+ write(
964
+ &fixture,
965
+ "lib/main.dart",
966
+ r"
967
+ final remote = Uri.http('api.example.com', '/login');
968
+ final dynamicRemote = Uri.http(authority, '/login');
969
+ final componentRemote = Uri(scheme: 'http', host: 'api.example.com');
970
+ final local = Uri.http('localhost:8080', '/health');
971
+ final secure = Uri(scheme: 'https', host: 'api.example.com');
972
+
973
+ Uri appUri(String host) =>
974
+ host.startsWith('localhost') || host.startsWith('10.')
975
+ ? Uri.http(host, '/health')
976
+ : Uri.https(host, '/health');
977
+
978
+ Uri debugUri(Uri base) {
979
+ if (kDebugMode && base.toString().startsWith('http://')) {
980
+ return Uri.http(base.authority, base.path);
981
+ }
982
+ return Uri.https(base.authority, base.path);
983
+ }
984
+ ",
985
+ )?;
986
+
987
+ let project = scan_project(fixture.path())?;
988
+ let report = analyze_security(&project, &SecurityOptions::default(), None)?;
989
+ let transport = report
990
+ .candidates
991
+ .iter()
992
+ .find(|candidate| candidate.rule_id == "dart-decimate/security-insecure-transport")
993
+ .ok_or("insecure transport candidate")?;
994
+
995
+ assert_eq!(transport.occurrences.len(), 3, "{report:#?}");
996
+
997
+ Ok(())
998
+ }
999
+
1000
+ #[test]
1001
+ fn plain_storage_uses_the_stored_value_not_metadata_names() -> Result<(), Box<dyn std::error::Error>>
1002
+ {
1003
+ let fixture = tempfile::tempdir()?;
1004
+ write(&fixture, "pubspec.yaml", "name: app\n")?;
1005
+ write(
1006
+ &fixture,
1007
+ "lib/main.dart",
1008
+ r"
1009
+ void persist(dynamic prefs, dynamic entry, dynamic credential, dynamic token) {
1010
+ prefs.setString('access_token', credential.accessToken);
1011
+ prefs.setString('token_type', AuthTokenType.headlessJwt.name);
1012
+ prefs.setString('show_token', const Uuid().v4());
1013
+ prefs.setString('access_token', token);
1014
+ entry.setString('otp', ProtectedValue.fromString(token));
1015
+ }
1016
+ ",
1017
+ )?;
1018
+
1019
+ let project = scan_project(fixture.path())?;
1020
+ let report = analyze_security(&project, &SecurityOptions::default(), None)?;
1021
+ let storage = report
1022
+ .candidates
1023
+ .iter()
1024
+ .find(|candidate| candidate.rule_id == "dart-decimate/security-plain-secret-storage")
1025
+ .ok_or("plain secret storage candidate")?;
1026
+
1027
+ assert_eq!(storage.occurrences.len(), 2, "{report:#?}");
1028
+
1029
+ Ok(())
1030
+ }
1031
+
698
1032
  fn write(fixture: &TempDir, path: &str, source: &str) -> Result<(), std::io::Error> {
699
1033
  let path = fixture.path().join(path);
700
1034
  if let Some(parent) = path.parent() {