Skip to content

Commit a148a15

Browse files
committed
preparing for v1.100.0
1 parent d125d68 commit a148a15

4 files changed

Lines changed: 14 additions & 33 deletions

File tree

crates/kingfisher-scanner/src/validation/utils.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ pub fn process_captures(captures: &SerializableCaptures) -> Vec<(String, String,
3232
/// that should be paired with a secret key.
3333
pub fn find_closest_variable(
3434
captures: &[(String, String, usize, usize)],
35-
target_value: &String,
35+
target_value: &str,
3636
target_variable_name: &str,
3737
search_variable_name: &str,
3838
) -> Option<String> {
3939
// Collect the positions of the target variable for the provided value so we can
4040
// compare relative offsets with candidate variables.
4141
let mut target_positions = Vec::new();
4242
for (name, value, start, end) in captures {
43-
if name == target_variable_name && value == target_value {
43+
if name == target_variable_name && value.as_str() == target_value {
4444
target_positions.push((*start, *end));
4545
}
4646
}
@@ -138,8 +138,7 @@ mod tests {
138138
("AKID".to_string(), "following".to_string(), 180usize, 200usize),
139139
];
140140

141-
let result =
142-
find_closest_variable(&captures, &"secret".to_string(), "TOKEN", "AKID").unwrap();
141+
let result = find_closest_variable(&captures, "secret", "TOKEN", "AKID").unwrap();
143142

144143
assert_eq!(result, "preceding".to_string());
145144
}
@@ -151,8 +150,7 @@ mod tests {
151150
("AKID".to_string(), "after".to_string(), 60usize, 80usize),
152151
];
153152

154-
let result =
155-
find_closest_variable(&captures, &"secret".to_string(), "TOKEN", "AKID").unwrap();
153+
let result = find_closest_variable(&captures, "secret", "TOKEN", "AKID").unwrap();
156154

157155
assert_eq!(result, "after".to_string());
158156
}

src/scanner/validation.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ pub async fn run_secret_validation(
725725
let mut by_key: FxHashMap<String, Vec<OwnedBlobMatch>> =
726726
FxHashMap::default();
727727
for om in owned {
728-
by_key.entry(build_cache_key(&om, &dep_vars)).or_default().push(om);
728+
by_key.entry(build_cache_key(&om)).or_default().push(om);
729729
}
730730
let reps: Vec<_> =
731731
by_key.into_iter().map(|(_k, mut v)| (v.remove(0), v)).collect();
@@ -859,7 +859,7 @@ async fn validate_single(
859859
validation_retries: u32,
860860
max_body_len: usize,
861861
) {
862-
let cache_key = build_cache_key(om, dep_vars);
862+
let cache_key = build_cache_key(om);
863863
// Check cache first
864864
if let Some(cached) = cache.get(&cache_key) {
865865
om.validation_success = cached.is_valid;
@@ -956,12 +956,8 @@ fn is_counted_validation_status(status: StatusCode) -> bool {
956956
!matches!(status, StatusCode::CONTINUE | StatusCode::PRECONDITION_REQUIRED)
957957
}
958958

959-
// Helper to compute the cache key for an OwnedBlobMatch
960-
fn build_cache_key(
961-
om: &OwnedBlobMatch,
962-
dep_vars: &FxHashMap<String, Vec<(String, OffsetSpan)>>,
963-
) -> String {
964-
// Build key
959+
// Helper to compute the cache key for an OwnedBlobMatch.
960+
fn build_cache_key(om: &OwnedBlobMatch) -> String {
965961
let capture0 = om.captures.captures.get(0).map_or(String::new(), |c| c.raw_value().to_string());
966962

967963
let has_context_dependency = om
@@ -982,16 +978,7 @@ fn build_cache_key(
982978
);
983979
}
984980

985-
let dep_vars_str = dep_vars
986-
.get(om.rule.id())
987-
.map(|hm| {
988-
let mut sorted: Vec<_> = hm.iter().collect();
989-
sorted.sort_by(|(k, _), (k2, _)| k.cmp(k2));
990-
sorted.into_iter().map(|(k, v)| format!("{}={}", k, v)).collect::<Vec<_>>().join("|")
991-
})
992-
.unwrap_or_default();
993-
994-
format!("{}|{}|{}", om.rule.name(), capture0, dep_vars_str)
981+
format!("{}|{}", om.rule.name(), capture0)
995982
}
996983

997984
fn maybe_record_access_map(om: &OwnedBlobMatch, collector: Option<&AccessMapCollector>) {

src/validation.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,9 +1551,7 @@ fn aws_akid_candidates(
15511551
) -> Vec<String> {
15521552
let mut candidates = Vec::new();
15531553

1554-
if let Some(closest) =
1555-
utils::find_closest_variable(captured_values, &secret.to_string(), "TOKEN", "AKID")
1556-
{
1554+
if let Some(closest) = utils::find_closest_variable(captured_values, secret, "TOKEN", "AKID") {
15571555
candidates.push((0usize, closest));
15581556
}
15591557

src/validation/utils.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,15 @@ pub fn process_captures(captures: &SerializableCaptures) -> Vec<(String, String,
153153

154154
pub fn find_closest_variable(
155155
captures: &[(String, String, usize, usize)],
156-
target_value: &String,
156+
target_value: &str,
157157
target_variable_name: &str,
158158
search_variable_name: &str,
159159
) -> Option<String> {
160160
// Collect the positions of the target variable for the provided value so we can
161161
// compare relative offsets with candidate variables.
162162
let mut target_positions = Vec::new();
163163
for (name, value, start, end) in captures {
164-
if name == target_variable_name && value == target_value {
164+
if name == target_variable_name && value.as_str() == target_value {
165165
target_positions.push((*start, *end));
166166
}
167167
}
@@ -346,8 +346,7 @@ mod tests {
346346
("AKID".to_string(), "following".to_string(), 180usize, 200usize),
347347
];
348348

349-
let result =
350-
find_closest_variable(&captures, &"secret".to_string(), "TOKEN", "AKID").unwrap();
349+
let result = find_closest_variable(&captures, "secret", "TOKEN", "AKID").unwrap();
351350

352351
assert_eq!(result, "preceding".to_string());
353352
}
@@ -359,8 +358,7 @@ mod tests {
359358
("AKID".to_string(), "after".to_string(), 60usize, 80usize),
360359
];
361360

362-
let result =
363-
find_closest_variable(&captures, &"secret".to_string(), "TOKEN", "AKID").unwrap();
361+
let result = find_closest_variable(&captures, "secret", "TOKEN", "AKID").unwrap();
364362

365363
assert_eq!(result, "after".to_string());
366364
}

0 commit comments

Comments
 (0)