diff options
| author | David Lönnhager <david.l@mullvad.net> | 2022-06-15 10:11:04 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2022-06-15 17:53:41 +0200 |
| commit | a7934705d2dc89dcba6f11ebdbf59e0f596c9693 (patch) | |
| tree | a58db72a2860049b90491eb480859f4bd87bdb0b | |
| parent | 5e641dbf5be1583bc69c20df83a23060b551d3dd (diff) | |
| download | mullvadvpn-a7934705d2dc89dcba6f11ebdbf59e0f596c9693.tar.xz mullvadvpn-a7934705d2dc89dcba6f11ebdbf59e0f596c9693.zip | |
Redact home dir for device paths in problem reports
| -rw-r--r-- | mullvad-problem-report/src/lib.rs | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/mullvad-problem-report/src/lib.rs b/mullvad-problem-report/src/lib.rs index b5fdadc2fe..a9bdf79051 100644 --- a/mullvad-problem-report/src/lib.rs +++ b/mullvad-problem-report/src/lib.rs @@ -420,10 +420,7 @@ impl ProblemReport { } fn redact_home_dir(input: &str) -> Cow<'_, str> { - match dirs_next::home_dir() { - Some(home) => Cow::from(input.replace(home.to_string_lossy().as_ref(), "~")), - None => Cow::from(input), - } + redact_home_dir_inner(input, dirs_next::home_dir()) } fn redact_network_info(input: &str) -> Cow<'_, str> { @@ -505,6 +502,32 @@ impl ProblemReport { } } +fn redact_home_dir_inner(input: &str, home_dir: Option<PathBuf>) -> Cow<'_, str> { + match home_dir { + Some(home) => { + let out = input.replace(home.to_string_lossy().as_ref(), "~"); + + // On Windows, redact the prefix of any path that contains \Users\{user}. + #[cfg(target_os = "windows")] + { + let mut home = home; + let prefix = home.components().next(); + if let Some(prefix @ std::path::Component::Prefix(_)) = prefix.as_ref() { + home = home.strip_prefix(prefix).unwrap().to_path_buf(); + } + let expr = format!(r"[\w\\]+{}", regex::escape(&home.display().to_string())); + let regex = Regex::new(&expr).unwrap(); + + Cow::Owned(regex.replace_all(&out, "~").to_string()) + } + + #[cfg(not(target_os = "windows"))] + Cow::from(out) + } + None => Cow::from(input), + } +} + fn build_mac_regex() -> String { let octet = "[[:xdigit:]]{2}"; // 0 - ff |
