From aab6a799feff343a18847435940a7c5315383199 Mon Sep 17 00:00:00 2001 From: UsherFall <98513748+UsherFall@users.noreply.github.com> Date: Sun, 24 Sep 2023 18:35:58 +0800 Subject: [PATCH] fix: use client secret field for providers (#2355) * feat: fix key exposure problem * fix display bug --- email/provider.go | 4 +-- notification/matrix.go | 2 +- notification/provider.go | 18 ++++++------ object/email.go | 2 +- web/src/ProviderEditPage.js | 55 +++++++++++++++++++++---------------- 5 files changed, 45 insertions(+), 36 deletions(-) diff --git a/email/provider.go b/email/provider.go index 56b5ff7d..71949968 100644 --- a/email/provider.go +++ b/email/provider.go @@ -18,9 +18,9 @@ type EmailProvider interface { Send(fromAddress string, fromName, toAddress string, subject string, content string) error } -func GetEmailProvider(typ string, clientId string, clientSecret string, appId string, host string, port int, disableSsl bool) EmailProvider { +func GetEmailProvider(typ string, clientId string, clientSecret string, host string, port int, disableSsl bool) EmailProvider { if typ == "Azure ACS" { - return NewAzureACSEmailProvider(appId, host) + return NewAzureACSEmailProvider(clientSecret, host) } else { return NewSmtpEmailProvider(clientId, clientSecret, host, port, typ, disableSsl) } diff --git a/notification/matrix.go b/notification/matrix.go index ff077b06..af6a01f1 100644 --- a/notification/matrix.go +++ b/notification/matrix.go @@ -21,7 +21,7 @@ import ( "maunium.net/go/mautrix/id" ) -func NewMatrixProvider(userId string, roomId string, accessToken string, homeServer string) (*notify.Notify, error) { +func NewMatrixProvider(userId string, accessToken string, roomId string, homeServer string) (*notify.Notify, error) { matrixSrv, err := matrix.New(id.UserID(userId), id.RoomID(roomId), homeServer, accessToken) if err != nil { return nil, err diff --git a/notification/provider.go b/notification/provider.go index ed298f1c..a86af01d 100644 --- a/notification/provider.go +++ b/notification/provider.go @@ -18,27 +18,27 @@ import "github.com/casdoor/notify" func GetNotificationProvider(typ string, clientId string, clientSecret string, clientId2 string, clientSecret2 string, appId string, receiver string, method string, title string, metaData string) (notify.Notifier, error) { if typ == "Telegram" { - return NewTelegramProvider(appId, receiver) + return NewTelegramProvider(clientSecret, receiver) } else if typ == "Custom HTTP" { return NewCustomHttpProvider(receiver, method, title) } else if typ == "DingTalk" { - return NewDingTalkProvider(appId, receiver) + return NewDingTalkProvider(clientId, clientSecret) } else if typ == "Lark" { - return NewLarkProvider(receiver) + return NewLarkProvider(clientSecret) } else if typ == "Microsoft Teams" { - return NewMicrosoftTeamsProvider(receiver) + return NewMicrosoftTeamsProvider(clientSecret) } else if typ == "Bark" { - return NewBarkProvider(receiver) + return NewBarkProvider(clientSecret) } else if typ == "Pushover" { - return NewPushoverProvider(appId, receiver) + return NewPushoverProvider(clientSecret, receiver) } else if typ == "Pushbullet" { - return NewPushbulletProvider(appId, receiver) + return NewPushbulletProvider(clientSecret, receiver) } else if typ == "Slack" { - return NewSlackProvider(appId, receiver) + return NewSlackProvider(clientSecret, receiver) } else if typ == "Webpush" { return NewWebpushProvider(clientId, clientSecret, receiver) } else if typ == "Discord" { - return NewDiscordProvider(appId, receiver) + return NewDiscordProvider(clientSecret, receiver) } else if typ == "Google Chat" { return NewGoogleChatProvider(metaData) } else if typ == "Line" { diff --git a/object/email.go b/object/email.go index e393295b..0b217bfe 100644 --- a/object/email.go +++ b/object/email.go @@ -36,7 +36,7 @@ func getDialer(provider *Provider) *gomail.Dialer { } func SendEmail(provider *Provider, title string, content string, dest string, sender string) error { - emailProvider := email.GetEmailProvider(provider.Type, provider.ClientId, provider.ClientSecret, provider.AppId, provider.Host, provider.Port, provider.DisableSsl) + emailProvider := email.GetEmailProvider(provider.Type, provider.ClientId, provider.ClientSecret, provider.Host, provider.Port, provider.DisableSsl) fromAddress := provider.ClientId2 if fromAddress == "" { diff --git a/web/src/ProviderEditPage.js b/web/src/ProviderEditPage.js index 700598b0..f6ec64c6 100644 --- a/web/src/ProviderEditPage.js +++ b/web/src/ProviderEditPage.js @@ -172,6 +172,12 @@ class ProviderEditPage extends React.Component { } else { return Setting.getLabel(i18next.t("provider:Site key"), i18next.t("provider:Site key - Tooltip")); } + case "Notification": + if (provider.type === "DingTalk") { + return Setting.getLabel(i18next.t("provider:Access key"), i18next.t("provider:Access key - Tooltip")); + } else { + return Setting.getLabel(i18next.t("provider:Client ID"), i18next.t("provider:Client ID - Tooltip")); + } default: return Setting.getLabel(i18next.t("provider:Client ID"), i18next.t("provider:Client ID - Tooltip")); } @@ -180,7 +186,11 @@ class ProviderEditPage extends React.Component { getClientSecretLabel(provider) { switch (provider.category) { case "Email": - return Setting.getLabel(i18next.t("general:Password"), i18next.t("general:Password - Tooltip")); + if (provider.type === "Azure ACS") { + return Setting.getLabel(i18next.t("provider:Secret key"), i18next.t("provider:Secret key - Tooltip")); + } else { + return Setting.getLabel(i18next.t("general:Password"), i18next.t("general:Password - Tooltip")); + } case "SMS": if (provider.type === "Volc Engine SMS" || provider.type === "Amazon SNS" || provider.type === "Baidu Cloud SMS") { return Setting.getLabel(i18next.t("provider:Secret access key"), i18next.t("provider:Secret access key - Tooltip")); @@ -202,8 +212,10 @@ class ProviderEditPage extends React.Component { return Setting.getLabel(i18next.t("provider:Secret key"), i18next.t("provider:Secret key - Tooltip")); } case "Notification": - if (provider.type === "Line") { + if (provider.type === "Line" || provider.type === "Telegram" || provider.type === "Bark" || provider.type === "DingTalk" || provider.type === "Discord" || provider.type === "Slack" || provider.type === "Pushover" || provider.type === "Pushbullet") { return Setting.getLabel(i18next.t("provider:Secret key"), i18next.t("provider:Secret key - Tooltip")); + } else if (provider.type === "Lark" || provider.type === "Microsoft Teams") { + return Setting.getLabel(i18next.t("provider:Endpoint"), i18next.t("provider:Endpoint - Tooltip")); } else { return Setting.getLabel(i18next.t("provider:Client secret"), i18next.t("provider:Client secret - Tooltip")); } @@ -297,7 +309,7 @@ class ProviderEditPage extends React.Component { tooltip = i18next.t("provider:Project Id - Tooltip"); } } else if (provider.category === "Email") { - if (provider.type === "SUBMAIL" || provider.type === "Azure ACS") { + if (provider.type === "SUBMAIL") { text = i18next.t("provider:App ID"); tooltip = i18next.t("provider:App ID - Tooltip"); } @@ -305,7 +317,7 @@ class ProviderEditPage extends React.Component { if (provider.type === "Viber") { text = i18next.t("provider:Domain"); tooltip = i18next.t("provider:Domain - Tooltip"); - } else if (provider.type === "Telegram" || provider.type === "DingTalk" || provider.type === "Pushover" || provider.type === "Pushbullet" || provider.type === "Slack" || provider.type === "Discord" || provider.type === "Line" || provider.type === "Matrix" || provider.type === "Rocket Chat") { + } else if (provider.type === "Line" || provider.type === "Matrix" || provider.type === "Rocket Chat") { text = i18next.t("provider:App Key"); tooltip = i18next.t("provider:App Key - Tooltip"); } @@ -336,12 +348,9 @@ class ProviderEditPage extends React.Component { if (provider.type === "Telegram" || provider.type === "Pushover" || provider.type === "Pushbullet" || provider.type === "Slack" || provider.type === "Discord" || provider.type === "Line" || provider.type === "Twitter" || provider.type === "Reddit" || provider.type === "Rocket Chat" || provider.type === "Viber") { text = i18next.t("provider:Chat ID"); tooltip = i18next.t("provider:Chat ID - Tooltip"); - } else if (provider.type === "Custom HTTP" || provider.type === "Lark" || provider.type === "Microsoft Teams" || provider.type === "Webpush" || provider.type === "Matrix") { + } else if (provider.type === "Custom HTTP" || provider.type === "Webpush" || provider.type === "Matrix") { text = i18next.t("provider:Endpoint"); tooltip = i18next.t("provider:Endpoint - Tooltip"); - } else if (provider.type === "DingTalk" || provider.type === "Bark") { - text = i18next.t("provider:Secret Key"); - tooltip = i18next.t("provider:Secret Key - Tooltip"); } if (text === "" && tooltip === "") { @@ -626,24 +635,24 @@ class ProviderEditPage extends React.Component { } { (this.state.provider.category === "Captcha" && this.state.provider.type === "Default") || - (this.state.provider.category === "Email" && this.state.provider.type === "Azure ACS") || (this.state.provider.category === "Web3") || - (this.state.provider.category === "Storage" && this.state.provider.type === "Local File System" || - (this.state.provider.category === "Notification" && this.state.provider.type !== "Webpush" && this.state.provider.type !== "Line" && this.state.provider.type !== "Matrix" && this.state.provider.type !== "Twitter" && this.state.provider.type !== "Reddit" && this.state.provider.type !== "Rocket Chat" && this.state.provider.type !== "Viber")) ? null : ( + (this.state.provider.category === "Storage" && this.state.provider.type === "Local File System") || + (this.state.provider.category === "Notification" && (this.state.provider.type === "Google Chat" || this.state.provider.type === "Custom HTTP")) ? null : ( { - this.state.provider.type === "Line" ? null : ( - - - {this.getClientIdLabel(this.state.provider)} : - - - { - this.updateProviderField("clientId", e.target.value); - }} /> - - - ) + (this.state.provider.category === "Email" && this.state.provider.type === "Azure ACS") || + (this.state.provider.category === "Notification" && (this.state.provider.type === "Line" || this.state.provider.type === "Telegram" || this.state.provider.type === "Bark" || this.state.provider.type === "Discord" || this.state.provider.type === "Slack" || this.state.provider.type === "Pushbullet" || this.state.provider.type === "Pushover" || this.state.provider.type === "Lark" || this.state.provider.type === "Microsoft Teams")) ? null : ( + + + {this.getClientIdLabel(this.state.provider)} : + + + { + this.updateProviderField("clientId", e.target.value); + }} /> + + + ) }