dart-decimate 0.0.28 → 0.0.30
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.
- package/Cargo.lock +1 -1
- package/Cargo.toml +1 -1
- package/README.md +36 -60
- package/npm/bin/runner.js +26 -14
- package/npm/scripts/postinstall.js +89 -63
- package/package.json +6 -5
- package/src/baseline.rs +38 -0
- package/src/cli/health_args.rs +36 -7
- package/src/cli/html_open.rs +4 -0
- package/src/cli/issue_filter_args.rs +1 -0
- package/src/cli/security_summary_run.rs +1 -0
- package/src/config/health.rs +22 -2
- package/src/config/rule_aliases.rs +43 -0
- package/src/config/rules.rs +46 -1
- package/src/config.rs +2 -1
- package/src/dart_parser/test_support.rs +51 -0
- package/src/dart_parser.rs +8 -0
- package/src/dependencies/analyze.rs +3 -1
- package/src/dependencies/tests.rs +111 -7
- package/src/dependencies/usage.rs +5 -1
- package/src/dependencies.rs +7 -3
- package/src/explain/flutter_style.rs +43 -0
- package/src/explain/misc.rs +72 -0
- package/src/explain.rs +23 -67
- package/src/flutter_style/scanner.rs +883 -0
- package/src/flutter_style/types.rs +90 -0
- package/src/flutter_style/usage.rs +349 -0
- package/src/flutter_style.rs +72 -0
- package/src/generated.rs +154 -0
- package/src/health/large_units.rs +49 -0
- package/src/health/tests.rs +212 -1
- package/src/health/threshold_types.rs +31 -1
- package/src/health/thresholds.rs +49 -0
- package/src/health/types.rs +35 -0
- package/src/health.rs +72 -6
- package/src/inspect.rs +8 -0
- package/src/lib.rs +17 -5
- package/src/manifest.rs +7 -3
- package/src/output/dependency_findings.rs +14 -1
- package/src/output/flutter_style.rs +189 -0
- package/src/output/health_findings.rs +93 -10
- package/src/output/health_inventory.rs +121 -0
- package/src/output/html/tests.rs +20 -0
- package/src/output/html.rs +10 -1
- package/src/output/human.rs +85 -1
- package/src/output/human_details.rs +93 -12
- package/src/output/scope.rs +62 -2
- package/src/output/security_findings.rs +101 -76
- package/src/output/security_sarif.rs +24 -13
- package/src/output/suppressions.rs +4 -0
- package/src/output/types.rs +38 -2
- package/src/output/verdict.rs +12 -0
- package/src/output.rs +77 -74
- package/src/report_schema/inventory.rs +268 -4
- package/src/report_schema.rs +94 -60
- package/src/security/catalogue.rs +103 -0
- package/src/security/detect/weak_randomness.rs +762 -0
- package/src/security/detect.rs +1535 -221
- package/src/security/security_matchers.toml +172 -0
- package/src/security/tests.rs +336 -2
- package/src/security.rs +292 -56
- package/src/security_gate.rs +28 -0
- package/src/semantic.rs +276 -0
- package/src/symbols/semantic_evidence.rs +342 -0
- package/src/symbols.rs +20 -10
- package/src/trace/rendering.rs +54 -0
- package/src/trace/semantic.rs +126 -0
- package/src/trace.rs +54 -62
- package/src/widgets/inheritance.rs +63 -0
- package/src/widgets.rs +33 -3
package/src/security.rs
CHANGED
|
@@ -2,13 +2,19 @@ use std::collections::{BTreeMap, BTreeSet};
|
|
|
2
2
|
use std::fs;
|
|
3
3
|
use std::path::PathBuf;
|
|
4
4
|
|
|
5
|
+
use rayon::prelude::*;
|
|
5
6
|
use serde::{Deserialize, Serialize};
|
|
6
7
|
use thiserror::Error;
|
|
7
8
|
|
|
8
9
|
use crate::graph::normalize_against;
|
|
9
|
-
use crate::{
|
|
10
|
+
use crate::{
|
|
11
|
+
DartCombinatorKind, DartImport, DeadCodeReport, DependencyKind, Location, ScannedProject,
|
|
12
|
+
};
|
|
10
13
|
|
|
14
|
+
mod catalogue;
|
|
11
15
|
mod detect;
|
|
16
|
+
use catalogue::MatcherCatalogue;
|
|
17
|
+
pub use catalogue::SecurityDefaultSeverity;
|
|
12
18
|
use detect::{detect_in_source, is_ignored_path};
|
|
13
19
|
|
|
14
20
|
/// Security candidate detector options.
|
|
@@ -33,6 +39,8 @@ pub struct SecurityReport {
|
|
|
33
39
|
pub candidates: Vec<SecurityCandidate>,
|
|
34
40
|
/// Raw security candidate occurrence count before `--top` truncation.
|
|
35
41
|
pub total_occurrences: usize,
|
|
42
|
+
/// Bounded cases where a sink-shaped expression could not be verified.
|
|
43
|
+
pub blind_spots: Vec<SecurityBlindSpot>,
|
|
36
44
|
/// Optional attack-surface inventory.
|
|
37
45
|
pub attack_surface: Vec<AttackSurfaceEntry>,
|
|
38
46
|
}
|
|
@@ -48,6 +56,20 @@ pub struct SecurityCandidate {
|
|
|
48
56
|
pub sink: String,
|
|
49
57
|
/// Detection confidence.
|
|
50
58
|
pub confidence: SecurityConfidence,
|
|
59
|
+
/// CWE ids owned by the embedded matcher catalogue.
|
|
60
|
+
pub cwe: Vec<String>,
|
|
61
|
+
/// Risk effect owned by the embedded matcher catalogue.
|
|
62
|
+
pub effect: String,
|
|
63
|
+
/// Evidence expectation owned by the embedded matcher catalogue.
|
|
64
|
+
pub evidence_template: String,
|
|
65
|
+
/// Evidence source family.
|
|
66
|
+
pub source: String,
|
|
67
|
+
/// Trust or platform boundary involved.
|
|
68
|
+
pub boundary: String,
|
|
69
|
+
/// Trace role for serialized evidence.
|
|
70
|
+
pub trace_role: String,
|
|
71
|
+
/// Default severity before rule overrides.
|
|
72
|
+
pub default_severity: SecurityDefaultSeverity,
|
|
51
73
|
/// Candidate occurrences.
|
|
52
74
|
pub occurrences: Vec<SecurityOccurrence>,
|
|
53
75
|
}
|
|
@@ -72,21 +94,22 @@ pub enum SecurityCategory {
|
|
|
72
94
|
RawSql,
|
|
73
95
|
/// Secret-like material written to plain local storage.
|
|
74
96
|
PlainSecretStorage,
|
|
97
|
+
/// Predictable `dart:math Random()` output used as security material.
|
|
98
|
+
WeakRandomness,
|
|
75
99
|
}
|
|
76
100
|
|
|
77
101
|
impl SecurityCategory {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
102
|
+
const ALL: [Self; 9] = [
|
|
103
|
+
Self::HardcodedSecret,
|
|
104
|
+
Self::FirebaseApiKey,
|
|
105
|
+
Self::InsecureTransport,
|
|
106
|
+
Self::TlsBypass,
|
|
107
|
+
Self::WebViewRisk,
|
|
108
|
+
Self::ProcessExecution,
|
|
109
|
+
Self::RawSql,
|
|
110
|
+
Self::PlainSecretStorage,
|
|
111
|
+
Self::WeakRandomness,
|
|
112
|
+
];
|
|
90
113
|
}
|
|
91
114
|
|
|
92
115
|
impl SecurityOptions {
|
|
@@ -122,6 +145,39 @@ pub struct SecurityOccurrence {
|
|
|
122
145
|
pub reachability: Option<SecurityReachability>,
|
|
123
146
|
}
|
|
124
147
|
|
|
148
|
+
/// Why a sink-shaped expression could not be verified by the bounded analyzer.
|
|
149
|
+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
|
150
|
+
#[serde(rename_all = "kebab-case")]
|
|
151
|
+
pub enum SecurityBlindSpotReason {
|
|
152
|
+
/// A value was assigned through an intermediate identifier.
|
|
153
|
+
UnflattenedRandomFlow,
|
|
154
|
+
/// A Random-shaped constructor could not be attributed to `dart:math`.
|
|
155
|
+
AmbiguousRandomProvenance,
|
|
156
|
+
/// A sink-shaped call could not be flattened into a complete argument list.
|
|
157
|
+
UnflattenedCall,
|
|
158
|
+
/// A sink-shaped call could not be attributed to its declaring library.
|
|
159
|
+
AmbiguousCallProvenance,
|
|
160
|
+
/// A TLS validation callback assignment could not be resolved locally.
|
|
161
|
+
AmbiguousTlsCallback,
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/// One bounded security-analysis blind spot.
|
|
165
|
+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
166
|
+
pub struct SecurityBlindSpot {
|
|
167
|
+
/// Candidate category whose verification was incomplete.
|
|
168
|
+
pub category: SecurityCategory,
|
|
169
|
+
/// Dart file path.
|
|
170
|
+
pub path: PathBuf,
|
|
171
|
+
/// Location of the ambiguous expression.
|
|
172
|
+
pub location: Location,
|
|
173
|
+
/// Sink or context family.
|
|
174
|
+
pub sink: String,
|
|
175
|
+
/// Stable bounded omission reason.
|
|
176
|
+
pub reason: SecurityBlindSpotReason,
|
|
177
|
+
/// Redacted source-line evidence.
|
|
178
|
+
pub evidence: String,
|
|
179
|
+
}
|
|
180
|
+
|
|
125
181
|
/// Module-level security reachability context.
|
|
126
182
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
127
183
|
pub struct SecurityReachability {
|
|
@@ -167,6 +223,12 @@ pub enum SecurityError {
|
|
|
167
223
|
/// Underlying IO error.
|
|
168
224
|
source: std::io::Error,
|
|
169
225
|
},
|
|
226
|
+
/// The embedded matcher catalogue was not valid TOML.
|
|
227
|
+
#[error("invalid embedded security matcher catalogue: {0}")]
|
|
228
|
+
MatcherCatalogue(toml::de::Error),
|
|
229
|
+
/// The embedded matcher catalogue violated its internal contract.
|
|
230
|
+
#[error("invalid embedded security matcher catalogue: {0}")]
|
|
231
|
+
InvalidMatcherCatalogue(String),
|
|
170
232
|
}
|
|
171
233
|
|
|
172
234
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
@@ -175,6 +237,13 @@ struct CandidateGroup {
|
|
|
175
237
|
category: SecurityCategory,
|
|
176
238
|
sink: String,
|
|
177
239
|
confidence: SecurityConfidence,
|
|
240
|
+
cwe: Vec<String>,
|
|
241
|
+
effect: String,
|
|
242
|
+
evidence_template: String,
|
|
243
|
+
source: String,
|
|
244
|
+
boundary: String,
|
|
245
|
+
trace_role: String,
|
|
246
|
+
default_severity: SecurityDefaultSeverity,
|
|
178
247
|
occurrences: Vec<SecurityOccurrence>,
|
|
179
248
|
}
|
|
180
249
|
|
|
@@ -186,6 +255,29 @@ struct DetectedSecurityCandidate {
|
|
|
186
255
|
occurrence: SecurityOccurrence,
|
|
187
256
|
}
|
|
188
257
|
|
|
258
|
+
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
|
259
|
+
struct DetectionResult {
|
|
260
|
+
candidates: Vec<DetectedSecurityCandidate>,
|
|
261
|
+
blind_spots: Vec<SecurityBlindSpot>,
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
|
265
|
+
struct LibraryImportContext {
|
|
266
|
+
visible_types: BTreeSet<(String, String, Option<String>)>,
|
|
267
|
+
declared_names: BTreeSet<String>,
|
|
268
|
+
import_prefixes: BTreeSet<String>,
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
impl LibraryImportContext {
|
|
272
|
+
fn exposes(&self, uri: &str, type_name: &str, prefix: Option<&str>) -> bool {
|
|
273
|
+
self.visible_types.contains(&(
|
|
274
|
+
uri.to_owned(),
|
|
275
|
+
type_name.to_owned(),
|
|
276
|
+
prefix.map(str::to_owned),
|
|
277
|
+
))
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
189
281
|
/// Detect unverified local security review candidates in Dart and Flutter code.
|
|
190
282
|
///
|
|
191
283
|
/// # Errors
|
|
@@ -196,21 +288,43 @@ pub fn analyze_security(
|
|
|
196
288
|
options: &SecurityOptions,
|
|
197
289
|
dead_code: Option<&DeadCodeReport>,
|
|
198
290
|
) -> Result<SecurityReport, SecurityError> {
|
|
291
|
+
let catalogue = MatcherCatalogue::parse()?;
|
|
199
292
|
let mut groups = BTreeMap::<(SecurityCategory, String), CandidateGroup>::new();
|
|
200
|
-
let mut
|
|
293
|
+
let mut blind_spots = Vec::new();
|
|
201
294
|
let reachability = dead_code.map(SecurityReachabilityContext::from);
|
|
295
|
+
let library_imports = library_import_contexts(project);
|
|
202
296
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
297
|
+
let mut detected_files = project
|
|
298
|
+
.files
|
|
299
|
+
.par_iter()
|
|
300
|
+
.filter_map(|file| {
|
|
301
|
+
let path = normalize_against(&project.root, &file.path);
|
|
302
|
+
if !path.starts_with(&project.root) || is_ignored_path(&path) {
|
|
303
|
+
return None;
|
|
304
|
+
}
|
|
305
|
+
let inherited_imports = library_imports.get(&path);
|
|
306
|
+
let detected = fs::read_to_string(&path)
|
|
307
|
+
.map(|source| detect_in_source(&path, &source, &catalogue, inherited_imports))
|
|
308
|
+
.map_err(|source| SecurityError::ReadFile {
|
|
309
|
+
path: path.clone(),
|
|
310
|
+
source,
|
|
311
|
+
});
|
|
312
|
+
Some((path, detected))
|
|
313
|
+
})
|
|
314
|
+
.collect::<Vec<_>>();
|
|
315
|
+
detected_files.sort_by(|left, right| left.0.cmp(&right.0));
|
|
316
|
+
let analyzed_files = detected_files.len();
|
|
317
|
+
|
|
318
|
+
for (_, detected) in detected_files {
|
|
319
|
+
let detected = detected?;
|
|
320
|
+
blind_spots.extend(
|
|
321
|
+
detected
|
|
322
|
+
.blind_spots
|
|
323
|
+
.into_iter()
|
|
324
|
+
.filter(|blind_spot| options.includes_category(blind_spot.category)),
|
|
325
|
+
);
|
|
326
|
+
for detected in detected
|
|
327
|
+
.candidates
|
|
214
328
|
.into_iter()
|
|
215
329
|
.filter(|candidate| options.includes_category(candidate.category))
|
|
216
330
|
{
|
|
@@ -219,11 +333,19 @@ pub fn analyze_security(
|
|
|
219
333
|
.as_ref()
|
|
220
334
|
.and_then(|context| context.reachability_for(&detected.occurrence.path));
|
|
221
335
|
let key = (detected.category, detected.sink.clone());
|
|
336
|
+
let matcher = catalogue.matcher(detected.category);
|
|
222
337
|
let group = groups.entry(key).or_insert_with(|| CandidateGroup {
|
|
223
|
-
rule_id:
|
|
338
|
+
rule_id: matcher.rule_id.clone(),
|
|
224
339
|
category: detected.category,
|
|
225
340
|
sink: detected.sink.clone(),
|
|
226
341
|
confidence: detected.confidence,
|
|
342
|
+
cwe: matcher.cwe.clone(),
|
|
343
|
+
effect: matcher.effect.clone(),
|
|
344
|
+
evidence_template: matcher.evidence_template.clone(),
|
|
345
|
+
source: matcher.source.clone(),
|
|
346
|
+
boundary: matcher.boundary.clone(),
|
|
347
|
+
trace_role: matcher.trace_role.clone(),
|
|
348
|
+
default_severity: matcher.default_severity,
|
|
227
349
|
occurrences: Vec::new(),
|
|
228
350
|
});
|
|
229
351
|
group.confidence = group.confidence.max(detected.confidence);
|
|
@@ -254,8 +376,9 @@ pub fn analyze_security(
|
|
|
254
376
|
if let Some(top) = options.top {
|
|
255
377
|
candidates.truncate(top);
|
|
256
378
|
}
|
|
379
|
+
deduplicate_blind_spots(&mut blind_spots);
|
|
257
380
|
let attack_surface = if options.surface {
|
|
258
|
-
attack_surface_for(&candidates)
|
|
381
|
+
attack_surface_for(&candidates, &catalogue)
|
|
259
382
|
} else {
|
|
260
383
|
Vec::new()
|
|
261
384
|
};
|
|
@@ -265,10 +388,111 @@ pub fn analyze_security(
|
|
|
265
388
|
analyzed_files,
|
|
266
389
|
candidates,
|
|
267
390
|
total_occurrences,
|
|
391
|
+
blind_spots,
|
|
268
392
|
attack_surface,
|
|
269
393
|
})
|
|
270
394
|
}
|
|
271
395
|
|
|
396
|
+
fn library_import_contexts(project: &ScannedProject) -> BTreeMap<PathBuf, LibraryImportContext> {
|
|
397
|
+
let files = project
|
|
398
|
+
.files
|
|
399
|
+
.iter()
|
|
400
|
+
.map(|file| (normalize_against(&project.root, &file.path), file))
|
|
401
|
+
.collect::<BTreeMap<_, _>>();
|
|
402
|
+
let mut parts_by_library = BTreeMap::<PathBuf, Vec<PathBuf>>::new();
|
|
403
|
+
let mut libraries_by_part = BTreeMap::<PathBuf, Vec<PathBuf>>::new();
|
|
404
|
+
for dependency in project
|
|
405
|
+
.graph
|
|
406
|
+
.dependencies()
|
|
407
|
+
.into_iter()
|
|
408
|
+
.filter(|dependency| dependency.kind == DependencyKind::Part)
|
|
409
|
+
{
|
|
410
|
+
parts_by_library
|
|
411
|
+
.entry(dependency.from_path.clone())
|
|
412
|
+
.or_default()
|
|
413
|
+
.push(dependency.to_path.clone());
|
|
414
|
+
libraries_by_part
|
|
415
|
+
.entry(dependency.to_path)
|
|
416
|
+
.or_default()
|
|
417
|
+
.push(dependency.from_path);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
let mut contexts = BTreeMap::new();
|
|
421
|
+
for (library, mut parts) in parts_by_library {
|
|
422
|
+
parts.sort();
|
|
423
|
+
parts.dedup();
|
|
424
|
+
let Some(owner) = files.get(&library) else {
|
|
425
|
+
continue;
|
|
426
|
+
};
|
|
427
|
+
if owner.parts.len() != parts.len()
|
|
428
|
+
|| parts.iter().any(|part| {
|
|
429
|
+
let mut libraries = libraries_by_part.get(part).cloned().unwrap_or_default();
|
|
430
|
+
libraries.sort();
|
|
431
|
+
libraries.dedup();
|
|
432
|
+
libraries.as_slice() != [library.clone()]
|
|
433
|
+
})
|
|
434
|
+
{
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
let mut context = LibraryImportContext::default();
|
|
438
|
+
for import in owner
|
|
439
|
+
.imports
|
|
440
|
+
.iter()
|
|
441
|
+
.filter(|import| import.condition.is_none())
|
|
442
|
+
{
|
|
443
|
+
record_security_import(&mut context, import);
|
|
444
|
+
}
|
|
445
|
+
for path in std::iter::once(&library).chain(parts.iter()) {
|
|
446
|
+
let Some(file) = files.get(path) else {
|
|
447
|
+
continue;
|
|
448
|
+
};
|
|
449
|
+
context.declared_names.extend(
|
|
450
|
+
file.declarations
|
|
451
|
+
.iter()
|
|
452
|
+
.map(|declaration| declaration.name.clone()),
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
contexts.insert(library, context.clone());
|
|
456
|
+
for part in parts {
|
|
457
|
+
contexts.insert(part, context.clone());
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
contexts
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
fn record_security_import(context: &mut LibraryImportContext, import: &DartImport) {
|
|
464
|
+
if let Some(prefix) = &import.prefix {
|
|
465
|
+
context.import_prefixes.insert(prefix.clone());
|
|
466
|
+
}
|
|
467
|
+
let type_names: &[&str] = match import.uri.as_str() {
|
|
468
|
+
"dart:io" => &["Platform", "Process"],
|
|
469
|
+
"package:process/process.dart" => &["LocalProcessManager", "ProcessManager"],
|
|
470
|
+
_ => return,
|
|
471
|
+
};
|
|
472
|
+
for type_name in type_names {
|
|
473
|
+
if extracted_import_exposes_name(import, type_name) {
|
|
474
|
+
context.visible_types.insert((
|
|
475
|
+
import.uri.clone(),
|
|
476
|
+
(*type_name).to_owned(),
|
|
477
|
+
import.prefix.clone(),
|
|
478
|
+
));
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
fn extracted_import_exposes_name(import: &DartImport, name: &str) -> bool {
|
|
484
|
+
let mut visible = true;
|
|
485
|
+
for combinator in &import.combinators {
|
|
486
|
+
let contains_name = combinator.names.iter().any(|candidate| candidate == name);
|
|
487
|
+
match combinator.kind {
|
|
488
|
+
DartCombinatorKind::Show => visible = contains_name,
|
|
489
|
+
DartCombinatorKind::Hide if contains_name => visible = false,
|
|
490
|
+
DartCombinatorKind::Hide => {}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
visible
|
|
494
|
+
}
|
|
495
|
+
|
|
272
496
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
273
497
|
struct SecurityReachabilityContext {
|
|
274
498
|
reachable_files: BTreeSet<PathBuf>,
|
|
@@ -323,12 +547,22 @@ impl From<CandidateGroup> for SecurityCandidate {
|
|
|
323
547
|
category: group.category,
|
|
324
548
|
sink: group.sink,
|
|
325
549
|
confidence: group.confidence,
|
|
550
|
+
cwe: group.cwe,
|
|
551
|
+
effect: group.effect,
|
|
552
|
+
evidence_template: group.evidence_template,
|
|
553
|
+
source: group.source,
|
|
554
|
+
boundary: group.boundary,
|
|
555
|
+
trace_role: group.trace_role,
|
|
556
|
+
default_severity: group.default_severity,
|
|
326
557
|
occurrences,
|
|
327
558
|
}
|
|
328
559
|
}
|
|
329
560
|
}
|
|
330
561
|
|
|
331
|
-
fn attack_surface_for(
|
|
562
|
+
fn attack_surface_for(
|
|
563
|
+
candidates: &[SecurityCandidate],
|
|
564
|
+
catalogue: &MatcherCatalogue,
|
|
565
|
+
) -> Vec<AttackSurfaceEntry> {
|
|
332
566
|
candidates
|
|
333
567
|
.iter()
|
|
334
568
|
.flat_map(|candidate| {
|
|
@@ -340,39 +574,41 @@ fn attack_surface_for(candidates: &[SecurityCandidate]) -> Vec<AttackSurfaceEntr
|
|
|
340
574
|
path: occurrence.path.clone(),
|
|
341
575
|
location: occurrence.location,
|
|
342
576
|
surface: candidate.sink.clone(),
|
|
343
|
-
verification_prompt:
|
|
577
|
+
verification_prompt: catalogue
|
|
578
|
+
.matcher(candidate.category)
|
|
579
|
+
.verification_prompt
|
|
580
|
+
.clone(),
|
|
344
581
|
})
|
|
345
582
|
})
|
|
346
583
|
.collect()
|
|
347
584
|
}
|
|
348
585
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
}
|
|
586
|
+
fn deduplicate_blind_spots(blind_spots: &mut Vec<SecurityBlindSpot>) {
|
|
587
|
+
blind_spots.sort_by(|left, right| {
|
|
588
|
+
(
|
|
589
|
+
&left.path,
|
|
590
|
+
left.location.line,
|
|
591
|
+
left.location.column,
|
|
592
|
+
left.category,
|
|
593
|
+
left.reason,
|
|
594
|
+
&left.sink,
|
|
595
|
+
)
|
|
596
|
+
.cmp(&(
|
|
597
|
+
&right.path,
|
|
598
|
+
right.location.line,
|
|
599
|
+
right.location.column,
|
|
600
|
+
right.category,
|
|
601
|
+
right.reason,
|
|
602
|
+
&right.sink,
|
|
603
|
+
))
|
|
604
|
+
});
|
|
605
|
+
blind_spots.dedup_by(|left, right| {
|
|
606
|
+
left.path == right.path
|
|
607
|
+
&& left.location == right.location
|
|
608
|
+
&& left.category == right.category
|
|
609
|
+
&& left.reason == right.reason
|
|
610
|
+
&& left.sink == right.sink
|
|
611
|
+
});
|
|
376
612
|
}
|
|
377
613
|
|
|
378
614
|
#[cfg(test)]
|
package/src/security_gate.rs
CHANGED
|
@@ -187,6 +187,9 @@ where
|
|
|
187
187
|
);
|
|
188
188
|
true
|
|
189
189
|
});
|
|
190
|
+
report
|
|
191
|
+
.security_blind_spots
|
|
192
|
+
.retain(|blind_spot| keep(&blind_spot.path, blind_spot.line));
|
|
190
193
|
report
|
|
191
194
|
.attack_surface
|
|
192
195
|
.retain(|entry| keep(&entry.path, entry.line));
|
|
@@ -404,6 +407,8 @@ fn recompute_summary(report: &mut JsonReport) {
|
|
|
404
407
|
report.summary.part_of_violations = kind_count(report, FindingKind::PartOfViolation);
|
|
405
408
|
report.summary.unused_dependencies = dependency_count(report);
|
|
406
409
|
report.summary.unused_dev_dependencies = kind_count(report, FindingKind::UnusedDevDependency);
|
|
410
|
+
report.summary.dev_dependencies_in_production =
|
|
411
|
+
kind_count(report, FindingKind::DevDependencyInProduction);
|
|
407
412
|
report.summary.test_only_dependencies = kind_count(report, FindingKind::TestOnlyDependency);
|
|
408
413
|
report.summary.dependency_overrides = kind_count(report, FindingKind::UnusedDependencyOverride)
|
|
409
414
|
+ kind_count(report, FindingKind::MisconfiguredDependencyOverride);
|
|
@@ -431,6 +436,19 @@ fn recompute_summary(report: &mut JsonReport) {
|
|
|
431
436
|
kind_count(report, FindingKind::MissingContextMountedAfterAwait);
|
|
432
437
|
report.summary.code_duplications = report.clone_groups.len();
|
|
433
438
|
report.summary.complex_functions = complexity_count(report);
|
|
439
|
+
report.summary.large_functions = report.large_functions.len();
|
|
440
|
+
report.summary.raw_flutter_style_values = style_count(report, "raw-flutter-style-value");
|
|
441
|
+
report.summary.near_duplicate_theme_tokens = style_count(report, "near-duplicate-theme-token");
|
|
442
|
+
report.summary.unused_theme_extension_tokens =
|
|
443
|
+
style_count(report, "unused-theme-extension-token");
|
|
444
|
+
report.summary.semantic_evidence = report
|
|
445
|
+
.semantic
|
|
446
|
+
.as_ref()
|
|
447
|
+
.map_or(0, |semantic| semantic.evidence.len());
|
|
448
|
+
report.summary.type_couplings = report
|
|
449
|
+
.semantic
|
|
450
|
+
.as_ref()
|
|
451
|
+
.map_or(0, |semantic| semantic.type_couplings.len());
|
|
434
452
|
report.summary.coverage_gaps = kind_count(report, FindingKind::CoverageGap);
|
|
435
453
|
report.summary.crap_functions = kind_count(report, FindingKind::HighCrapScore);
|
|
436
454
|
report.summary.file_scores = report.file_scores.len();
|
|
@@ -448,6 +466,7 @@ fn recompute_summary(report: &mut JsonReport) {
|
|
|
448
466
|
.iter()
|
|
449
467
|
.map(|candidate| candidate.occurrences.len())
|
|
450
468
|
.sum();
|
|
469
|
+
report.summary.security_blind_spots = report.security_blind_spots.len();
|
|
451
470
|
report.summary.attack_surface = report.attack_surface.len();
|
|
452
471
|
report.summary.missing_entry_points = kind_count(report, FindingKind::MissingEntryPoint);
|
|
453
472
|
report.summary.cycles = kind_count(report, FindingKind::CircularDependency);
|
|
@@ -471,6 +490,14 @@ fn recompute_summary(report: &mut JsonReport) {
|
|
|
471
490
|
};
|
|
472
491
|
}
|
|
473
492
|
|
|
493
|
+
fn style_count(report: &JsonReport, kind: &str) -> usize {
|
|
494
|
+
report
|
|
495
|
+
.flutter_style
|
|
496
|
+
.iter()
|
|
497
|
+
.filter(|finding| finding.kind == kind)
|
|
498
|
+
.count()
|
|
499
|
+
}
|
|
500
|
+
|
|
474
501
|
fn kind_count(report: &JsonReport, kind: FindingKind) -> usize {
|
|
475
502
|
report
|
|
476
503
|
.findings
|
|
@@ -488,6 +515,7 @@ fn dependency_count(report: &JsonReport) -> usize {
|
|
|
488
515
|
finding.kind,
|
|
489
516
|
FindingKind::UnusedDependency
|
|
490
517
|
| FindingKind::UnusedDevDependency
|
|
518
|
+
| FindingKind::DevDependencyInProduction
|
|
491
519
|
| FindingKind::TestOnlyDependency
|
|
492
520
|
| FindingKind::UnusedDependencyOverride
|
|
493
521
|
)
|