mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-19 14:57:04 +00:00
This patch adds checks that verify: - The envelope from must match the authenticated user. This prevents impersonation at the envelope level (while still allowing bounces, of course). - If the destination is remote, then the user must have completed authentication. This prevents unauthorized relaying. The patch ends up adjusting quite a few tests, as they were not written considering these restrictions so they have to be changed accordingly.
39 lines
702 B
Go
39 lines
702 B
Go
// Package envelope implements functions related to handling email envelopes
|
|
// (basically tuples of (from, to, data).
|
|
package envelope
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"blitiri.com.ar/go/chasquid/internal/set"
|
|
)
|
|
|
|
// Split an user@domain address into user and domain.
|
|
func Split(addr string) (string, string) {
|
|
ps := strings.SplitN(addr, "@", 2)
|
|
if len(ps) != 2 {
|
|
return addr, ""
|
|
}
|
|
|
|
return ps[0], ps[1]
|
|
}
|
|
|
|
func UserOf(addr string) string {
|
|
user, _ := Split(addr)
|
|
return user
|
|
}
|
|
|
|
func DomainOf(addr string) string {
|
|
_, domain := Split(addr)
|
|
return domain
|
|
}
|
|
|
|
func DomainIn(addr string, locals *set.String) bool {
|
|
domain := DomainOf(addr)
|
|
if domain == "" {
|
|
return true
|
|
}
|
|
|
|
return locals.Has(domain)
|
|
}
|