Skip to content

Commit

Permalink
check/spf: Handle empty MAIL FROM in accordance with RFC 7208
Browse files Browse the repository at this point in the history
See #652.
See #603.
  • Loading branch information
foxcpp committed Jan 21, 2024
1 parent 5b5fb72 commit ab94e0b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
12 changes: 11 additions & 1 deletion internal/check/spf/spf.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,17 @@ func (s *state) CheckConnection(ctx context.Context) module.CheckResult {
return module.CheckResult{}
}

mailFrom, err := prepareMailFrom(s.msgMeta.OriginalFrom)
mailFromOriginal := s.msgMeta.OriginalFrom
if mailFromOriginal == "" {
// RFC 7208 Section 2.4.
// >When the reverse-path is null, this document
// >defines the "MAIL FROM" identity to be the mailbox composed of the
// >local-part "postmaster" and the "HELO" identity (which might or might
// >not have been checked separately before).
mailFromOriginal = "postmaster@" + s.msgMeta.Conn.Hostname
}

mailFrom, err := prepareMailFrom(mailFromOriginal)
if err != nil {
s.skip = true
return module.CheckResult{
Expand Down
13 changes: 11 additions & 2 deletions tests/smtp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,22 @@ func TestCheckSPF(tt *testing.T) {

conn := t.Conn("smtp")
defer conn.Close()
conn.SMTPNegotation("localhost", nil, nil)
conn.SMTPNegotation("fail.maddy.test", nil, nil)

conn.Writeln("MAIL FROM:<[email protected]>")
conn.ExpectPattern("250 *")
conn.Writeln("RSET")
conn.ExpectPattern("250 *")

// Actually checks fail.maddy.test.
conn.Writeln("MAIL FROM:<>")
conn.ExpectPattern("552 5.7.0 *")

conn.SMTPNegotation("pass.maddy.test", nil, nil)

conn.Writeln("MAIL FROM:<>")
conn.ExpectPattern("250 *")

conn.Writeln("MAIL FROM:<[email protected]>")
conn.ExpectPattern("551 5.7.0 *")

Expand Down Expand Up @@ -364,7 +373,7 @@ func TestCheckAuthorizeSender(tt *testing.T) {
auth_normalize precis_casefold
user_to_email static {
entry "test-user1" "[email protected]"
entry "test-user2" "é@example1.org"
entry "test-user2" "é@example1.org"
}
}
}
Expand Down

0 comments on commit ab94e0b

Please sign in to comment.