Rewrite placeholders in query parameter values. Returns `Some((resolved_query, redacted_query))` if any placeholders were found.
(
query: &str,
resolver: &SecretResolver,
)
| 868 | /// |
| 869 | /// Returns `Some((resolved_query, redacted_query))` if any placeholders were found. |
| 870 | fn rewrite_uri_query_params( |
| 871 | query: &str, |
| 872 | resolver: &SecretResolver, |
| 873 | ) -> Result<Option<(String, String)>, UnresolvedPlaceholderError> { |
| 874 | if !contains_reserved_credential_marker(query) { |
| 875 | return Ok(None); |
| 876 | } |
| 877 | |
| 878 | let mut resolved_params = Vec::new(); |
| 879 | let mut redacted_params = Vec::new(); |
| 880 | let mut any_rewritten = false; |
| 881 | |
| 882 | for param in query.split('&') { |
| 883 | if let Some((key, value)) = param.split_once('=') { |
| 884 | let decoded_value = percent_decode(value); |
| 885 | if contains_raw_reserved_marker(&decoded_value) { |
| 886 | let mut rewritten = decoded_value.clone(); |
| 887 | let replacements = |
| 888 | resolver.rewrite_text_placeholders(&mut rewritten, "query_param")?; |
| 889 | if replacements == 0 || contains_raw_reserved_marker(&rewritten) { |
| 890 | return Err(UnresolvedPlaceholderError { |
| 891 | location: "query_param", |
| 892 | }); |
| 893 | } |
| 894 | resolved_params.push(format!("{key}={}", percent_encode_query(&rewritten))); |
| 895 | redacted_params.push(format!("{key}=[CREDENTIAL]")); |
| 896 | any_rewritten = true; |
| 897 | } else { |
| 898 | resolved_params.push(param.to_string()); |
| 899 | redacted_params.push(param.to_string()); |
| 900 | } |
| 901 | } else { |
| 902 | resolved_params.push(param.to_string()); |
| 903 | redacted_params.push(param.to_string()); |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | if !any_rewritten { |
| 908 | return Ok(None); |
| 909 | } |
| 910 | |
| 911 | Ok(Some((resolved_params.join("&"), redacted_params.join("&")))) |
| 912 | } |
| 913 | |
| 914 | // --------------------------------------------------------------------------- |
| 915 | // Public rewrite API |
no test coverage detected