From 5db58f930e3a72dbb6f4cec852ee2e5e9068e38d Mon Sep 17 00:00:00 2001 From: Chaehyeon Lee Date: Fri, 24 Jul 2026 16:45:41 +0900 Subject: [PATCH] fix(webhook): remove slack channel name check (#38608) Users should know what they are doing, don't check everything, especially for that we don't understand. Fixes #23840 --------- Co-authored-by: wxiaoguang --- services/webhook/slack.go | 13 +++++-------- services/webhook/slack_test.go | 19 ------------------- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/services/webhook/slack.go b/services/webhook/slack.go index 368a92607b9..23fd5a5b16d 100644 --- a/services/webhook/slack.go +++ b/services/webhook/slack.go @@ -7,7 +7,6 @@ import ( "context" "fmt" "net/http" - "regexp" "strings" webhook_model "gitea.dev/models/webhook" @@ -317,12 +316,10 @@ func init() { RegisterWebhookRequester(webhook_module.SLACK, newSlackRequest) } -var slackChannel = regexp.MustCompile(`^#?[a-z0-9_-]{1,80}$`) - -// IsValidSlackChannel validates a channel name conforms to what slack expects: -// https://api.slack.com/methods/conversations.rename#naming -// Conversation names can only contain lowercase letters, numbers, hyphens, and underscores, and must be 80 characters or less. -// Gitea accepts if it starts with a #. func IsValidSlackChannel(name string) bool { - return slackChannel.MatchString(name) + // Some documents: https://api.slack.com/methods/conversations.rename#naming + // 1. Internal channel name should "only contain lowercase letters, numbers, hyphens, and underscores, and must be 80 characters or less" + // 2. Slack would also "modify it to meet the above criteria" + // Since we know nothing about the details, don't do any validation here. + return name != "" } diff --git a/services/webhook/slack_test.go b/services/webhook/slack_test.go index ab1a3798c8b..f49e7203e09 100644 --- a/services/webhook/slack_test.go +++ b/services/webhook/slack_test.go @@ -191,22 +191,3 @@ func TestSlackJSONPayload(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "[:] 2 new commits pushed by user1", body.Text) } - -func TestIsValidSlackChannel(t *testing.T) { - tt := []struct { - channelName string - expected bool - }{ - {"gitea", true}, - {"#gitea", true}, - {" ", false}, - {"#", false}, - {" #", false}, - {"gitea ", false}, - {" gitea", false}, - } - - for _, v := range tt { - assert.Equal(t, v.expected, IsValidSlackChannel(v.channelName)) - } -}