dart-decimate 0.0.77 → 0.0.78
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 +8 -8
- package/package.json +2 -2
- package/src/boundaries.rs +1 -9
- package/src/cli/analyze.rs +33 -3
- package/src/cli/error.rs +16 -0
- package/src/cli/list_run.rs +3 -1
- package/src/cli/scope_args.rs +14 -3
- package/src/config.rs +12 -8
- package/src/dart_parser.rs +100 -9
- package/src/dependencies/analyze.rs +4 -3
- package/src/dependencies/discovery.rs +10 -2
- package/src/dependencies/flutter_usage.rs +4 -0
- package/src/dependencies/tests.rs +5 -5
- package/src/dependencies/usage.rs +0 -9
- package/src/dependencies.rs +12 -7
- package/src/dupes/declarations.rs +1 -2
- package/src/dupes.rs +1 -10
- package/src/explain/misc.rs +1 -1
- package/src/explain.rs +1 -1
- package/src/extract/members.rs +24 -15
- package/src/extract/tests.rs +89 -0
- package/src/extract.rs +51 -15
- package/src/graph.rs +9 -0
- package/src/lib.rs +3 -2
- package/src/output/duplication_findings.rs +1 -2
- package/src/output/human.rs +7 -2
- package/src/output/human_details.rs +6 -0
- package/src/output/next_steps.rs +111 -0
- package/src/output/route_cycle/aliases.rs +1 -2
- package/src/output/route_cycle/wrappers.rs +1 -2
- package/src/output/types.rs +2 -0
- package/src/output.rs +27 -5
- package/src/outside/loader.rs +133 -0
- package/src/outside/loader_tests.rs +136 -0
- package/src/outside/resolver.rs +484 -0
- package/src/outside/tests.rs +242 -0
- package/src/outside.rs +186 -0
- package/src/package_map.rs +30 -1
- package/src/report_schema.rs +1 -0
- package/src/routes.rs +2 -0
- package/src/scan.rs +24 -3
- package/src/security/detect/process_arguments.rs +106 -0
- package/src/security/detect.rs +98 -40
- package/src/symbols/extensions.rs +42 -27
- package/src/symbols/path_filters.rs +10 -1
- package/src/symbols/tests.rs +15 -0
- package/src/symbols.rs +489 -67
- package/src/trace.rs +6 -5
- package/src/widgets/reads.rs +4 -8
- package/src/widgets/resolution.rs +63 -10
- package/src/workspace_scope.rs +1 -10
package/src/security/detect.rs
CHANGED
|
@@ -3,6 +3,7 @@ use std::path::Path;
|
|
|
3
3
|
|
|
4
4
|
use tree_sitter::Node;
|
|
5
5
|
|
|
6
|
+
use self::process_arguments::{list_is_proven_fixed, name_is_reassigned};
|
|
6
7
|
use super::catalogue::MatcherCatalogue;
|
|
7
8
|
use super::{
|
|
8
9
|
DetectedSecurityCandidate, DetectionResult, LibraryImportContext, SecurityBlindSpot,
|
|
@@ -12,6 +13,7 @@ use crate::Location;
|
|
|
12
13
|
use crate::dart_parser::parse_dart_source_lossy;
|
|
13
14
|
use crate::generated::{is_flutterfire_options_path, is_generated_dart_path};
|
|
14
15
|
|
|
16
|
+
mod process_arguments;
|
|
15
17
|
mod weak_randomness;
|
|
16
18
|
|
|
17
19
|
pub(super) fn detect_in_source(
|
|
@@ -676,6 +678,7 @@ fn detect_process_call(
|
|
|
676
678
|
let Ok(function) = function_node.utf8_text(source.as_bytes()) else {
|
|
677
679
|
return;
|
|
678
680
|
};
|
|
681
|
+
let function = function.rsplit("=>").next().map_or(function, str::trim);
|
|
679
682
|
let index = function_node.start_byte();
|
|
680
683
|
let pattern = matcher
|
|
681
684
|
.callees
|
|
@@ -741,19 +744,17 @@ fn detect_process_call(
|
|
|
741
744
|
return;
|
|
742
745
|
}
|
|
743
746
|
let risky = if package_process {
|
|
744
|
-
|
|
745
|
-
|| process_manager_invokes_command_shell(root, source, index, arguments[0])
|
|
746
|
-
|| !fixed_argument_list(root, source, index, arguments[0])
|
|
747
|
+
process_manager_call_is_risky(root, source, index, arguments[0])
|
|
747
748
|
} else {
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
749
|
+
process_call_is_risky(
|
|
750
|
+
root,
|
|
751
|
+
source,
|
|
752
|
+
index,
|
|
753
|
+
call,
|
|
754
|
+
pattern,
|
|
755
|
+
&arguments,
|
|
756
|
+
inherited_imports,
|
|
757
|
+
)
|
|
757
758
|
};
|
|
758
759
|
if risky {
|
|
759
760
|
result.candidates.push(detected(
|
|
@@ -768,6 +769,37 @@ fn detect_process_call(
|
|
|
768
769
|
}
|
|
769
770
|
}
|
|
770
771
|
|
|
772
|
+
fn process_manager_call_is_risky(
|
|
773
|
+
root: Node<'_>,
|
|
774
|
+
source: &str,
|
|
775
|
+
index: usize,
|
|
776
|
+
command: &str,
|
|
777
|
+
) -> bool {
|
|
778
|
+
!parsed_run_in_shell_is_disabled(root, source, index)
|
|
779
|
+
|| process_manager_invokes_command_shell(root, source, index, command)
|
|
780
|
+
|| !fixed_argument_list(root, source, index, command)
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
fn process_call_is_risky(
|
|
784
|
+
root: Node<'_>,
|
|
785
|
+
source: &str,
|
|
786
|
+
index: usize,
|
|
787
|
+
call: &str,
|
|
788
|
+
pattern: &str,
|
|
789
|
+
arguments: &[&str],
|
|
790
|
+
inherited_imports: Option<&LibraryImportContext>,
|
|
791
|
+
) -> bool {
|
|
792
|
+
let fixed_executable =
|
|
793
|
+
resolved_fixed_literal_value(root, source, index, arguments[0]).is_some();
|
|
794
|
+
let fixed_dart_runtime = pattern == "Process.start"
|
|
795
|
+
&& resolved_dart_runtime_start(Some((root, source)), index, call, inherited_imports);
|
|
796
|
+
let fixed_arguments = fixed_argument_list(root, source, index, arguments[1]);
|
|
797
|
+
!parsed_run_in_shell_is_disabled(root, source, index)
|
|
798
|
+
|| call_invokes_command_shell(root, source, index, call)
|
|
799
|
+
|| (!fixed_executable && !fixed_dart_runtime)
|
|
800
|
+
|| !fixed_arguments
|
|
801
|
+
}
|
|
802
|
+
|
|
771
803
|
fn flattened_process_arguments<'source>(
|
|
772
804
|
node: Node<'_>,
|
|
773
805
|
source: &'source str,
|
|
@@ -1096,6 +1128,9 @@ fn string_literals(source: &str) -> Vec<StringLiteral> {
|
|
|
1096
1128
|
fn read_string(source: &str, start: usize) -> Option<(String, usize, usize)> {
|
|
1097
1129
|
let bytes = source.as_bytes();
|
|
1098
1130
|
let quote = *bytes.get(start)?;
|
|
1131
|
+
if !matches!(quote, b'\'' | b'"') {
|
|
1132
|
+
return None;
|
|
1133
|
+
}
|
|
1099
1134
|
if bytes.get(start..start + 3) == Some([quote, quote, quote].as_slice()) {
|
|
1100
1135
|
let mut index = start + 3;
|
|
1101
1136
|
let value_start = index;
|
|
@@ -1883,6 +1918,9 @@ fn resolved_list_arguments_inner(
|
|
|
1883
1918
|
return None;
|
|
1884
1919
|
}
|
|
1885
1920
|
let binding = lexical_binding_value(root, source, index, value)?;
|
|
1921
|
+
if !list_is_proven_fixed(root, source, index, value) {
|
|
1922
|
+
return None;
|
|
1923
|
+
}
|
|
1886
1924
|
resolved_list_arguments_inner(root, source, index, binding, visited)
|
|
1887
1925
|
}
|
|
1888
1926
|
|
|
@@ -1890,6 +1928,23 @@ fn fixed_string_literal(value: &str) -> bool {
|
|
|
1890
1928
|
fixed_literal_value(value).is_some()
|
|
1891
1929
|
}
|
|
1892
1930
|
|
|
1931
|
+
fn settled_binding<'source>(
|
|
1932
|
+
root: Node<'_>,
|
|
1933
|
+
source: &str,
|
|
1934
|
+
index: usize,
|
|
1935
|
+
name: &str,
|
|
1936
|
+
binding: LexicalBinding<'source>,
|
|
1937
|
+
local: bool,
|
|
1938
|
+
) -> Option<&'source str> {
|
|
1939
|
+
match binding {
|
|
1940
|
+
LexicalBinding::Value(value) => Some(value),
|
|
1941
|
+
LexicalBinding::Mutable(value) => {
|
|
1942
|
+
(local && !name_is_reassigned(root, source, index, name)).then_some(value)
|
|
1943
|
+
}
|
|
1944
|
+
LexicalBinding::Unknown => None,
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1893
1948
|
fn lexical_binding_value<'source>(
|
|
1894
1949
|
root: Node<'_>,
|
|
1895
1950
|
source: &'source str,
|
|
@@ -1901,10 +1956,7 @@ fn lexical_binding_value<'source>(
|
|
|
1901
1956
|
if parent.kind() == "class_body"
|
|
1902
1957
|
&& let Some(binding) = class_binding(parent, child, name, source)
|
|
1903
1958
|
{
|
|
1904
|
-
return
|
|
1905
|
-
LexicalBinding::Value(value) => Some(value),
|
|
1906
|
-
LexicalBinding::Unknown => None,
|
|
1907
|
-
};
|
|
1959
|
+
return settled_binding(root, source, index, name, binding, false);
|
|
1908
1960
|
}
|
|
1909
1961
|
if process_scope_parameters_bind_name(parent, name, source)
|
|
1910
1962
|
|| process_scope_header_binds_name(parent, child, name, source)
|
|
@@ -1912,7 +1964,14 @@ fn lexical_binding_value<'source>(
|
|
|
1912
1964
|
return None;
|
|
1913
1965
|
}
|
|
1914
1966
|
if parent.parent().is_none() {
|
|
1915
|
-
return
|
|
1967
|
+
return settled_binding(
|
|
1968
|
+
root,
|
|
1969
|
+
source,
|
|
1970
|
+
index,
|
|
1971
|
+
name,
|
|
1972
|
+
top_level_binding(parent, name, source)?,
|
|
1973
|
+
false,
|
|
1974
|
+
);
|
|
1916
1975
|
}
|
|
1917
1976
|
let mut cursor = parent.walk();
|
|
1918
1977
|
let mut siblings = parent
|
|
@@ -1921,10 +1980,14 @@ fn lexical_binding_value<'source>(
|
|
|
1921
1980
|
.collect::<Vec<_>>();
|
|
1922
1981
|
while let Some(sibling) = siblings.pop() {
|
|
1923
1982
|
if let Some(binding) = direct_binding(sibling, name, source, false) {
|
|
1924
|
-
return
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1983
|
+
return settled_binding(
|
|
1984
|
+
root,
|
|
1985
|
+
source,
|
|
1986
|
+
index,
|
|
1987
|
+
name,
|
|
1988
|
+
binding,
|
|
1989
|
+
parent.kind() != "class_body",
|
|
1990
|
+
);
|
|
1928
1991
|
}
|
|
1929
1992
|
}
|
|
1930
1993
|
child = parent;
|
|
@@ -2039,7 +2102,7 @@ fn top_level_binding<'source>(
|
|
|
2039
2102
|
root: Node<'_>,
|
|
2040
2103
|
name: &str,
|
|
2041
2104
|
source: &'source str,
|
|
2042
|
-
) -> Option
|
|
2105
|
+
) -> Option<LexicalBinding<'source>> {
|
|
2043
2106
|
let mut cursor = root.walk();
|
|
2044
2107
|
let mut binding = None;
|
|
2045
2108
|
for child in root.named_children(&mut cursor) {
|
|
@@ -2051,10 +2114,7 @@ fn top_level_binding<'source>(
|
|
|
2051
2114
|
}
|
|
2052
2115
|
binding = Some(candidate);
|
|
2053
2116
|
}
|
|
2054
|
-
|
|
2055
|
-
Some(LexicalBinding::Value(value)) => Some(value),
|
|
2056
|
-
Some(LexicalBinding::Unknown) | None => None,
|
|
2057
|
-
}
|
|
2117
|
+
binding
|
|
2058
2118
|
}
|
|
2059
2119
|
|
|
2060
2120
|
fn class_binding<'source>(
|
|
@@ -2249,8 +2309,10 @@ fn root_node(mut node: Node<'_>) -> Node<'_> {
|
|
|
2249
2309
|
node
|
|
2250
2310
|
}
|
|
2251
2311
|
|
|
2312
|
+
#[derive(Clone, Copy)]
|
|
2252
2313
|
enum LexicalBinding<'source> {
|
|
2253
2314
|
Value(&'source str),
|
|
2315
|
+
Mutable(&'source str),
|
|
2254
2316
|
Unknown,
|
|
2255
2317
|
}
|
|
2256
2318
|
|
|
@@ -2288,26 +2350,22 @@ fn direct_binding<'source>(
|
|
|
2288
2350
|
if binding_name != name {
|
|
2289
2351
|
return None;
|
|
2290
2352
|
}
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
);
|
|
2353
|
+
let value = node
|
|
2354
|
+
.child_by_field_name("value")
|
|
2355
|
+
.and_then(|value| value.utf8_text(source.as_bytes()).ok())
|
|
2356
|
+
.map(str::trim);
|
|
2357
|
+
return Some(match (value, immutable) {
|
|
2358
|
+
(Some(value), true) => LexicalBinding::Value(value),
|
|
2359
|
+
(Some(value), false) => LexicalBinding::Mutable(value),
|
|
2360
|
+
(None, _) => LexicalBinding::Unknown,
|
|
2361
|
+
});
|
|
2300
2362
|
}
|
|
2301
2363
|
if node.kind() == "assignment_expression" {
|
|
2302
2364
|
let left = node
|
|
2303
2365
|
.child_by_field_name("left")?
|
|
2304
2366
|
.utf8_text(source.as_bytes())
|
|
2305
2367
|
.ok()?;
|
|
2306
|
-
|
|
2307
|
-
.child_by_field_name("operator")?
|
|
2308
|
-
.utf8_text(source.as_bytes())
|
|
2309
|
-
.ok()?;
|
|
2310
|
-
if left.trim() == name && operator == "=" {
|
|
2368
|
+
if left.trim() == name {
|
|
2311
2369
|
return Some(LexicalBinding::Unknown);
|
|
2312
2370
|
}
|
|
2313
2371
|
return None;
|
|
@@ -14,6 +14,23 @@ pub(super) fn extend_implicit_extension_references(
|
|
|
14
14
|
project: &ScannedProject,
|
|
15
15
|
) {
|
|
16
16
|
let dependencies = project.graph.dependencies();
|
|
17
|
+
let mut imports_by_source = BTreeMap::<&PathBuf, Vec<&crate::ResolvedDependency>>::new();
|
|
18
|
+
for dependency in dependencies
|
|
19
|
+
.iter()
|
|
20
|
+
.filter(|dependency| dependency.kind == DependencyKind::Import)
|
|
21
|
+
{
|
|
22
|
+
imports_by_source
|
|
23
|
+
.entry(&dependency.from_path)
|
|
24
|
+
.or_default()
|
|
25
|
+
.push(dependency);
|
|
26
|
+
}
|
|
27
|
+
let mut member_names = BTreeMap::<(&PathBuf, &String), Vec<&String>>::new();
|
|
28
|
+
for member in members {
|
|
29
|
+
member_names
|
|
30
|
+
.entry((&member.path, &member.member.owner))
|
|
31
|
+
.or_default()
|
|
32
|
+
.push(&member.member.name);
|
|
33
|
+
}
|
|
17
34
|
for declaration in declarations
|
|
18
35
|
.iter()
|
|
19
36
|
.filter(|declaration| declaration.declaration.kind == DeclarationKind::Extension)
|
|
@@ -27,13 +44,11 @@ pub(super) fn extend_implicit_extension_references(
|
|
|
27
44
|
.map(|exported| exported.entry_path.clone())
|
|
28
45
|
.chain(std::iter::once(declaration.path.clone()))
|
|
29
46
|
.collect::<BTreeSet<_>>();
|
|
30
|
-
let implicit_references =
|
|
31
|
-
.
|
|
32
|
-
.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})
|
|
36
|
-
.filter_map(|member| references_by_name.get(&member.member.name))
|
|
47
|
+
let implicit_references = member_names
|
|
48
|
+
.get(&(&declaration.path, &declaration.declaration.name))
|
|
49
|
+
.into_iter()
|
|
50
|
+
.flatten()
|
|
51
|
+
.filter_map(|name| references_by_name.get(*name))
|
|
37
52
|
.flatten()
|
|
38
53
|
.filter(|reference| {
|
|
39
54
|
extension_visible_from(
|
|
@@ -41,7 +56,7 @@ pub(super) fn extend_implicit_extension_references(
|
|
|
41
56
|
declaration,
|
|
42
57
|
&entry_paths,
|
|
43
58
|
library_by_path,
|
|
44
|
-
&
|
|
59
|
+
&imports_by_source,
|
|
45
60
|
)
|
|
46
61
|
})
|
|
47
62
|
.cloned()
|
|
@@ -62,7 +77,7 @@ fn extension_visible_from(
|
|
|
62
77
|
declaration: &IndexedDeclaration,
|
|
63
78
|
entry_paths: &BTreeSet<PathBuf>,
|
|
64
79
|
library_by_path: &BTreeMap<PathBuf, PathBuf>,
|
|
65
|
-
|
|
80
|
+
imports_by_source: &BTreeMap<&PathBuf, Vec<&crate::ResolvedDependency>>,
|
|
66
81
|
) -> bool {
|
|
67
82
|
let reference_library = library_by_path
|
|
68
83
|
.get(&reference.path)
|
|
@@ -74,22 +89,22 @@ fn extension_visible_from(
|
|
|
74
89
|
return true;
|
|
75
90
|
}
|
|
76
91
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
imports_by_source
|
|
93
|
+
.get(&reference.path)
|
|
94
|
+
.is_some_and(|imports| {
|
|
95
|
+
imports.iter().any(|dependency| {
|
|
96
|
+
entry_paths.contains(&dependency.to_path)
|
|
97
|
+
&& dependency.visibility.prefix.is_none()
|
|
98
|
+
&& dependency.visibility.combinators.iter().all(|combinator| {
|
|
99
|
+
match combinator.kind {
|
|
100
|
+
DartCombinatorKind::Show => {
|
|
101
|
+
combinator.names.contains(&declaration.declaration.name)
|
|
102
|
+
}
|
|
103
|
+
DartCombinatorKind::Hide => {
|
|
104
|
+
!combinator.names.contains(&declaration.declaration.name)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
})
|
|
95
110
|
}
|
|
@@ -4,7 +4,7 @@ pub(super) fn is_private(name: &str) -> bool {
|
|
|
4
4
|
name.starts_with('_')
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
pub(
|
|
7
|
+
pub(crate) fn is_library_source(root: &Path, path: &Path) -> bool {
|
|
8
8
|
path.strip_prefix(root).is_ok_and(|relative| {
|
|
9
9
|
relative
|
|
10
10
|
.components()
|
|
@@ -13,6 +13,15 @@ pub(super) fn is_library_source(root: &Path, path: &Path) -> bool {
|
|
|
13
13
|
})
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
pub(super) fn is_bin_source(root: &Path, path: &Path) -> bool {
|
|
17
|
+
path.strip_prefix(root).is_ok_and(|relative| {
|
|
18
|
+
relative
|
|
19
|
+
.components()
|
|
20
|
+
.next()
|
|
21
|
+
.is_some_and(|component| component.as_os_str() == "bin")
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
16
25
|
pub(super) fn is_public_library_entry(root: &Path, path: &Path) -> bool {
|
|
17
26
|
path.strip_prefix(root).is_ok_and(|relative| {
|
|
18
27
|
let mut components = relative.components();
|
package/src/symbols/tests.rs
CHANGED
|
@@ -725,3 +725,18 @@ fn write(fixture: &TempDir, path: &str, source: &str) -> Result<(), std::io::Err
|
|
|
725
725
|
}
|
|
726
726
|
fs::write(path, source)
|
|
727
727
|
}
|
|
728
|
+
|
|
729
|
+
#[test]
|
|
730
|
+
fn package_folder_text_uses_forward_slashes() {
|
|
731
|
+
let package = Path::new("/r").join("apps").join("pure");
|
|
732
|
+
assert_eq!(
|
|
733
|
+
super::package_folder(Path::new("/r"), &package),
|
|
734
|
+
"apps/pure"
|
|
735
|
+
);
|
|
736
|
+
if std::path::MAIN_SEPARATOR == '/' {
|
|
737
|
+
assert_eq!(
|
|
738
|
+
super::package_folder(Path::new("/r"), Path::new("/r/a\\b")),
|
|
739
|
+
"a\\b"
|
|
740
|
+
);
|
|
741
|
+
}
|
|
742
|
+
}
|