π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[server] Mask email domain in public collection participants
Neeraj Gupta55d84114982e
diff --git a/server/pkg/controller/public/comments.go b/server/pkg/controller/public/comments.goindex af503f0de6..bb8bcecabf 100644--- a/server/pkg/controller/public/comments.go+++ b/server/pkg/controller/public/comments.go@@ -178,7 +178,7 @@ func (c *CommentsController) Participants(ctx context.Context, collectionID int6}participants = append(participants, participant{UserID: id,- EmailMasked: emailUtil.GetMaskedEmail(user.Email),+ EmailMasked: emailUtil.GetMaskedEmailForPublic(user.Email),})}// Sort by userID for consistent orderingdiff --git a/server/pkg/utils/email/email.go b/server/pkg/utils/email/email.goindex 792234c72f..93ceaaaa99 100644--- a/server/pkg/utils/email/email.go+++ b/server/pkg/utils/email/email.go@@ -354,6 +354,43 @@ func GetMaskedEmail(email string) string {}}+// GetMaskedEmailForPublic masks an email for public display.+// Format: first 2 chars of username + masked remainder + @ + first char of domain + masked middle + last char of domain+func GetMaskedEmailForPublic(email string) string {+ email = strings.TrimSpace(email)+ at := strings.LastIndex(email, "@")+ if at <= 0 || at == len(email)-1 {+ return "[invalid_email]"+ }+ username := email[:at]+ domain := email[at+1:]++ maskedUsername := maskForPublicUsername(username)+ maskedDomain := maskForPublicDomain(domain)++ return maskedUsername + "@" + maskedDomain+}++// maskForPublicUsername masks a username keeping the first 2 runes visible.+// Remaining runes are replaced with asterisks.+func maskForPublicUsername(s string) string {+ runes := []rune(s)+ if len(runes) <= 2 {+ return s+ }+ return string(runes[:2]) + strings.Repeat("*", len(runes)-2)+}++// maskForPublicDomain masks a domain showing first and last rune.+// Middle runes are replaced with asterisks.+func maskForPublicDomain(domain string) string {+ runes := []rune(domain)+ if len(runes) <= 2 {+ return domain+ }+ return string(runes[0]) + strings.Repeat("*", len(runes)-2) + string(runes[len(runes)-1])+}+// GetMaskedEmailWithHint masks both the username and non-TLD domain segments while keeping helpful hints.func GetMaskedEmailWithHint(email string) string {email = strings.TrimSpace(email)diff --git a/server/pkg/utils/email/email_test.go b/server/pkg/utils/email/email_test.gonew file mode 100644index 0000000000..bdcf3b3df9--- /dev/null+++ b/server/pkg/utils/email/email_test.go@@ -0,0 +1,98 @@+package email++import (+ "testing"++ "github.com/stretchr/testify/assert"+)++func TestGetMaskedEmailForPublic(t *testing.T) {+ tests := []struct {+ name string+ email string+ expected string+ }{+ {+ name: "standard email",+ email: "[email protected]",+ expected: "jo**@e********o",+ },+ {+ name: "gmail address",+ email: "[email protected]",+ expected: "jo******@g*******m",+ },+ {+ name: "short username 2 chars",+ email: "[email protected]",+ expected: "ab@e*********m",+ },+ {+ name: "short username 1 char",+ email: "[email protected]",+ expected: "a@e*********m",+ },+ {+ name: "short domain 2 chars",+ email: "test@ab",+ expected: "te**@ab",+ },+ {+ name: "short domain 1 char",+ email: "test@a",+ expected: "te**@a",+ },+ {+ name: "email with spaces trimmed",+ email: " [email protected] ",+ expected: "us**@d********m",+ },+ {+ name: "invalid email no @",+ email: "invalidemail",+ expected: "[invalid_email]",+ },+ {+ name: "invalid email @ at start",+ email: "@domain.com",+ expected: "[invalid_email]",+ },+ {+ name: "invalid email @ at end",+ email: "user@",+ expected: "[invalid_email]",+ },+ {+ name: "empty string",+ email: "",+ expected: "[invalid_email]",+ },+ {+ name: "long username and domain",+ email: "[email protected]",+ expected: "ve**************@v****************g",+ },+ {+ name: "unicode username",+ email: "η¨ζ·ε@example.com",+ expected: "η¨ζ·*@e*********m",+ },+ {+ name: "unicode domain",+ email: "test@δΎγ.jp",+ expected: "te**@δΎ***p",+ },+ {+ name: "mixed unicode",+ email: "ζ₯ζ¬θͺ@γγ‘γ€γ³.jp",+ expected: "ζ₯ζ¬*@γ*****p",+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ result := GetMaskedEmailForPublic(tt.email)+ assert.Equal(t, tt.expected, result)+ })+ }+}