dart-decimate 0.0.1
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 +572 -0
- package/Cargo.toml +41 -0
- package/LICENSE +21 -0
- package/README.md +617 -0
- package/assets/dart-decimate-banner.png +0 -0
- package/npm/bin/dart-decimate-mcp.js +48 -0
- package/npm/bin/dart-decimate.js +48 -0
- package/npm/scripts/postinstall.js +46 -0
- package/npm/scripts/test-npx-local.js +54 -0
- package/npm/scripts/test-npx-mcp-local.js +56 -0
- package/package.json +45 -0
- package/src/baseline.rs +643 -0
- package/src/bin/dart-decimate-mcp.rs +11 -0
- package/src/boundaries/tests.rs +60 -0
- package/src/boundaries.rs +317 -0
- package/src/changed_scope.rs +117 -0
- package/src/ci_template.rs +399 -0
- package/src/cli/analyze.rs +462 -0
- package/src/cli/analyzer_options.rs +82 -0
- package/src/cli/audit_run.rs +327 -0
- package/src/cli/boundary_args.rs +44 -0
- package/src/cli/ci_template_run.rs +196 -0
- package/src/cli/command_name.rs +20 -0
- package/src/cli/common_args.rs +167 -0
- package/src/cli/config_run.rs +78 -0
- package/src/cli/coverage_run.rs +393 -0
- package/src/cli/decision_surface_run.rs +99 -0
- package/src/cli/default_command.rs +69 -0
- package/src/cli/dupes_args.rs +150 -0
- package/src/cli/entry_points.rs +121 -0
- package/src/cli/error.rs +149 -0
- package/src/cli/error_output.rs +68 -0
- package/src/cli/explain_run.rs +72 -0
- package/src/cli/fix_run.rs +162 -0
- package/src/cli/flags_args.rs +23 -0
- package/src/cli/health_args.rs +200 -0
- package/src/cli/hooks_run.rs +191 -0
- package/src/cli/impact_run.rs +95 -0
- package/src/cli/init_run.rs +49 -0
- package/src/cli/inspect_args.rs +20 -0
- package/src/cli/inspect_run.rs +66 -0
- package/src/cli/issue_filter_args.rs +240 -0
- package/src/cli/list_run.rs +311 -0
- package/src/cli/mode_args.rs +72 -0
- package/src/cli/output_format.rs +62 -0
- package/src/cli/regression_args.rs +156 -0
- package/src/cli/request_args.rs +175 -0
- package/src/cli/schema_commands.rs +72 -0
- package/src/cli/scope_args.rs +174 -0
- package/src/cli/security_args.rs +175 -0
- package/src/cli/security_gate_run.rs +66 -0
- package/src/cli/security_summary_run.rs +43 -0
- package/src/cli/summary_args.rs +12 -0
- package/src/cli/tests.rs +516 -0
- package/src/cli/trace_args.rs +67 -0
- package/src/cli/trace_run.rs +131 -0
- package/src/cli/trace_tests.rs +235 -0
- package/src/cli/unsupported_run.rs +116 -0
- package/src/cli/watch_run.rs +153 -0
- package/src/cli.rs +603 -0
- package/src/config/boundary_config.rs +235 -0
- package/src/config/cache.rs +25 -0
- package/src/config/dependencies.rs +114 -0
- package/src/config/health.rs +237 -0
- package/src/config/jsonc.rs +66 -0
- package/src/config/policy.rs +91 -0
- package/src/config/rule_aliases.rs +487 -0
- package/src/config/rules.rs +339 -0
- package/src/config.rs +635 -0
- package/src/coverage.rs +469 -0
- package/src/dart_parser.rs +673 -0
- package/src/decision_surface.rs +405 -0
- package/src/dependencies/analyze.rs +218 -0
- package/src/dependencies/codegen.rs +118 -0
- package/src/dependencies/discovery.rs +60 -0
- package/src/dependencies/overrides.rs +76 -0
- package/src/dependencies/private_src_imports.rs +32 -0
- package/src/dependencies/pubspec_document.rs +86 -0
- package/src/dependencies/pubspec_entry.rs +96 -0
- package/src/dependencies/tests.rs +544 -0
- package/src/dependencies/usage.rs +33 -0
- package/src/dependencies.rs +553 -0
- package/src/dependency_scripts.rs +91 -0
- package/src/dupes/lex.rs +236 -0
- package/src/dupes/tests.rs +119 -0
- package/src/dupes.rs +625 -0
- package/src/explain.rs +692 -0
- package/src/extract/directives.rs +252 -0
- package/src/extract/error_tests.rs +25 -0
- package/src/extract/members.rs +210 -0
- package/src/extract/primary_constructors.rs +421 -0
- package/src/extract/references.rs +151 -0
- package/src/extract/routes.rs +691 -0
- package/src/extract/signatures.rs +266 -0
- package/src/extract/string_tests.rs +18 -0
- package/src/extract/strings.rs +107 -0
- package/src/extract/tests.rs +697 -0
- package/src/extract.rs +680 -0
- package/src/feature_flags/tests.rs +76 -0
- package/src/feature_flags.rs +453 -0
- package/src/finding_identity.rs +60 -0
- package/src/fix.rs +551 -0
- package/src/generated.rs +53 -0
- package/src/graph/augment_tests.rs +212 -0
- package/src/graph/conditionals.rs +74 -0
- package/src/graph/package_config_tests.rs +100 -0
- package/src/graph/parts.rs +248 -0
- package/src/graph/pubspec_tests.rs +119 -0
- package/src/graph/tests.rs +837 -0
- package/src/graph/uri_tests.rs +102 -0
- package/src/graph.rs +644 -0
- package/src/health/coverage.rs +309 -0
- package/src/health/ownership.rs +175 -0
- package/src/health/runtime_coverage.rs +616 -0
- package/src/health/runtime_intelligence.rs +511 -0
- package/src/health/scores.rs +296 -0
- package/src/health/tests.rs +240 -0
- package/src/health/threshold_types.rs +163 -0
- package/src/health/thresholds.rs +229 -0
- package/src/health/types.rs +636 -0
- package/src/health.rs +597 -0
- package/src/hooks/agent_settings.rs +175 -0
- package/src/hooks/templates.rs +51 -0
- package/src/hooks.rs +569 -0
- package/src/impact.rs +287 -0
- package/src/init.rs +237 -0
- package/src/inspect.rs +142 -0
- package/src/intelligence/tests.rs +232 -0
- package/src/intelligence.rs +305 -0
- package/src/lib.rs +198 -0
- package/src/main.rs +5 -0
- package/src/manifest/mcp.rs +565 -0
- package/src/manifest.rs +552 -0
- package/src/mcp/cli_args/value_args.rs +175 -0
- package/src/mcp/cli_args.rs +658 -0
- package/src/mcp/cli_args_tests.rs +522 -0
- package/src/mcp/code_execute.rs +671 -0
- package/src/mcp/tools.rs +660 -0
- package/src/mcp.rs +325 -0
- package/src/output/audit_risk.rs +135 -0
- package/src/output/dependency_findings.rs +327 -0
- package/src/output/duplication_findings.rs +114 -0
- package/src/output/feature_flag_findings.rs +122 -0
- package/src/output/format.rs +31 -0
- package/src/output/graph_findings.rs +461 -0
- package/src/output/health_findings.rs +612 -0
- package/src/output/human.rs +27 -0
- package/src/output/next_steps.rs +92 -0
- package/src/output/route_findings.rs +76 -0
- package/src/output/runtime_coverage.rs +515 -0
- package/src/output/scope.rs +183 -0
- package/src/output/security_findings.rs +390 -0
- package/src/output/security_sarif.rs +150 -0
- package/src/output/suppressions.rs +323 -0
- package/src/output/symbol_findings.rs +257 -0
- package/src/output/tests.rs +114 -0
- package/src/output/types.rs +604 -0
- package/src/output/widget_findings.rs +213 -0
- package/src/output.rs +682 -0
- package/src/package_map.rs +495 -0
- package/src/policy/packs.rs +232 -0
- package/src/policy/tests.rs +134 -0
- package/src/policy.rs +640 -0
- package/src/project_list.rs +376 -0
- package/src/report_schema/inventory.rs +418 -0
- package/src/report_schema.rs +488 -0
- package/src/routes.rs +354 -0
- package/src/scan/tests.rs +250 -0
- package/src/scan.rs +275 -0
- package/src/security/detect.rs +639 -0
- package/src/security/tests.rs +178 -0
- package/src/security.rs +373 -0
- package/src/security_gate.rs +555 -0
- package/src/symbols/path_filters.rs +27 -0
- package/src/symbols/private_type_leaks.rs +125 -0
- package/src/symbols/riverpod.rs +113 -0
- package/src/symbols/tests.rs +692 -0
- package/src/symbols.rs +693 -0
- package/src/trace/tests.rs +225 -0
- package/src/trace.rs +690 -0
- package/src/unsupported.rs +47 -0
- package/src/widgets/lifecycle.rs +484 -0
- package/src/widgets/params.rs +236 -0
- package/src/widgets/tests.rs +430 -0
- package/src/widgets/top_level.rs +110 -0
- package/src/widgets/unrendered.rs +374 -0
- package/src/widgets.rs +590 -0
- package/src/workspace_scope.rs +358 -0
|
@@ -0,0 +1,639 @@
|
|
|
1
|
+
use std::path::Path;
|
|
2
|
+
|
|
3
|
+
use super::{DetectedSecurityCandidate, SecurityCategory, SecurityConfidence, SecurityOccurrence};
|
|
4
|
+
use crate::Location;
|
|
5
|
+
use crate::generated::is_generated_dart_path;
|
|
6
|
+
|
|
7
|
+
pub(super) fn detect_in_source(path: &Path, source: &str) -> Vec<DetectedSecurityCandidate> {
|
|
8
|
+
let mut candidates = Vec::new();
|
|
9
|
+
detect_hardcoded_secrets(path, source, &mut candidates);
|
|
10
|
+
detect_insecure_transport(path, source, &mut candidates);
|
|
11
|
+
detect_tls_bypass(path, source, &mut candidates);
|
|
12
|
+
detect_webview_risk(path, source, &mut candidates);
|
|
13
|
+
detect_process_execution(path, source, &mut candidates);
|
|
14
|
+
detect_raw_sql(path, source, &mut candidates);
|
|
15
|
+
detect_plain_secret_storage(path, source, &mut candidates);
|
|
16
|
+
candidates
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
pub(super) fn is_ignored_path(path: &Path) -> bool {
|
|
20
|
+
if path.components().any(|component| {
|
|
21
|
+
let value = component.as_os_str().to_string_lossy();
|
|
22
|
+
matches!(value.as_ref(), "test" | "integration_test" | "test_driver")
|
|
23
|
+
}) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
is_generated_dart_path(path)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
fn detect_hardcoded_secrets(
|
|
30
|
+
path: &Path,
|
|
31
|
+
source: &str,
|
|
32
|
+
candidates: &mut Vec<DetectedSecurityCandidate>,
|
|
33
|
+
) {
|
|
34
|
+
for literal in string_literals(source) {
|
|
35
|
+
if is_comment_match(source, literal.index) || is_placeholder(&literal.value) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
let line = line_at(source, literal.index);
|
|
39
|
+
let secret_value = has_secret_shape(&literal.value);
|
|
40
|
+
if line.contains("FirebaseOptions")
|
|
41
|
+
|| line.contains("googleAppId")
|
|
42
|
+
|| (!secret_value && literal_looks_like_storage_key(&literal.value))
|
|
43
|
+
|| (!secret_value && diagnostic_context(source, literal.index))
|
|
44
|
+
|| (!secret_value && literal.value.contains('$'))
|
|
45
|
+
{
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
let secret_name = has_secret_like_name(line);
|
|
49
|
+
if secret_name && literal.value.len() >= 12 || secret_value {
|
|
50
|
+
candidates.push(detected(
|
|
51
|
+
path,
|
|
52
|
+
source,
|
|
53
|
+
literal.index,
|
|
54
|
+
SecurityCategory::HardcodedSecret,
|
|
55
|
+
"secret-literal",
|
|
56
|
+
if secret_value {
|
|
57
|
+
SecurityConfidence::High
|
|
58
|
+
} else {
|
|
59
|
+
SecurityConfidence::Medium
|
|
60
|
+
},
|
|
61
|
+
"string-literal",
|
|
62
|
+
));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
fn detect_insecure_transport(
|
|
68
|
+
path: &Path,
|
|
69
|
+
source: &str,
|
|
70
|
+
candidates: &mut Vec<DetectedSecurityCandidate>,
|
|
71
|
+
) {
|
|
72
|
+
for literal in string_literals(source) {
|
|
73
|
+
if is_comment_match(source, literal.index)
|
|
74
|
+
|| !literal.value.starts_with("http://")
|
|
75
|
+
|| is_local_http_url(&literal.value)
|
|
76
|
+
{
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
let line = line_at(source, literal.index);
|
|
80
|
+
if has_network_context(line) {
|
|
81
|
+
candidates.push(detected(
|
|
82
|
+
path,
|
|
83
|
+
source,
|
|
84
|
+
literal.index,
|
|
85
|
+
SecurityCategory::InsecureTransport,
|
|
86
|
+
"cleartext-http",
|
|
87
|
+
SecurityConfidence::High,
|
|
88
|
+
"http-url",
|
|
89
|
+
));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
fn detect_tls_bypass(path: &Path, source: &str, candidates: &mut Vec<DetectedSecurityCandidate>) {
|
|
95
|
+
for pattern in [
|
|
96
|
+
"badCertificateCallback",
|
|
97
|
+
"HttpOverrides.global",
|
|
98
|
+
"SecurityContext(withTrustedRoots: false",
|
|
99
|
+
"validateCertificate",
|
|
100
|
+
] {
|
|
101
|
+
for index in match_indices(source, pattern) {
|
|
102
|
+
let window = following_window(source, index, 4);
|
|
103
|
+
let risky = match pattern {
|
|
104
|
+
"badCertificateCallback" | "validateCertificate" => {
|
|
105
|
+
returns_true(window) && !returns_false(window)
|
|
106
|
+
}
|
|
107
|
+
_ => true,
|
|
108
|
+
};
|
|
109
|
+
if risky {
|
|
110
|
+
candidates.push(detected(
|
|
111
|
+
path,
|
|
112
|
+
source,
|
|
113
|
+
index,
|
|
114
|
+
SecurityCategory::TlsBypass,
|
|
115
|
+
pattern,
|
|
116
|
+
SecurityConfidence::High,
|
|
117
|
+
pattern,
|
|
118
|
+
));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
fn detect_webview_risk(path: &Path, source: &str, candidates: &mut Vec<DetectedSecurityCandidate>) {
|
|
125
|
+
for pattern in [
|
|
126
|
+
"JavaScriptMode.unrestricted",
|
|
127
|
+
"javaScriptEnabled: true",
|
|
128
|
+
"allowFileAccess: true",
|
|
129
|
+
"allowFileAccessFromFileURLs: true",
|
|
130
|
+
"allowUniversalAccessFromFileURLs: true",
|
|
131
|
+
] {
|
|
132
|
+
for index in match_indices(source, pattern) {
|
|
133
|
+
candidates.push(detected(
|
|
134
|
+
path,
|
|
135
|
+
source,
|
|
136
|
+
index,
|
|
137
|
+
SecurityCategory::WebViewRisk,
|
|
138
|
+
"webview",
|
|
139
|
+
SecurityConfidence::High,
|
|
140
|
+
pattern,
|
|
141
|
+
));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
for literal in string_literals(source) {
|
|
145
|
+
if literal.value.starts_with("file://") {
|
|
146
|
+
let line = line_at(source, literal.index);
|
|
147
|
+
if line.contains("loadUrl") || line.contains("loadRequest") {
|
|
148
|
+
candidates.push(detected(
|
|
149
|
+
path,
|
|
150
|
+
source,
|
|
151
|
+
literal.index,
|
|
152
|
+
SecurityCategory::WebViewRisk,
|
|
153
|
+
"webview-file-url",
|
|
154
|
+
SecurityConfidence::Medium,
|
|
155
|
+
"file-url",
|
|
156
|
+
));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
fn detect_process_execution(
|
|
163
|
+
path: &Path,
|
|
164
|
+
source: &str,
|
|
165
|
+
candidates: &mut Vec<DetectedSecurityCandidate>,
|
|
166
|
+
) {
|
|
167
|
+
for pattern in [
|
|
168
|
+
"Process.run(",
|
|
169
|
+
"Process.start(",
|
|
170
|
+
"processManager.run(",
|
|
171
|
+
"processManager.start(",
|
|
172
|
+
] {
|
|
173
|
+
for index in match_indices(source, pattern) {
|
|
174
|
+
let window = following_window(source, index, 3);
|
|
175
|
+
let args = call_inside_after(source, index + pattern.len());
|
|
176
|
+
let risky = window.contains("runInShell: true")
|
|
177
|
+
|| args.as_deref().is_some_and(|call| {
|
|
178
|
+
!first_call_arg_is_fixed_literal(call) || has_dynamic_text(call)
|
|
179
|
+
});
|
|
180
|
+
if risky {
|
|
181
|
+
candidates.push(detected(
|
|
182
|
+
path,
|
|
183
|
+
source,
|
|
184
|
+
index,
|
|
185
|
+
SecurityCategory::ProcessExecution,
|
|
186
|
+
"process-exec",
|
|
187
|
+
SecurityConfidence::High,
|
|
188
|
+
pattern.trim_end_matches('('),
|
|
189
|
+
));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
fn detect_raw_sql(path: &Path, source: &str, candidates: &mut Vec<DetectedSecurityCandidate>) {
|
|
196
|
+
for pattern in [
|
|
197
|
+
".rawQuery(",
|
|
198
|
+
".rawInsert(",
|
|
199
|
+
".rawUpdate(",
|
|
200
|
+
".rawDelete(",
|
|
201
|
+
".execute(",
|
|
202
|
+
".customSelect(",
|
|
203
|
+
".customStatement(",
|
|
204
|
+
] {
|
|
205
|
+
for index in match_indices(source, pattern) {
|
|
206
|
+
let Some(call) = call_inside_after(source, index + pattern.len()) else {
|
|
207
|
+
continue;
|
|
208
|
+
};
|
|
209
|
+
if sql_call_is_parameterized(&call) {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
let risky = has_dynamic_text(&call) || !first_call_arg_is_fixed_literal(&call);
|
|
213
|
+
let broad_execute = pattern == ".execute(";
|
|
214
|
+
if risky && (!broad_execute || sql_like_text(&call)) {
|
|
215
|
+
candidates.push(detected(
|
|
216
|
+
path,
|
|
217
|
+
source,
|
|
218
|
+
index,
|
|
219
|
+
SecurityCategory::RawSql,
|
|
220
|
+
"raw-sql",
|
|
221
|
+
SecurityConfidence::High,
|
|
222
|
+
pattern.trim_start_matches('.').trim_end_matches('('),
|
|
223
|
+
));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
for index in match_indices(source, "where:") {
|
|
228
|
+
let line = line_at(source, index);
|
|
229
|
+
if (line.contains('$') || line.contains('+')) && !line.contains("whereArgs") {
|
|
230
|
+
candidates.push(detected(
|
|
231
|
+
path,
|
|
232
|
+
source,
|
|
233
|
+
index,
|
|
234
|
+
SecurityCategory::RawSql,
|
|
235
|
+
"dynamic-where",
|
|
236
|
+
SecurityConfidence::Medium,
|
|
237
|
+
"where",
|
|
238
|
+
));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
fn detect_plain_secret_storage(
|
|
244
|
+
path: &Path,
|
|
245
|
+
source: &str,
|
|
246
|
+
candidates: &mut Vec<DetectedSecurityCandidate>,
|
|
247
|
+
) {
|
|
248
|
+
for pattern in [
|
|
249
|
+
".setString(",
|
|
250
|
+
".setStringList(",
|
|
251
|
+
".put(",
|
|
252
|
+
".writeAsString(",
|
|
253
|
+
".writeAsBytes(",
|
|
254
|
+
] {
|
|
255
|
+
for index in match_indices(source, pattern) {
|
|
256
|
+
let line = line_at(source, index);
|
|
257
|
+
if line.contains("FlutterSecureStorage") || line.contains(".write(") {
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
let storage_context = match pattern {
|
|
261
|
+
".setString(" | ".setStringList(" => true,
|
|
262
|
+
".put(" => line.contains("Hive") || line.contains("box."),
|
|
263
|
+
_ => line.contains("File(") || line.contains(".writeAs"),
|
|
264
|
+
};
|
|
265
|
+
if storage_context && has_secret_like_name(line) && !line.contains("HiveAesCipher") {
|
|
266
|
+
candidates.push(detected(
|
|
267
|
+
path,
|
|
268
|
+
source,
|
|
269
|
+
index,
|
|
270
|
+
SecurityCategory::PlainSecretStorage,
|
|
271
|
+
"plain-local-storage",
|
|
272
|
+
SecurityConfidence::Medium,
|
|
273
|
+
pattern.trim_start_matches('.').trim_end_matches('('),
|
|
274
|
+
));
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
fn detected(
|
|
281
|
+
path: &Path,
|
|
282
|
+
source: &str,
|
|
283
|
+
index: usize,
|
|
284
|
+
category: SecurityCategory,
|
|
285
|
+
sink: &str,
|
|
286
|
+
confidence: SecurityConfidence,
|
|
287
|
+
expression: &str,
|
|
288
|
+
) -> DetectedSecurityCandidate {
|
|
289
|
+
DetectedSecurityCandidate {
|
|
290
|
+
category,
|
|
291
|
+
sink: sink.to_owned(),
|
|
292
|
+
confidence,
|
|
293
|
+
occurrence: SecurityOccurrence {
|
|
294
|
+
path: path.to_path_buf(),
|
|
295
|
+
location: location_for_index(source, index),
|
|
296
|
+
expression: expression.to_owned(),
|
|
297
|
+
evidence: redact_line(line_at(source, index)),
|
|
298
|
+
reachability: None,
|
|
299
|
+
},
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
304
|
+
struct StringLiteral {
|
|
305
|
+
index: usize,
|
|
306
|
+
value: String,
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
fn string_literals(source: &str) -> Vec<StringLiteral> {
|
|
310
|
+
let mut literals = Vec::new();
|
|
311
|
+
let mut index = 0;
|
|
312
|
+
let bytes = source.as_bytes();
|
|
313
|
+
while index < bytes.len() {
|
|
314
|
+
if matches!(bytes[index], b'\'' | b'"')
|
|
315
|
+
&& !is_comment_match(source, index)
|
|
316
|
+
&& let Some((value, end)) = read_string(source, index)
|
|
317
|
+
{
|
|
318
|
+
literals.push(StringLiteral { index, value });
|
|
319
|
+
index = end;
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
index += 1;
|
|
323
|
+
}
|
|
324
|
+
literals
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
fn read_string(source: &str, start: usize) -> Option<(String, usize)> {
|
|
328
|
+
let bytes = source.as_bytes();
|
|
329
|
+
let quote = *bytes.get(start)?;
|
|
330
|
+
let mut index = start + 1;
|
|
331
|
+
let value_start = index;
|
|
332
|
+
while index < bytes.len() {
|
|
333
|
+
if bytes[index] == b'\\' {
|
|
334
|
+
index = (index + 2).min(bytes.len());
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
if bytes[index] == quote {
|
|
338
|
+
return Some((source[value_start..index].to_owned(), index + 1));
|
|
339
|
+
}
|
|
340
|
+
index += 1;
|
|
341
|
+
}
|
|
342
|
+
None
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
fn match_indices(source: &str, pattern: &str) -> Vec<usize> {
|
|
346
|
+
let mut matches = Vec::new();
|
|
347
|
+
let mut offset = 0;
|
|
348
|
+
while let Some(relative) = source[offset..].find(pattern) {
|
|
349
|
+
let index = offset + relative;
|
|
350
|
+
offset = index + pattern.len();
|
|
351
|
+
if !is_comment_match(source, index) {
|
|
352
|
+
matches.push(index);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
matches
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
fn call_inside_after(source: &str, start: usize) -> Option<String> {
|
|
359
|
+
let bytes = source.as_bytes();
|
|
360
|
+
let mut depth = 1usize;
|
|
361
|
+
let mut index = start;
|
|
362
|
+
while index < bytes.len() {
|
|
363
|
+
match bytes[index] {
|
|
364
|
+
b'\'' | b'"' => {
|
|
365
|
+
index = read_string(source, index)?.1;
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
b'(' => depth += 1,
|
|
369
|
+
b')' => {
|
|
370
|
+
depth = depth.saturating_sub(1);
|
|
371
|
+
if depth == 0 {
|
|
372
|
+
return Some(source[start..index].to_owned());
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
_ => {}
|
|
376
|
+
}
|
|
377
|
+
index += 1;
|
|
378
|
+
}
|
|
379
|
+
None
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
fn first_call_arg_is_fixed_literal(call: &str) -> bool {
|
|
383
|
+
let trimmed = call.trim_start();
|
|
384
|
+
if !matches!(trimmed.as_bytes().first(), Some(b'\'' | b'"')) {
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
let Some((_, end)) = read_string(trimmed, 0) else {
|
|
388
|
+
return false;
|
|
389
|
+
};
|
|
390
|
+
let rest = trimmed[end..].trim_start();
|
|
391
|
+
matches!(rest.as_bytes().first(), Some(b',' | b')'))
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
fn sql_call_is_parameterized(call: &str) -> bool {
|
|
395
|
+
call.contains('?') && (call.contains('[') || call.contains("whereArgs"))
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
fn has_dynamic_text(text: &str) -> bool {
|
|
399
|
+
text.contains('$') || text.contains(" + ") || text.contains("+ ") || text.contains(" +")
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
fn sql_like_text(text: &str) -> bool {
|
|
403
|
+
let upper = text.to_ascii_uppercase();
|
|
404
|
+
[
|
|
405
|
+
"SELECT ", "INSERT ", "UPDATE ", "DELETE ", "CREATE ", "DROP ", "ALTER ", " WHERE ",
|
|
406
|
+
" FROM ", " JOIN ",
|
|
407
|
+
]
|
|
408
|
+
.iter()
|
|
409
|
+
.any(|keyword| upper.contains(keyword))
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
fn has_network_context(line: &str) -> bool {
|
|
413
|
+
[
|
|
414
|
+
"Uri.parse",
|
|
415
|
+
"http.",
|
|
416
|
+
"Dio(",
|
|
417
|
+
"BaseOptions",
|
|
418
|
+
"Request(",
|
|
419
|
+
"getUrl",
|
|
420
|
+
"openUrl",
|
|
421
|
+
"loadRequest",
|
|
422
|
+
]
|
|
423
|
+
.iter()
|
|
424
|
+
.any(|pattern| line.contains(pattern))
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
fn has_secret_like_name(text: &str) -> bool {
|
|
428
|
+
let lower = text.to_ascii_lowercase();
|
|
429
|
+
[
|
|
430
|
+
"secret",
|
|
431
|
+
"token",
|
|
432
|
+
"jwt",
|
|
433
|
+
"privatekey",
|
|
434
|
+
"private_key",
|
|
435
|
+
"clientsecret",
|
|
436
|
+
"client_secret",
|
|
437
|
+
"refreshtoken",
|
|
438
|
+
"refresh_token",
|
|
439
|
+
"accesstoken",
|
|
440
|
+
"access_token",
|
|
441
|
+
"password",
|
|
442
|
+
"passwd",
|
|
443
|
+
"bearer",
|
|
444
|
+
"authorization",
|
|
445
|
+
"apikey",
|
|
446
|
+
"api_key",
|
|
447
|
+
"signingkey",
|
|
448
|
+
"signing_key",
|
|
449
|
+
]
|
|
450
|
+
.iter()
|
|
451
|
+
.any(|needle| lower.contains(needle))
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
fn has_secret_shape(value: &str) -> bool {
|
|
455
|
+
if value.contains('$') {
|
|
456
|
+
return false;
|
|
457
|
+
}
|
|
458
|
+
value.contains("-----BEGIN ") && value.contains("PRIVATE KEY-----")
|
|
459
|
+
|| value.starts_with("Bearer ")
|
|
460
|
+
|| value.starts_with("sk_")
|
|
461
|
+
|| value.starts_with("ghp_")
|
|
462
|
+
|| jwt_like(value)
|
|
463
|
+
|| long_hex(value)
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
fn jwt_like(value: &str) -> bool {
|
|
467
|
+
let parts = value.split('.').collect::<Vec<_>>();
|
|
468
|
+
parts.len() == 3
|
|
469
|
+
&& parts
|
|
470
|
+
.iter()
|
|
471
|
+
.all(|part| part.len() >= 10 && is_base64ish(part))
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
fn long_hex(value: &str) -> bool {
|
|
475
|
+
value.len() >= 32 && value.bytes().all(|byte| byte.is_ascii_hexdigit())
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
fn is_base64ish(value: &str) -> bool {
|
|
479
|
+
value.bytes().all(|byte| {
|
|
480
|
+
byte.is_ascii_alphanumeric() || matches!(byte, b'_' | b'-' | b'+' | b'/' | b'=')
|
|
481
|
+
})
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
fn literal_looks_like_storage_key(value: &str) -> bool {
|
|
485
|
+
let trimmed = value.trim();
|
|
486
|
+
!trimmed.is_empty()
|
|
487
|
+
&& trimmed.len() <= 64
|
|
488
|
+
&& trimmed
|
|
489
|
+
.bytes()
|
|
490
|
+
.all(|byte| byte.is_ascii_alphabetic() || matches!(byte, b'_' | b'-' | b'.'))
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
fn diagnostic_context(source: &str, index: usize) -> bool {
|
|
494
|
+
let mut start = source[..index]
|
|
495
|
+
.rfind('\n')
|
|
496
|
+
.map_or(0, |position| position + 1);
|
|
497
|
+
for _ in 0..2 {
|
|
498
|
+
if start == 0 {
|
|
499
|
+
break;
|
|
500
|
+
}
|
|
501
|
+
start = source[..start - 1]
|
|
502
|
+
.rfind('\n')
|
|
503
|
+
.map_or(0, |position| position + 1);
|
|
504
|
+
}
|
|
505
|
+
let end = source[index..]
|
|
506
|
+
.find('\n')
|
|
507
|
+
.map_or(source.len(), |position| index + position);
|
|
508
|
+
line_is_diagnostic_text(&source[start..end])
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
fn line_is_diagnostic_text(line: &str) -> bool {
|
|
512
|
+
let lower = line.to_ascii_lowercase();
|
|
513
|
+
[
|
|
514
|
+
"_log.",
|
|
515
|
+
"logger.",
|
|
516
|
+
"log.",
|
|
517
|
+
"print(",
|
|
518
|
+
"debugprint(",
|
|
519
|
+
"throw ",
|
|
520
|
+
"exception(",
|
|
521
|
+
"error(",
|
|
522
|
+
]
|
|
523
|
+
.iter()
|
|
524
|
+
.any(|pattern| lower.contains(pattern))
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
fn is_placeholder(value: &str) -> bool {
|
|
528
|
+
let normalized = value
|
|
529
|
+
.trim()
|
|
530
|
+
.trim_matches(|character| matches!(character, '<' | '>' | '{' | '}'))
|
|
531
|
+
.to_ascii_lowercase()
|
|
532
|
+
.replace(['-', '_', ' '], "");
|
|
533
|
+
normalized.is_empty()
|
|
534
|
+
|| normalized.chars().all(|character| character == 'x')
|
|
535
|
+
|| [
|
|
536
|
+
"todo",
|
|
537
|
+
"example",
|
|
538
|
+
"dummy",
|
|
539
|
+
"test",
|
|
540
|
+
"changeme",
|
|
541
|
+
"redacted",
|
|
542
|
+
"yourapikey",
|
|
543
|
+
"yourkeyhere",
|
|
544
|
+
"yourtoken",
|
|
545
|
+
"placeholder",
|
|
546
|
+
]
|
|
547
|
+
.iter()
|
|
548
|
+
.any(|placeholder| normalized.contains(placeholder))
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
fn is_local_http_url(value: &str) -> bool {
|
|
552
|
+
let lower = value.to_ascii_lowercase();
|
|
553
|
+
[
|
|
554
|
+
"http://localhost",
|
|
555
|
+
"http://127.0.0.1",
|
|
556
|
+
"http://[::1]",
|
|
557
|
+
"http://::1",
|
|
558
|
+
"http://10.0.2.2",
|
|
559
|
+
"http://0.0.0.0",
|
|
560
|
+
]
|
|
561
|
+
.iter()
|
|
562
|
+
.any(|prefix| lower.starts_with(prefix))
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
fn returns_true(text: &str) -> bool {
|
|
566
|
+
text.contains("=> true") || text.contains("return true") || text.contains(": true")
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
fn returns_false(text: &str) -> bool {
|
|
570
|
+
text.contains("=> false") || text.contains("return false") || text.contains(": false")
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
fn following_window(source: &str, index: usize, lines: usize) -> &str {
|
|
574
|
+
let mut end = index;
|
|
575
|
+
for _ in 0..lines {
|
|
576
|
+
end = source[end..]
|
|
577
|
+
.find('\n')
|
|
578
|
+
.map_or(source.len(), |relative| end + relative + 1);
|
|
579
|
+
if end == source.len() {
|
|
580
|
+
break;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
&source[index..end]
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
fn line_at(source: &str, index: usize) -> &str {
|
|
587
|
+
let start = source[..index]
|
|
588
|
+
.rfind('\n')
|
|
589
|
+
.map_or(0, |position| position + 1);
|
|
590
|
+
let end = source[index..]
|
|
591
|
+
.find('\n')
|
|
592
|
+
.map_or(source.len(), |position| index + position);
|
|
593
|
+
&source[start..end]
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
fn redact_line(line: &str) -> String {
|
|
597
|
+
let mut redacted = String::new();
|
|
598
|
+
let mut index = 0;
|
|
599
|
+
let bytes = line.as_bytes();
|
|
600
|
+
while index < bytes.len() {
|
|
601
|
+
if matches!(bytes[index], b'\'' | b'"') {
|
|
602
|
+
let quote = bytes[index] as char;
|
|
603
|
+
redacted.push(quote);
|
|
604
|
+
redacted.push_str("<redacted>");
|
|
605
|
+
redacted.push(quote);
|
|
606
|
+
if let Some((_, end)) = read_string(line, index) {
|
|
607
|
+
index = end;
|
|
608
|
+
continue;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
redacted.push(bytes[index] as char);
|
|
612
|
+
index += 1;
|
|
613
|
+
}
|
|
614
|
+
redacted.trim().to_owned()
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
fn is_comment_match(source: &str, index: usize) -> bool {
|
|
618
|
+
let line_start = source[..index]
|
|
619
|
+
.rfind('\n')
|
|
620
|
+
.map_or(0, |position| position + 1);
|
|
621
|
+
if source[line_start..index].contains("//") {
|
|
622
|
+
return true;
|
|
623
|
+
}
|
|
624
|
+
let last_block_open = source[..index].rfind("/*");
|
|
625
|
+
let last_block_close = source[..index].rfind("*/");
|
|
626
|
+
last_block_open.is_some_and(|open| last_block_close.is_none_or(|close| open > close))
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
fn location_for_index(source: &str, index: usize) -> Location {
|
|
630
|
+
let line = source[..index]
|
|
631
|
+
.bytes()
|
|
632
|
+
.filter(|byte| *byte == b'\n')
|
|
633
|
+
.count()
|
|
634
|
+
+ 1;
|
|
635
|
+
let column = source[..index]
|
|
636
|
+
.rfind('\n')
|
|
637
|
+
.map_or(index, |position| index - position - 1);
|
|
638
|
+
Location { line, column }
|
|
639
|
+
}
|