dart-decimate 0.0.8 → 0.0.10

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.
@@ -2,7 +2,7 @@ use std::path::Path;
2
2
 
3
3
  use super::{DetectedSecurityCandidate, SecurityCategory, SecurityConfidence, SecurityOccurrence};
4
4
  use crate::Location;
5
- use crate::generated::is_generated_dart_path;
5
+ use crate::generated::{is_flutterfire_options_path, is_generated_dart_path};
6
6
 
7
7
  pub(super) fn detect_in_source(path: &Path, source: &str) -> Vec<DetectedSecurityCandidate> {
8
8
  let mut candidates = Vec::new();
@@ -24,7 +24,7 @@ pub(super) fn is_ignored_path(path: &Path) -> bool {
24
24
  }) {
25
25
  return true;
26
26
  }
27
- is_generated_dart_path(path)
27
+ is_generated_dart_path(path) && !is_flutterfire_options_path(path)
28
28
  }
29
29
 
30
30
  fn detect_hardcoded_secrets(
@@ -59,9 +59,14 @@ fn detect_hardcoded_secrets(
59
59
  } else {
60
60
  has_secret_like_name(line)
61
61
  };
62
+ let secret_binding_name = if firebase_options_literal {
63
+ secret_name
64
+ } else {
65
+ literal_secret_binding_context(source, literal.index)
66
+ };
62
67
  if is_module_uri_directive_line(line)
63
68
  || firebase_api_key_context(source, literal.index)
64
- || (!secret_value && benign_secret_named_literal(&literal.value))
69
+ || (!secret_value && benign_secret_named_literal(&literal.value, secret_binding_name))
65
70
  || (!secret_value && firebase_options_literal && !secret_name)
66
71
  || google_app_id_context(source, literal.index)
67
72
  || (!secret_value && literal_looks_like_storage_key(&literal.value))
@@ -539,6 +544,48 @@ fn firebase_secret_name_context(source: &str, index: usize) -> bool {
539
544
  literal_argument_context(source, index).is_some_and(has_secret_like_name)
540
545
  }
541
546
 
547
+ fn literal_secret_binding_context(source: &str, index: usize) -> bool {
548
+ literal_binding_identifier(source, index).is_some_and(secret_binding_identifier)
549
+ }
550
+
551
+ fn literal_binding_identifier(source: &str, index: usize) -> Option<&str> {
552
+ let context = literal_context(source, index)?;
553
+ for separator in ['=', ':'] {
554
+ let Some((candidate, rest)) = context.rsplit_once(separator) else {
555
+ continue;
556
+ };
557
+ if rest.trim().is_empty() {
558
+ return trailing_identifier(candidate);
559
+ }
560
+ }
561
+ None
562
+ }
563
+
564
+ fn secret_binding_identifier(identifier: &str) -> bool {
565
+ let lower = identifier.to_ascii_lowercase();
566
+ [
567
+ "token",
568
+ "secret",
569
+ "jwt",
570
+ "privatekey",
571
+ "private_key",
572
+ "clientsecret",
573
+ "client_secret",
574
+ "refreshtoken",
575
+ "refresh_token",
576
+ "accesstoken",
577
+ "access_token",
578
+ "bearer",
579
+ "authorization",
580
+ "apikey",
581
+ "api_key",
582
+ "signingkey",
583
+ "signing_key",
584
+ ]
585
+ .iter()
586
+ .any(|suffix| lower == *suffix || lower.ends_with(suffix))
587
+ }
588
+
542
589
  fn named_argument_context(source: &str, index: usize, name: &str) -> bool {
543
590
  let Some(context) = literal_argument_context(source, index) else {
544
591
  return false;
@@ -1026,13 +1073,16 @@ const RESET_OR_RECOVERY_PATH_MARKERS: &[&str] = &[
1026
1073
  "recover-password",
1027
1074
  ];
1028
1075
 
1029
- fn benign_secret_named_literal(value: &str) -> bool {
1076
+ fn benign_secret_named_literal(value: &str, secret_binding_name: bool) -> bool {
1030
1077
  let route_or_reset_url =
1031
1078
  literal_looks_like_route_path(value) || literal_looks_like_reset_or_recovery_url(value);
1079
+ let benign_copy = literal_looks_like_user_facing_copy(value)
1080
+ || literal_looks_like_validation_copy(value)
1081
+ || literal_looks_like_operational_copy(value);
1032
1082
  (route_or_reset_url
1033
1083
  && !literal_has_secret_like_url_parameter(value)
1034
1084
  && !literal_has_secret_like_reset_path_segment(value))
1035
- || literal_looks_like_user_facing_copy(value)
1085
+ || (benign_copy && !secret_binding_name && !literal_has_concrete_token_like_segment(value))
1036
1086
  }
1037
1087
 
1038
1088
  fn literal_looks_like_route_path(value: &str) -> bool {
@@ -1141,15 +1191,26 @@ fn literal_looks_like_user_facing_copy(value: &str) -> bool {
1141
1191
  .any(|word| lower.contains(word))
1142
1192
  && [
1143
1193
  "change password",
1194
+ "current password",
1195
+ "new password",
1144
1196
  "invalid email or password",
1145
1197
  "forgot password",
1198
+ "forgot your password",
1146
1199
  "reset password",
1200
+ "password reset",
1147
1201
  "enter password",
1148
1202
  "confirm password",
1149
1203
  "password must",
1150
1204
  "password is",
1205
+ "password should",
1206
+ "password cannot",
1207
+ "passwords do not match",
1208
+ "password do not match",
1209
+ "password field",
1210
+ "password requirements",
1151
1211
  "token expired",
1152
1212
  "invalid token",
1213
+ "cloud function error",
1153
1214
  ]
1154
1215
  .iter()
1155
1216
  .any(|phrase| lower.contains(phrase))
@@ -1158,9 +1219,81 @@ fn literal_looks_like_user_facing_copy(value: &str) -> bool {
1158
1219
  || character.is_ascii_whitespace()
1159
1220
  || matches!(
1160
1221
  character,
1161
- '.' | ',' | '!' | '?' | ':' | ';' | '\'' | '"' | '-' | '/' | '(' | ')'
1222
+ '.' | ','
1223
+ | '!'
1224
+ | '?'
1225
+ | ':'
1226
+ | ';'
1227
+ | '\''
1228
+ | '"'
1229
+ | '-'
1230
+ | '_'
1231
+ | '/'
1232
+ | '|'
1233
+ | '('
1234
+ | ')'
1235
+ )
1236
+ })
1237
+ }
1238
+
1239
+ fn literal_looks_like_validation_copy(value: &str) -> bool {
1240
+ let trimmed = value.trim();
1241
+ let lower = trimmed.to_ascii_lowercase();
1242
+ trimmed.len() <= 120
1243
+ && trimmed.contains(char::is_whitespace)
1244
+ && ((lower.contains("use at least") && lower.contains("characters"))
1245
+ || (lower.contains("reset link") && lower.contains("invalid or expired")))
1246
+ && trimmed.chars().all(|character| {
1247
+ character.is_ascii_alphanumeric()
1248
+ || character.is_ascii_whitespace()
1249
+ || matches!(
1250
+ character,
1251
+ '.' | ',' | '!' | '?' | ':' | ';' | '\'' | '"' | '-' | '_' | '/' | '|'
1252
+ )
1253
+ })
1254
+ }
1255
+
1256
+ fn literal_looks_like_operational_copy(value: &str) -> bool {
1257
+ let trimmed = value.trim();
1258
+ let lower = trimmed.to_ascii_lowercase();
1259
+ trimmed.len() <= 120
1260
+ && trimmed.contains(char::is_whitespace)
1261
+ && [
1262
+ "token issued",
1263
+ "pre-fetch token",
1264
+ "token notifications active",
1265
+ "updating password",
1266
+ ]
1267
+ .iter()
1268
+ .any(|phrase| lower.contains(phrase))
1269
+ && trimmed.chars().all(|character| !character.is_control())
1270
+ }
1271
+
1272
+ fn literal_has_concrete_token_like_segment(value: &str) -> bool {
1273
+ value
1274
+ .split(|character: char| {
1275
+ character.is_ascii_whitespace()
1276
+ || matches!(
1277
+ character,
1278
+ ':' | ';'
1279
+ | ','
1280
+ | '='
1281
+ | '&'
1282
+ | '?'
1283
+ | '#'
1284
+ | '\''
1285
+ | '"'
1286
+ | '('
1287
+ | ')'
1288
+ | '['
1289
+ | ']'
1290
+ | '{'
1291
+ | '}'
1292
+ | '<'
1293
+ | '>'
1162
1294
  )
1163
1295
  })
1296
+ .any(concrete_secret_like_path_segment)
1164
1297
  }
1165
1298
 
1166
1299
  fn has_secret_shape(value: &str) -> bool {
@@ -1178,6 +1311,7 @@ fn has_secret_shape(value: &str) -> bool {
1178
1311
  fn jwt_like(value: &str) -> bool {
1179
1312
  let parts = value.split('.').collect::<Vec<_>>();
1180
1313
  parts.len() == 3
1314
+ && parts[0].starts_with("eyJ")
1181
1315
  && parts
1182
1316
  .iter()
1183
1317
  .all(|part| part.len() >= 10 && is_base64ish(part))
@@ -121,6 +121,13 @@ class Routes {
121
121
  class Copy {
122
122
  String get settingsSecurityChangePassword => 'Change Password';
123
123
  static const String invalidCredentials = 'Invalid email or password';
124
+ static const String passwordsDoNotMatch = 'Passwords do not match';
125
+ static const String passwordTooShort = 'Use at least 8 characters';
126
+ static const String cloudFunctionSubject = 'Jabal Sina Cloud Function Error | token_notifications';
127
+ static const String pingResponse = 'Pong - Token Notifications Active';
128
+ static const String tokenTitle = '🎫 Token Issued';
129
+ static const String requestTokenOperation = 'Pre-fetch token';
130
+ static const String updatingPassword = 'Updating password...';
124
131
  }
125
132
  ",
126
133
  )?;
@@ -134,6 +141,95 @@ class Copy {
134
141
  Ok(())
135
142
  }
136
143
 
144
+ #[test]
145
+ fn reports_operational_copy_with_concrete_token_segments() -> Result<(), Box<dyn std::error::Error>>
146
+ {
147
+ let fixture = tempfile::tempdir()?;
148
+ write(&fixture, "pubspec.yaml", "name: app\n")?;
149
+ write(
150
+ &fixture,
151
+ "lib/main.dart",
152
+ "class Session {
153
+ static const String accessToken = 'Token issued: abc123abc123';
154
+ static const String operationMessage = 'Pre-fetch token abc123abc123';
155
+ }
156
+ ",
157
+ )?;
158
+
159
+ let project = scan_project(fixture.path())?;
160
+ let report = analyze_security(&project, &SecurityOptions::default(), None)?;
161
+
162
+ assert_eq!(report.total_occurrences, 2);
163
+ assert_eq!(
164
+ report.candidates[0].rule_id,
165
+ "dart-decimate/security-hardcoded-secret"
166
+ );
167
+ assert_eq!(report.candidates[0].occurrences.len(), 2);
168
+
169
+ Ok(())
170
+ }
171
+
172
+ #[test]
173
+ fn reports_user_copy_with_secret_bindings_or_token_segments()
174
+ -> Result<(), Box<dyn std::error::Error>> {
175
+ let fixture = tempfile::tempdir()?;
176
+ write(&fixture, "pubspec.yaml", "name: app\n")?;
177
+ write(
178
+ &fixture,
179
+ "lib/main.dart",
180
+ "class Session {
181
+ static const String accessToken = 'Invalid token abc123abc123';
182
+ static const String resetToken = 'Reset link invalid or expired abc123abc123';
183
+ }
184
+ ",
185
+ )?;
186
+
187
+ let project = scan_project(fixture.path())?;
188
+ let report = analyze_security(&project, &SecurityOptions::default(), None)?;
189
+
190
+ assert_eq!(report.total_occurrences, 2);
191
+ assert_eq!(
192
+ report.candidates[0].rule_id,
193
+ "dart-decimate/security-hardcoded-secret"
194
+ );
195
+ assert_eq!(report.candidates[0].occurrences.len(), 2);
196
+
197
+ Ok(())
198
+ }
199
+
200
+ #[test]
201
+ fn skips_dot_qualified_diagnostic_identifiers_but_reports_jwts()
202
+ -> Result<(), Box<dyn std::error::Error>> {
203
+ let fixture = tempfile::tempdir()?;
204
+ write(&fixture, "pubspec.yaml", "name: app\n")?;
205
+ write(
206
+ &fixture,
207
+ "lib/main.dart",
208
+ "class Crash {
209
+ static void error(Object error, StackTrace stackTrace, {required String reason}) {}
210
+ }
211
+
212
+ void report(Object error, StackTrace stackTrace) {
213
+ Crash.error(error, stackTrace, reason: 'ActiveWorkoutNotifier.saveActiveWorkout.squadCheckIn');
214
+ }
215
+
216
+ const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
217
+ ",
218
+ )?;
219
+
220
+ let project = scan_project(fixture.path())?;
221
+ let report = analyze_security(&project, &SecurityOptions::default(), None)?;
222
+
223
+ assert_eq!(report.total_occurrences, 1);
224
+ assert_eq!(
225
+ report.candidates[0].rule_id,
226
+ "dart-decimate/security-hardcoded-secret"
227
+ );
228
+ assert_eq!(report.candidates[0].occurrences[0].location.line, 9);
229
+
230
+ Ok(())
231
+ }
232
+
137
233
  #[test]
138
234
  fn reports_secret_named_urls_with_concrete_secret_parameters()
139
235
  -> Result<(), Box<dyn std::error::Error>> {
package/src/trace.rs CHANGED
@@ -105,7 +105,7 @@ pub struct DependencyTraceReport {
105
105
  pub type_only_importers: Vec<TraceDependencyDirective>,
106
106
  /// Number of Dart import/export directives referencing the package.
107
107
  pub total_import_count: usize,
108
- /// Whether non-Dart scripts reference the package. Not scanned yet.
108
+ /// Whether non-Dart tooling files reference the package.
109
109
  pub used_in_scripts: bool,
110
110
  /// Whether Dart source references the package in import/export directives.
111
111
  pub is_used: bool,