feat: 移除notification+system历史发信地址兼容并发布V2.13.1部署包
Some checks are pending
Security Checks / security (push) Waiting to run
Some checks are pending
Security Checks / security (push) Waiting to run
This commit is contained in:
parent
0d2826500d
commit
596b233999
@ -7,11 +7,9 @@ import (
|
||||
|
||||
var ErrNotificationRecipient = errors.New("notification address does not accept mail")
|
||||
|
||||
// notification 为主发信账号;notification+system 为历史保留兼容账号。
|
||||
// 两者均为系统保留地址,禁止普通用户占用,且拒收任何外部来信。
|
||||
// notification 为系统专属发信账号,禁止普通用户占用,且拒收任何外部来信。
|
||||
const (
|
||||
NotificationLocalPart = "notification"
|
||||
LegacyNotificationLocalPart = "notification+system"
|
||||
NotificationLocalPart = "notification"
|
||||
)
|
||||
|
||||
func NotificationAddress(domain string) string {
|
||||
@ -21,19 +19,12 @@ func NotificationAddress(domain string) string {
|
||||
return NotificationLocalPart + "@" + domain
|
||||
}
|
||||
|
||||
func LegacyNotificationAddress(domain string) string {
|
||||
if domain == "" {
|
||||
return ""
|
||||
}
|
||||
return LegacyNotificationLocalPart + "@" + domain
|
||||
}
|
||||
|
||||
func IsNotificationAddress(address string, domains []string) bool {
|
||||
parts := strings.Split(strings.ToLower(strings.TrimSpace(address)), "@")
|
||||
if len(parts) != 2 {
|
||||
return false
|
||||
}
|
||||
if parts[0] != NotificationLocalPart && parts[0] != LegacyNotificationLocalPart {
|
||||
if parts[0] != NotificationLocalPart {
|
||||
return false
|
||||
}
|
||||
for _, domain := range domains {
|
||||
@ -52,5 +43,5 @@ func IsAuthorizedNotificationSender(address, domain string) bool {
|
||||
if len(parts) != 2 || !strings.EqualFold(parts[1], domain) {
|
||||
return false
|
||||
}
|
||||
return parts[0] == NotificationLocalPart || parts[0] == LegacyNotificationLocalPart
|
||||
return parts[0] == NotificationLocalPart
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package validation
|
||||
package validation
|
||||
|
||||
import "testing"
|
||||
|
||||
@ -9,19 +9,13 @@ func TestNotificationAddressAndSenderValidation(t *testing.T) {
|
||||
t.Fatalf("NotificationAddress want notification@example.com, got %s", primarySender)
|
||||
}
|
||||
|
||||
legacySender := LegacyNotificationAddress(domain)
|
||||
if legacySender != "notification+system@example.com" {
|
||||
t.Fatalf("LegacyNotificationAddress want notification+system@example.com, got %s", legacySender)
|
||||
}
|
||||
|
||||
domains := []string{"example.com", "other.com"}
|
||||
|
||||
// 验证 IsNotificationAddress:主地址和历史地址均应被识别为通知地址
|
||||
if !IsNotificationAddress("notification@example.com", domains) {
|
||||
t.Fatalf("notification@example.com should be recognized as notification address")
|
||||
}
|
||||
if !IsNotificationAddress("notification+system@example.com", domains) {
|
||||
t.Fatalf("notification+system@example.com should be recognized as notification address")
|
||||
if IsNotificationAddress("notification+system@example.com", domains) {
|
||||
t.Fatalf("notification+system@example.com should NOT be notification address")
|
||||
}
|
||||
if !IsNotificationAddress("NOTIFICATION@OTHER.COM", domains) {
|
||||
t.Fatalf("case insensitive notification address check failed")
|
||||
@ -30,12 +24,11 @@ func TestNotificationAddressAndSenderValidation(t *testing.T) {
|
||||
t.Fatalf("user@example.com should NOT be notification address")
|
||||
}
|
||||
|
||||
// 验证 IsAuthorizedNotificationSender
|
||||
if !IsAuthorizedNotificationSender("notification@example.com", domain) {
|
||||
t.Fatalf("notification@example.com should be authorized sender")
|
||||
}
|
||||
if !IsAuthorizedNotificationSender("notification+system@example.com", domain) {
|
||||
t.Fatalf("notification+system@example.com should be authorized sender")
|
||||
if IsAuthorizedNotificationSender("notification+system@example.com", domain) {
|
||||
t.Fatalf("notification+system@example.com should NOT be authorized notification sender")
|
||||
}
|
||||
if IsAuthorizedNotificationSender("attacker@example.com", domain) {
|
||||
t.Fatalf("attacker@example.com should NOT be authorized notification sender")
|
||||
|
||||
@ -57,7 +57,7 @@
|
||||
<el-icon><Setting /></el-icon>
|
||||
<span class="settings-label">{{ lang.settings }}</span>
|
||||
</div>
|
||||
<span class="app-version-badge">V2.13.0</span>
|
||||
<span class="app-version-badge">V2.13.1</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user