mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-12-23 21:06:58 +00:00
Redact webhook authorize header on display
This commit is contained in:
committed by
Clément Renault
parent
75f036e087
commit
710483d69c
@@ -11,6 +11,24 @@ pub struct Webhook {
|
|||||||
pub headers: BTreeMap<String, String>,
|
pub headers: BTreeMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Webhook {
|
||||||
|
pub fn redact_authorization_header(&mut self) {
|
||||||
|
// headers are case insensitive, so to make the redaction robust we iterate over qualifying headers
|
||||||
|
// rather than getting one canonical `Authorization` header.
|
||||||
|
for value in self
|
||||||
|
.headers
|
||||||
|
.iter_mut()
|
||||||
|
.filter_map(|(name, value)| name.eq_ignore_ascii_case("authorization").then_some(value))
|
||||||
|
{
|
||||||
|
if value.starts_with("Bearer ") {
|
||||||
|
crate::settings::hide_secret(value, "Bearer ".len());
|
||||||
|
} else {
|
||||||
|
crate::settings::hide_secret(value, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Default, Clone, PartialEq)]
|
#[derive(Debug, Serialize, Default, Clone, PartialEq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct WebhooksView {
|
pub struct WebhooksView {
|
||||||
|
|||||||
@@ -99,7 +99,8 @@ pub(super) struct WebhookWithMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl WebhookWithMetadata {
|
impl WebhookWithMetadata {
|
||||||
pub fn from(uuid: Uuid, webhook: Webhook) -> Self {
|
pub fn from(uuid: Uuid, mut webhook: Webhook) -> Self {
|
||||||
|
webhook.redact_authorization_header();
|
||||||
Self { uuid, is_editable: uuid != Uuid::nil(), webhook }
|
Self { uuid, is_editable: uuid != Uuid::nil(), webhook }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user