Skip to content

Commit b3274f3

Browse files
committed
fix: tighten file permissions and phone length validation
- Attachment directories: 0750 instead of 0755 - Attachment files: 0600 instead of 0644 - Phone number max length: 15 digits (E.164 limit) to prevent data pollution from crafted WhatsApp DBs
1 parent ed2bf62 commit b3274f3

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

internal/whatsapp/importer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ func (imp *Importer) handleMediaFile(media waMedia, opts ImportOptions) (string,
512512

513513
// Create directory and stream-copy the file.
514514
absStorageDir := filepath.Dir(absStoragePath)
515-
if err := os.MkdirAll(absStorageDir, 0755); err != nil {
515+
if err := os.MkdirAll(absStorageDir, 0750); err != nil {
516516
return "", contentHash
517517
}
518518

@@ -521,7 +521,7 @@ func (imp *Importer) handleMediaFile(media waMedia, opts ImportOptions) (string,
521521
return "", contentHash
522522
}
523523

524-
dst, err := os.OpenFile(absStoragePath, os.O_CREATE|os.O_WRONLY|os.O_EXCL, 0644)
524+
dst, err := os.OpenFile(absStoragePath, os.O_CREATE|os.O_WRONLY|os.O_EXCL, 0600)
525525
if err != nil {
526526
if os.IsExist(err) {
527527
// Race: another goroutine already wrote it.

internal/whatsapp/mapping.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ func normalizePhone(user, server string) string {
143143
}
144144
}
145145

146-
// Must be at least a few digits to be a plausible phone number.
147-
if len(user) < 4 {
146+
// Must be at least a few digits to be a plausible phone number,
147+
// and no more than 15 (E.164 max) to prevent data pollution.
148+
if len(user) < 4 || len(user) > 15 {
148149
return ""
149150
}
150151

0 commit comments

Comments
 (0)