Skip to content

Commit af0b6a3

Browse files
committed
Include tld in email obfuscation
1 parent 77ddd92 commit af0b6a3

File tree

4 files changed

+38
-34
lines changed

4 files changed

+38
-34
lines changed

backend/server/auth/handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func AccountHandler(w http.ResponseWriter, req *http.Request, id string) {
161161
return
162162
}
163163

164-
obscuredEmail, _ := utils.ObscureEmail(user.Email)
164+
obscuredEmail, _ := shared.ObscureEmail(user.Email)
165165
_ = json.NewEncoder(w).Encode(shared.AccountResponse{
166166
Email: obscuredEmail,
167167
PaymentID: user.PaymentID,

backend/server/html/handlers.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"yeetfile/backend/server/html/templates"
1212
"yeetfile/backend/server/session"
1313
"yeetfile/backend/server/upgrades"
14-
"yeetfile/backend/utils"
1514
"yeetfile/shared"
1615
"yeetfile/shared/endpoints"
1716
)
@@ -198,7 +197,7 @@ func AccountPageHandler(w http.ResponseWriter, req *http.Request, userID string)
198197

199198
successMsg, errorMsg := generateAccountMessages(req)
200199
hasHint := user.PasswordHint != nil && len(user.PasswordHint) > 0
201-
obscuredEmail, _ := utils.ObscureEmail(user.Email)
200+
obscuredEmail, _ := shared.ObscureEmail(user.Email)
202201
isPrevUpgraded := user.UpgradeExp.Year() >= 2024
203202

204203
_ = templates.ServeTemplate(

backend/utils/misc.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"crypto/sha1"
55
"encoding/base64"
66
"encoding/json"
7-
"errors"
87
"fmt"
98
"io"
109
"log"
@@ -238,36 +237,6 @@ func ParseSizeString(str string) int64 {
238237
return 0
239238
}
240239

241-
// ObscureEmail takes an email and strips out the majority of the address and
242-
// domain, adding "***" as an indicator of the obfuscation for both.
243-
func ObscureEmail(email string) (string, error) {
244-
segments := strings.Split(email, "@")
245-
if len(segments) != 2 {
246-
return "", errors.New("invalid email")
247-
}
248-
249-
address := segments[0]
250-
domain := segments[1]
251-
252-
var hiddenEmail string
253-
if len(address) > 1 {
254-
hiddenEmail = fmt.Sprintf(
255-
"%c%c***%c@%c***.com",
256-
address[0],
257-
address[1],
258-
address[len(address)-1],
259-
domain[0])
260-
} else {
261-
hiddenEmail = fmt.Sprintf(
262-
"%c***%c@%c***.com",
263-
address[0],
264-
address[len(address)-1],
265-
domain[0])
266-
}
267-
268-
return hiddenEmail, nil
269-
}
270-
271240
// LimitedChunkReader reads the request body, limited to max chunk size + encryption
272241
// overhead + 1024 bytes. This is big enough for all data-containing requests
273242
// made to the YeetFile API.

shared/utils.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package shared
22

33
import (
44
"bufio"
5+
"errors"
56
"fmt"
67
"math"
78
"math/rand"
@@ -184,3 +185,38 @@ func ArrayContains(items []string, target string) bool {
184185
}
185186
return false
186187
}
188+
189+
// ObscureEmail takes an email and strips out the majority of the address and
190+
// domain, adding "***" as an indicator of the obfuscation for both.
191+
func ObscureEmail(email string) (string, error) {
192+
segments := strings.Split(email, "@")
193+
if len(segments) != 2 {
194+
return "", errors.New("invalid email")
195+
}
196+
197+
address := segments[0]
198+
domain := segments[1]
199+
200+
segments = strings.Split(email, ".")
201+
ext := segments[len(segments)-1]
202+
203+
var hiddenEmail string
204+
if len(address) > 1 {
205+
hiddenEmail = fmt.Sprintf(
206+
"%c%c***%c@%c***.%s",
207+
address[0],
208+
address[1],
209+
address[len(address)-1],
210+
domain[0],
211+
ext)
212+
} else {
213+
hiddenEmail = fmt.Sprintf(
214+
"%c***%c@%c***.%s",
215+
address[0],
216+
address[len(address)-1],
217+
domain[0],
218+
ext)
219+
}
220+
221+
return hiddenEmail, nil
222+
}

0 commit comments

Comments
 (0)