Skip to content
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
5 changes: 5 additions & 0 deletions components/fxa-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ impl GetErrorHandling for Error {
.report_error("fxa-state-machine-error")
}
Error::OriginMismatch(_) => ErrorHandling::convert(FxaError::OriginMismatch),
// Just log a warning for these. They're already reported in `parse_url` and
// `join_url`.
Error::MalformedUrl { .. } => {
ErrorHandling::convert(FxaError::Other(self.to_string())).log_warning()
}
_ => ErrorHandling::convert(FxaError::Other(self.to_string()))
.report_error("fxa-client-other-error"),
}
Expand Down
2 changes: 1 addition & 1 deletion components/fxa-client/src/internal/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl Config {

pub fn token_server_endpoint_url(&self) -> Result<Url> {
if let Some(token_server_url_override) = &self.token_server_url_override {
return util::parse_url(
return util::parse_user_url(
token_server_url_override,
"token_server_endpoint_url (override)",
);
Expand Down
38 changes: 32 additions & 6 deletions components/fxa-client/src/internal/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use crate::{Error, Result};
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
use error_support::report_error;
use rc_crypto::rand;
use std::time::{SystemTime, UNIX_EPOCH};

Expand Down Expand Up @@ -54,16 +55,41 @@ impl Xorable for [u8] {
}

pub fn parse_url(url: &str, when: impl Into<String>) -> Result<url::Url> {
url::Url::parse(url).map_err(|_| Error::MalformedUrl {
sanitized_url: sanitized_url(url),
when: when.into(),
url::Url::parse(url).map_err(|_| {
let sanitized_url = sanitized_url(url);
let when = when.into();
report_error!("fxa-client-malformed-url", "{sanitized_url} ({when})");
Error::MalformedUrl {
sanitized_url,
when,
}
})
}

/// Parse a user-specified URL
///
/// This works the same as [parse_url], except we don't report errors to sentry for malformed URL.
/// (https://bugzilla.mozilla.org/show_bug.cgi?id=2007419)
pub fn parse_user_url(url: &str, when: impl Into<String>) -> Result<url::Url> {
url::Url::parse(url).map_err(|_| {
let sanitized_url = sanitized_url(url);
let when = when.into();
Error::MalformedUrl {
sanitized_url,
when,
}
})
}

pub fn join_url(url: &url::Url, path: &str, when: impl Into<String>) -> Result<url::Url> {
url.join(path).map_err(|_| Error::MalformedUrl {
sanitized_url: sanitized_url(url.as_str()),
when: when.into(),
url.join(path).map_err(|_| {
let sanitized_url = sanitized_url(url.as_str());
let when = when.into();
report_error!("fxa-client-malformed-url", "{sanitized_url} ({when})");
Error::MalformedUrl {
sanitized_url,
when,
}
})
}

Expand Down