diff --git a/src/processing/playlist_processor.rs b/src/processing/playlist_processor.rs index f2f3cfdaa..722d50ac2 100644 --- a/src/processing/playlist_processor.rs +++ b/src/processing/playlist_processor.rs @@ -29,6 +29,7 @@ use crate::repository::playlist_repository::persist_playlist; use crate::utils::default_utils::default_as_default; use crate::utils::download; use crate::{get_errors_notify_message, model::config, Config}; +use crate::utils::request_utils::mask_sensitive_info; fn is_valid(pli: &PlaylistItem, target: &ConfigTarget) -> bool { let provider = ValueProvider { pli: RefCell::new(pli) }; @@ -312,7 +313,7 @@ async fn process_source(cfg: Arc, source_idx: usize, user_targets: Arc

, source_idx: usize, user_targets: Arc

Ok(content), Err(e) => { - error!("cant download input url: {} => {}", url_str, e); + error!("cant download input url: {} => {}", mask_sensitive_info(url_str), mask_sensitive_info(e.to_string().as_str())); create_m3u_filter_error_result!(M3uFilterErrorKind::Notify, "Failed to download") } } @@ -83,7 +84,7 @@ pub async fn get_input_text_content(input: &ConfigInput, working_dir: &String, u match download_text_content(input, url_str, persist_filepath).await { Ok(content) => Ok(content), Err(e) => { - error!("cant download input url: {} => {}", url_str, e); + error!("cant download input url: {} => {}", mask_sensitive_info(url_str), mask_sensitive_info(e.to_string().as_str())); create_m3u_filter_error_result!(M3uFilterErrorKind::Notify, "Failed to download") } } @@ -253,7 +254,7 @@ async fn get_remote_content(input: &ConfigInput, url: &Url) -> Result { - debug!("Request took:{} {url}", format_elapsed_time(start_time.elapsed().as_secs())); + debug!("Request took:{} {}", format_elapsed_time(start_time.elapsed().as_secs()), mask_sensitive_info(url.to_string().as_str())); Ok(decoded_content) } Err(err) => Err(std::io::Error::new(ErrorKind::Other, format!("failed to plain text content {err}"))) @@ -276,7 +277,7 @@ async fn get_remote_content(input: &ConfigInput, url: &Url) -> Result) -> Result { if let Ok(url) = url_str.parse::() { if url.scheme() == "file" { - url.to_file_path().map_or_else(|()| Err(Error::new(ErrorKind::Unsupported, format!("Unknown file {url}"))), |file_path| if file_path.exists() { + url.to_file_path().map_or_else(|()| Err(Error::new(ErrorKind::Unsupported, format!("Unknown file {}", mask_sensitive_info(url_str)))), |file_path| if file_path.exists() { Ok(file_path) } else { Err(Error::new(ErrorKind::NotFound, format!("Unknown file {file_path:?}"))) @@ -302,7 +303,7 @@ pub async fn download_text_content_as_file(input: &ConfigInput, url_str: &str, w pub async fn download_text_content(input: &ConfigInput, url_str: &str, persist_filepath: Option) -> Result { if let Ok(url) = url_str.parse::() { let result = if url.scheme() == "file" { - url.to_file_path().map_or_else(|()| Err(Error::new(ErrorKind::Other, format!("Unknown file {url}"))), |file_path| get_local_file_content(&file_path)) + url.to_file_path().map_or_else(|()| Err(Error::new(ErrorKind::Other, format!("Unknown file {}", mask_sensitive_info(url_str)))), |file_path| get_local_file_content(&file_path)) } else { get_remote_content(input, &url).await }; @@ -322,7 +323,7 @@ pub async fn download_text_content(input: &ConfigInput, url_str: &str, persist_f async fn download_json_content(input: &ConfigInput, url: &str, persist_filepath: Option) -> Result { if log_enabled!(Level::Debug) { - debug!("downloading json content from {url}"); + debug!("downloading json content from {}", mask_sensitive_info(url)); } match download_text_content(input, url, persist_filepath).await { Ok(content) => { @@ -338,7 +339,7 @@ async fn download_json_content(input: &ConfigInput, url: &str, persist_filepath: pub async fn get_input_json_content(input: &ConfigInput, url: &str, persist_filepath: Option) -> Result { match download_json_content(input, url, persist_filepath).await { Ok(content) => Ok(content), - Err(e) => create_m3u_filter_error_result!(M3uFilterErrorKind::Notify, "cant download input url: {url} => {}", e) + Err(e) => create_m3u_filter_error_result!(M3uFilterErrorKind::Notify, "cant download input url: {} => {}", mask_sensitive_info(url), mask_sensitive_info(e.to_string().as_str())) } } // @@ -353,3 +354,17 @@ pub async fn get_input_json_content(input: &ConfigInput, url: &str, persist_file // } // None // } + + +pub fn mask_sensitive_info(query: &str) -> String { + let re_username = Regex::new(r"(username=)[^&]*").unwrap(); + let re_password = Regex::new(r"(password=)[^&]*").unwrap(); + let re_token = Regex::new(r"(token=)[^&]*").unwrap(); + + // Replace with "***" + let masked_query = re_username.replace_all(query, "$1***"); + let masked_query = re_password.replace_all(&masked_query, "$1***"); + let masked_query = re_token.replace_all(&masked_query, "$1***"); + + masked_query.to_string() +} \ No newline at end of file