From 5d45545ca1f003305be272e092b6eb49d5a4cac2 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Tue, 9 Apr 2024 10:09:00 +0200 Subject: [PATCH] webhook deliver: keep Bearer prefix in history --- services/webhook/deliver.go | 8 +++++++- services/webhook/deliver_test.go | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/services/webhook/deliver.go b/services/webhook/deliver.go index d488b1725..8db1c7257 100644 --- a/services/webhook/deliver.go +++ b/services/webhook/deliver.go @@ -78,7 +78,13 @@ func Deliver(ctx context.Context, t *webhook_model.HookTask) error { } if authorization != "" { req.Header.Set("Authorization", authorization) - t.RequestInfo.Headers["Authorization"] = "******" + redacted := "******" + if strings.HasPrefix(authorization, "Bearer ") { + redacted = "Bearer " + redacted + } else if strings.HasPrefix(authorization, "Basic ") { + redacted = "Basic " + redacted + } + t.RequestInfo.Headers["Authorization"] = redacted } t.ResponseInfo = &webhook_model.HookResponse{ diff --git a/services/webhook/deliver_test.go b/services/webhook/deliver_test.go index c68933266..aa281de84 100644 --- a/services/webhook/deliver_test.go +++ b/services/webhook/deliver_test.go @@ -132,7 +132,7 @@ func TestWebhookDeliverAuthorizationHeader(t *testing.T) { } assert.True(t, hookTask.IsSucceed) - assert.Equal(t, "******", hookTask.RequestInfo.Headers["Authorization"]) + assert.Equal(t, "Bearer ******", hookTask.RequestInfo.Headers["Authorization"]) } func TestWebhookDeliverHookTask(t *testing.T) {