Skip to content

BUG: Weak random number generation for MIME boundaries #729

@andrinoff

Description

@andrinoff

Describe the bug
In pgp/yubikey.go line 96, MIME boundary uses only time.Now().Unix() which is predictable and not cryptographically secure. While crypto/rand is used in sender.go, yubikey.go has weaker fallback.

To reproduce
Examine pgp/yubikey.go line 96:

boundary := fmt.Sprintf("----=_Part_%d", time.Now().Unix())

Compare to sender/sender.go lines 81, 283, 487 which use crypto/rand properly.

Expected behavior
Use crypto/rand for MIME boundaries to prevent prediction attacks.

Additional context

  • Good first issue
  • Low severity (MIME boundary prediction has limited attack surface)
  • Best practice: always use crypto/rand for boundaries
  • sender/sender.go shows correct pattern

Suggested fix:

buf := make([]byte, 16)
if _, err := rand.Read(buf); err == nil {
    boundary = fmt.Sprintf("----=_Part_%x", buf)
} else {
    // fallback
    boundary = fmt.Sprintf("----=_Part_%d", time.Now().UnixNano())
}

OS
All platforms

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions