Skip to content

Commit

Permalink
Slack Webhook URL redacted from debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
abdolence committed Oct 8, 2022
1 parent 65baf50 commit 65ef9fa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "slack-morphism"
version = "1.3.0"
version = "1.3.1-alpha.0"
authors = ["Abdulla Abdurakhmanov <me@abdolence.dev>"]
edition = "2021"
license = "Apache-2.0"
Expand Down
1 change: 1 addition & 0 deletions src/api/webhook.rs
Expand Up @@ -33,6 +33,7 @@ where
rate_control_params: Some(&POST_WEBHOOK_SPECIAL_LIMIT_RATE_CTL),
token: None,
tracing_span: &http_webhook_span,
is_sensitive_url: true,
};

self.http_api
Expand Down
5 changes: 5 additions & 0 deletions src/client.rs
Expand Up @@ -52,6 +52,7 @@ pub struct SlackClientApiCallContext<'a> {
pub rate_control_params: Option<&'a SlackApiMethodRateControlConfig>,
pub token: Option<&'a SlackApiToken>,
pub tracing_span: &'a Span,
pub is_sensitive_url: bool,
}

pub trait SlackClientHttpConnector {
Expand Down Expand Up @@ -238,6 +239,7 @@ where
rate_control_params,
token: Some(self.token),
tracing_span: &self.span,
is_sensitive_url: false,
};

self.client
Expand All @@ -262,6 +264,7 @@ where
rate_control_params,
token: Some(self.token),
tracing_span: &self.span,
is_sensitive_url: false,
};

self.client
Expand All @@ -285,6 +288,7 @@ where
rate_control_params,
token: Some(self.token),
tracing_span: &self.span,
is_sensitive_url: false,
};

self.client
Expand All @@ -308,6 +312,7 @@ where
rate_control_params,
token: Some(self.token),
tracing_span: &self.span,
is_sensitive_url: false,
};

self.client
Expand Down
20 changes: 19 additions & 1 deletion src/hyper_tokio/connector.rs
Expand Up @@ -69,7 +69,24 @@ impl<H: 'static + Send + Sync + Clone + connect::Connect> SlackClientHyperConnec
where
RS: for<'de> serde::de::Deserialize<'de>,
{
let uri_str = request.uri().to_string();
let uri_str = if context.is_sensitive_url {
format!(
"{}://{}/<redacted>",
request
.uri()
.scheme()
.map(|scheme| scheme.to_string())
.unwrap_or_else(|| "unknown-scheme".to_string()),
request
.uri()
.host()
.map(|host| host.to_string())
.unwrap_or_else(|| "unknown-host".to_string())
)
} else {
request.uri().to_string()
};

context.tracing_span.in_scope(|| {
debug!(
slack_uri = uri_str.as_str(),
Expand Down Expand Up @@ -287,6 +304,7 @@ impl<H: 'static + Send + Sync + Clone + connect::Connect> SlackClientHttpConnect
rate_control_params: None,
token: None,
tracing_span: &http_oauth_span,
is_sensitive_url: false,
};

self.send_rate_controlled_request(
Expand Down

0 comments on commit 65ef9fa

Please sign in to comment.