Skip to content

Commit 24cd545

Browse files
committed
chore_: truncate sensitive information in error messages
This commit adds a utility function from the common package to truncate sensitive information (like addresses, IDs, etc.) in error messages across multiple files. This helps prevent accidentally exposing full sensitive data in logs and error messages while maintaining readability.
1 parent d3404d3 commit 24cd545

File tree

16 files changed

+52
-45
lines changed

16 files changed

+52
-45
lines changed

abi-spec/utils.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"go.uber.org/zap"
1212

1313
"github.com/ethereum/go-ethereum/common"
14+
gocommon "github.com/status-im/status-go/common"
1415
"github.com/status-im/status-go/eth-node/crypto"
1516
"github.com/status-im/status-go/logutils"
1617
)
@@ -183,7 +184,7 @@ func ToChecksumAddress(address string) (string, error) {
183184
return "", nil
184185
}
185186
if !addressBasicPattern.MatchString(address) {
186-
return "", fmt.Errorf("given address '%s' is not a valid Ethereum address", address)
187+
return "", fmt.Errorf("given address '%s' is not a valid Ethereum address", gocommon.TruncateWithDot(address))
187188
}
188189

189190
address = strings.ToLower(address)

account/accounts.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
gethcommon "github.com/ethereum/go-ethereum/common"
2121
"github.com/ethereum/go-ethereum/common/hexutil"
2222
"github.com/status-im/status-go/account/generator"
23+
gocommon "github.com/status-im/status-go/common"
2324
"github.com/status-im/status-go/eth-node/crypto"
2425
"github.com/status-im/status-go/eth-node/keystore"
2526
"github.com/status-im/status-go/eth-node/types"
@@ -230,7 +231,7 @@ func (m *DefaultManager) VerifyAccountPassword(keyStoreDir, address, password st
230231

231232
// avoid swap attack
232233
if key.Address != addressObj {
233-
return nil, fmt.Errorf("account mismatch: have %s, want %s", key.Address.Hex(), addressObj.Hex())
234+
return nil, fmt.Errorf("account mismatch: have %s, want %s", gocommon.TruncateWithDot(key.Address.Hex()), gocommon.TruncateWithDot(addressObj.Hex()))
234235
}
235236

236237
return key, nil

api/geth_backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ func (b *GethStatusBackend) getAccountByKeyUID(keyUID string) (*multiaccounts.Ac
283283
return &acc, nil
284284
}
285285
}
286-
return nil, fmt.Errorf("account with keyUID %s not found", keyUID)
286+
return nil, fmt.Errorf("account with keyUID %s not found", gocommon.TruncateWithDot(keyUID))
287287
}
288288

