Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't log username/password in binary mirror proxy URLs #1758

Merged
merged 5 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/rover-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ crossbeam-channel = { workspace = true }
notify = { workspace = true }
rayon = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
tracing = { workspace = true }
url = { workspace = true }
2 changes: 2 additions & 0 deletions crates/rover-std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ mod emoji;
mod error;
mod fs;
mod style;
mod url;

pub mod prompt;
pub use emoji::Emoji;
pub use error::RoverStdError;
pub use fs::Fs;
pub use style::is_no_color_set;
pub use style::Style;
pub use url::sanitize_url;
42 changes: 42 additions & 0 deletions crates/rover-std/src/url.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use url::Url;

pub fn sanitize_url(url: &str) -> Option<String> {
Url::parse(url).ok().and_then(|mut parsed_url| {
if (parsed_url.username() != "" && parsed_url.set_username("").is_err())
|| parsed_url.set_password(None).is_err()
{
None
} else {
Some(parsed_url.to_string())
}
})
}

#[cfg(test)]
mod tests {
use super::*;

const UNAUTHENTICATED_URL: &str = "https://rover.apollo.dev/nix/latest";
const AUTHENTICATED_URL: &str = "https://username:[email protected]/nix/latest";
const SANITIZED_AUTHENTICATED_URL: &str = "https://customer.proxy/nix/latest";

const INVALID_URL: &str = "not-a-url";

#[test]
fn it_leaves_unauthenticated_url_alone() {
let sanitized_url = sanitize_url(UNAUTHENTICATED_URL);
assert_eq!(sanitized_url, Some(UNAUTHENTICATED_URL.to_string()));
}

#[test]
fn it_sanitizes_authenticated_url() {
let sanitized_url = sanitize_url(AUTHENTICATED_URL);
assert_eq!(sanitized_url, Some(SANITIZED_AUTHENTICATED_URL.to_string()));
}

#[test]
fn it_returns_none_for_invalid_url() {
let sanitized_url = sanitize_url(INVALID_URL);
assert_eq!(sanitized_url, None);
}
}
9 changes: 7 additions & 2 deletions src/command/install/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::{anyhow, Context};
use apollo_federation_types::config::{FederationVersion, PluginVersion, RouterVersion};
use binstall::Installer;
use camino::Utf8PathBuf;
use rover_std::Fs;
use rover_std::{sanitize_url, Fs};
use semver::Version;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -330,7 +330,12 @@ impl PluginInstaller {
fn do_install(&self, plugin: &Plugin, is_latest: bool) -> RoverResult<Option<Utf8PathBuf>> {
let plugin_name = plugin.get_name();
let plugin_tarball_url = plugin.get_tarball_url()?;
eprintln!("downloading the '{plugin_name}' plugin from {plugin_tarball_url}");
// only print the download message if the username and password have been stripped from the URL
if let Some(sanitized_url) = sanitize_url(&plugin_tarball_url) {
eprintln!("downloading the '{plugin_name}' plugin from {sanitized_url}");
} else {
eprintln!("downloading the '{plugin_name}' plugin");
}
Ok(self.rover_installer.install_plugin(
&plugin_name,
&plugin_tarball_url,
Expand Down