289289
func (b *GethStatusBackend) SaveAccount(account multiaccounts.Account) error {

protocol/identity/utils.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ import (
77
"testing"
88

99
"github.com/ethereum/go-ethereum/crypto/secp256k1"
10+
11+
gocommon "github.com/status-im/status-go/common"
1012
)
1113

1214
func ToColorID(pubkey string) (int64, error) {
1315
const colorPalletLength = 12
1416

1517
pubkeyValue, ok := new(big.Int).SetString(pubkey, 0)
1618
if !ok {
17-
return 0, fmt.Errorf("invalid pubkey: %s", pubkey)
19+
return 0, fmt.Errorf("invalid pubkey: %s", gocommon.TruncateWithDot(pubkey))
1820
}
1921

2022
colorID := new(big.Int).Mod(pubkeyValue, new(big.Int).SetInt64(colorPalletLength-1)).Int64()
@@ -61,12 +63,12 @@ func Slices(compressedPubkey []byte) (res [4][]byte, err error) {
6163
func ToCompressedKey(pubkey string) ([]byte, error) {
6264
pubkeyValue, ok := new(big.Int).SetString(pubkey, 0)
6365
if !ok {
64-
return nil, fmt.Errorf("invalid pubkey: %s", pubkey)
66+
return nil, fmt.Errorf("invalid pubkey: %s", gocommon.TruncateWithDot(pubkey))
6567
}
6668

6769
x, y := secp256k1.S256().Unmarshal(pubkeyValue.Bytes())
6870
if x == nil || !secp256k1.S256().IsOnCurve(x, y) {
69-
return nil, fmt.Errorf("invalid pubkey: %s", pubkey)
71+
return nil, fmt.Errorf("invalid pubkey: %s", gocommon.TruncateWithDot(pubkey))
7072
}
7173

7274
return secp256k1.CompressPubkey(x, y), nil

protocol/linkpreview_unfurler_status.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"go.uber.org/zap"
77

88
"github.com/status-im/status-go/api/multiformat"
9+
gocommon "github.com/status-im/status-go/common"
910
"github.com/status-im/status-go/images"
1011
"github.com/status-im/status-go/protocol/common"
1112
"github.com/status-im/status-go/protocol/common/shard"
@@ -61,10 +62,10 @@ func (u *StatusUnfurler) buildContactData(publicKey string) (*common.StatusConta
6162
if contact == nil {
6263
contact, err = u.m.FetchContact(contactID, true)
6364
if err != nil {
64-
return nil, fmt.Errorf("failed to request contact info from mailserver for public key '%s': %w", publicKey, err)
65+
return nil, fmt.Errorf("failed to request contact info from mailserver for public key '%s': %w", gocommon.TruncateWithDot(publicKey), err)
6566
}
6667
if contact == nil {
67-
return nil, fmt.Errorf("contact wasn't found at the store node %s", publicKey)
68+
return nil, fmt.Errorf("contact wasn't found at the store node %s", gocommon.TruncateWithDot(publicKey))
6869
}
6970
}
7071

@@ -93,7 +94,7 @@ func (u *StatusUnfurler) buildCommunityData(communityID string, shard *shard.Sha
9394
})
9495

9596
if err != nil {
96-
return nil, nil, fmt.Errorf("failed to get community info for communityID '%s': %w", communityID, err)
97+
return nil, nil, fmt.Errorf("failed to get community info for communityID '%s': %w", gocommon.TruncateWithDot(communityID), err)
9798
}
9899

99100
if community == nil {
@@ -102,7 +103,7 @@ func (u *StatusUnfurler) buildCommunityData(communityID string, shard *shard.Sha
102103

103104
statusCommunityLinkPreviews, err := community.ToStatusLinkPreview()
104105
if err != nil {
105-
return nil, nil, fmt.Errorf("failed to get status community link preview for communityID '%s': %w", communityID, err)
106+
return nil, nil, fmt.Errorf("failed to get status community link preview for communityID '%s': %w", gocommon.TruncateWithDot(communityID), err)
106107
}
107108

108109
return community, statusCommunityLinkPreviews, nil
@@ -116,7 +117,7 @@ func (u *StatusUnfurler) buildChannelData(channelUUID string, communityID string
116117

117118
channel, ok := community.Chats()[channelUUID]
118119
if !ok {
119-
return nil, fmt.Errorf("channel with channelID '%s' not found in community '%s'", channelUUID, communityID)
120+
return nil, fmt.Errorf("channel with channelID '%s' not found in community '%s'", gocommon.TruncateWithDot(channelUUID), gocommon.TruncateWithDot(communityID))
120121
}
121122

122123
return &common.StatusCommunityChannelLinkPreview{

protocol/messenger.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,7 @@ func (m *Messenger) dispatchMessage(ctx context.Context, rawMessage common.RawMe
20382038
zap.String("chatName", chat.Name),
20392039
zap.Any("messageType", rawMessage.MessageType),
20402040
)
2041-
return rawMessage, fmt.Errorf("can't post message type '%d' on chat '%s'", rawMessage.MessageType, chat.ID)
2041+
return rawMessage, fmt.Errorf("can't post message type '%d' on chat '%s'", rawMessage.MessageType, gocommon.TruncateWithDot(chat.ID))
20422042
}
20432043

20442044
logger.Debug("sending community chat message", zap.String("chatName", chat.Name))
@@ -3023,12 +3023,12 @@ func (r *ReceivedMessageState) addNewMessageNotification(publicKey ecdsa.PublicK
30233023

30243024
chat, ok := r.AllChats.Load(m.LocalChatID)
30253025
if !ok {
3026-
return fmt.Errorf("chat ID '%s' not present", m.LocalChatID)
3026+
return fmt.Errorf("chat ID '%s' not present", gocommon.TruncateWithDot(m.LocalChatID))
30273027
}
30283028

30293029
contact, ok := r.AllContacts.Load(contactID)
30303030
if !ok {
3031-
return fmt.Errorf("contact ID '%s' not present", contactID)
3031+
return fmt.Errorf("contact ID '%s' not present", gocommon.TruncateWithDot(contactID))
30323032
}
30333033

30343034
if !chat.Muted {
@@ -3098,7 +3098,7 @@ func (r *ReceivedMessageState) addNewActivityCenterNotification(publicKey ecdsa.
30983098

30993099
chat, ok := r.AllChats.Load(message.LocalChatID)
31003100
if !ok {
3101-
return fmt.Errorf("chat ID '%s' not present", message.LocalChatID)
3101+
return fmt.Errorf("chat ID '%s' not present", gocommon.TruncateWithDot(message.LocalChatID))
31023102
}
31033103

31043104
isNotification, notificationType := showMentionOrReplyActivityCenterNotification(publicKey, message, chat, responseTo)
@@ -4283,7 +4283,7 @@ func (m *Messenger) MarkAllReadInCommunity(ctx context.Context, communityID stri
42834283
m.allChats.Store(chat.ID, chat)
42844284
response.AddChat(chat)
42854285
} else {
4286-
err = fmt.Errorf("chat with chatID %s not found", chatID)
4286+
err = fmt.Errorf("chat with chatID %s not found", gocommon.TruncateWithDot(chatID))
42874287
}
42884288
}
42894289
return response, err

protocol/messenger_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ func (m *Messenger) syncContactRequestForInstallationContact(contact *Contact, s
486486
}
487487

488488
if chat == nil {
489-
return fmt.Errorf("no chat restored during the contact synchronisation, contact.ID = %s", contact.ID)
489+
return fmt.Errorf("no chat restored during the contact synchronisation, contact.ID = %s", gocommon.TruncateWithDot(contact.ID))
490490
}
491491

492492
contactRequestID, err := m.persistence.LatestPendingContactRequestIDForContact(contact.ID)

protocol/messenger_mention.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func (m *MentionManager) getMentionableUser(chatID string, pk string) (*Mentiona
222222
}
223223
user, ok := mentionableUsers[pk]
224224
if !ok {
225-
return nil, fmt.Errorf("user not found when getting mentionable user, pk: %s", pk)
225+
return nil, fmt.Errorf("user not found when getting mentionable user, pk: %s", gocommon.TruncateWithDot(pk))
226226
}
227227
return user, nil
228228
}
@@ -231,7 +231,7 @@ func (m *MentionManager) getMentionableUsers(chatID string) (map[string]*Mention
231231
mentionableUsers := make(map[string]*MentionableUser)
232232
chat, _ := m.allChats.Load(chatID)
233233
if chat == nil {
234-
return nil, fmt.Errorf("chat not found when getting mentionable users, chatID: %s", chatID)
234+
return nil, fmt.Errorf("chat not found when getting mentionable users, chatID: %s", gocommon.TruncateWithDot(chatID))
235235
}
236236

237237
var publicKeys []string
@@ -291,7 +291,7 @@ func (m *MentionManager) addMentionableUser(mentionableUsers map[string]*Mention
291291
func (m *MentionManager) ReplaceWithPublicKey(chatID, text string) (string, error) {
292292
chat, _ := m.allChats.Load(chatID)
293293
if chat == nil {
294-
return "", fmt.Errorf("chat not found when check mentions, chatID: %s", chatID)
294+
return "", fmt.Errorf("chat not found when check mentions, chatID: %s", gocommon.TruncateWithDot(chatID))
295295
}
296296
mentionableUsers, err := m.mentionableUserGetter.getMentionableUsers(chatID)
297297
if err != nil {

protocol/messenger_share_urls.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/andybalholm/brotli"
1313

1414
"github.com/status-im/status-go/api/multiformat"
15+
gocommon "github.com/status-im/status-go/common"
1516
"github.com/status-im/status-go/eth-node/crypto"
1617
"github.com/status-im/status-go/eth-node/types"
1718
"github.com/status-im/status-go/protocol/common"
@@ -224,7 +225,7 @@ func (m *Messenger) ShareCommunityChannelURLWithChatKey(request *requests.Commun
224225
}
225226

226227
if !valid {
227-
return "", fmt.Errorf("channelID should be UUID, got %s", request.ChannelID)
228+
return "", fmt.Errorf("channelID should be UUID, got %s", gocommon.TruncateWithDot(request.ChannelID))
228229
}
229230

230231
return fmt.Sprintf("%s/cc/%s#%s", baseShareURL, request.ChannelID, shortKey), nil
@@ -237,7 +238,7 @@ func parseCommunityChannelURLWithChatKey(channelID string, publicKey string) (*U
237238
}
238239

239240
if !valid {
240-
return nil, fmt.Errorf("channelID should be UUID, got %s", channelID)
241+
return nil, fmt.Errorf("channelID should be UUID, got %s", gocommon.TruncateWithDot(channelID))
241242
}
242243

243244
communityID, err := decodeCommunityID(publicKey)
@@ -313,7 +314,7 @@ func (m *Messenger) ShareCommunityChannelURLWithData(request *requests.Community
313314
}
314315

315316
if !valid {
316-
return "nil", fmt.Errorf("channelID should be UUID, got %s", request.ChannelID)
317+
return "", fmt.Errorf("channelID should be UUID, got %s", gocommon.TruncateWithDot(request.ChannelID))
317318
}
318319

319320
community, err := m.GetCommunityByID(request.CommunityID)
@@ -323,7 +324,7 @@ func (m *Messenger) ShareCommunityChannelURLWithData(request *requests.Community
323324

324325
channel := community.Chats()[request.ChannelID]
325326
if channel == nil {
326-
return "", fmt.Errorf("channel with channelID %s not found", request.ChannelID)
327+
return "", fmt.Errorf("channel with channelID %s not found", gocommon.TruncateWithDot(request.ChannelID))
327328
}
328329

329330
data, shortKey, err := m.prepareEncodedCommunityChannelData(community, channel, request.ChannelID)

protocol/messenger_store_node_request_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (m *StoreNodeRequestManager) FetchCommunities(ctx context.Context, communit
149149
for _, community := range communities {
150150
_, _, err := m.FetchCommunity(ctx, community, opts)
151151
if err != nil {
152-
outErr = fmt.Errorf("%sfailed to create a request for community %s: %w", outErr, community.CommunityID, err)
152+
outErr = fmt.Errorf("%sfailed to create a request for community %s: %w", outErr, gocommon.TruncateWithDot(community.CommunityID), err)
153153
}
154154
}
155155

0 commit comments

Comments
 (0)