Skip to main content

9. 记录结果 (Recording the Result)

为了向下游代理(例如MUA)提供它们在评估或表示消息内容的表面安全性方面可能需要的信息,建议SMTP接收器在消息标头中记录SPF处理的结果。对于选择在消息标头中记录SPF结果以供内部过滤器或MUA处理的SPF验证器操作者,提供了两种方法:第9.1节定义了Received-SPF字段,这是最初为SPF使用定义的结果字段。第9.2节讨论了Authentication-Results标头字段[RFC7001],该字段是最近指定的,旨在供SPF和其他身份验证方法使用。

两者都在常用中,因此两者都包含在此处。然而,重要的是要注意,它们被设计用于略有不同的目的。Received-SPF旨在包含足够的信息以能够重建消息的SPF评估,而Authentication-Results仅旨在中继结果本身以及可能对最终用户有用的相关输出细节(例如,实际验证的消息属性是什么以及它包含什么),将重建工作留给系统日志和Received字段内容的范围。此外,Received-SPF依赖于接收ADMD内的代理遵守[RFC5321]和[RFC5322]的标头字段排序规则,而Authentication-Results包含一些保护措施以防止不符合要求的实现。

SPF验证器操作者可以选择同时使用两者来服务不同的下游代理。在这种情况下,需要注意确保两个字段传达相同的细节,否则可能会出现意外结果。

9.1. Received-SPF 标头字段 (The Received-SPF Header Field)

Received-SPF标头字段是一个跟踪字段(参见[RFC5322]第3.6.7节),应该预先添加到现有标头之上,位于SMTP接收器生成的Received:字段之上。它必须出现在消息中所有其他Received-SPF字段之上。标头字段具有以下格式:

header-field = "Received-SPF:" [CFWS] result FWS [comment FWS]
[ key-value-list ] CRLF

result = "pass" / "fail" / "softfail" / "neutral" /
"none" / "temperror" / "permerror"

key-value-list = key-value-pair *( ";" [CFWS] key-value-pair ) [";"]

key-value-pair = key [CFWS] "=" ( dot-atom / quoted-string )

key = "client-ip" / "envelope-from" / "helo" /
"problem" / "receiver" / "identity" /
"mechanism" / name

identity = "mailfrom" ; for the "MAIL FROM" identity
/ "helo" ; for the "HELO" identity
/ name ; other identities

标头字段应该在结果后包含"(...)"样式的注释,传达结果的支持信息,例如

以下键值对设计用于以后的机器解析。SPF验证器应该提供足够的信息以便可以验证SPF结果——即至少"client-ip"、"helo",以及如果检查了"MAIL FROM"身份,则还包括"envelope-from"。

  • client-ip - SMTP客户端的IP地址
  • envelope-from - 信封发件人邮箱
  • helo - 在HELO或EHLO命令中给出的主机名
  • mechanism - 匹配的机制(如果没有机制匹配,则替换为单词"default")
  • problem - 如果返回错误,则是关于错误的详细信息
  • receiver - SPF验证器的主机名
  • identity - 被检查的身份;参见 ABNF规则

其他键可以由SPF验证器定义。

SPF验证器必须确保Received-SPF标头字段不包含无效字符,不过长(参见[RFC5322]第2.1.1节),并且不包含发件人提供的恶意数据。

可能生成的各种标头字段样式的示例如下:

Received-SPF: pass (mybox.example.org: domain of
[email protected] designates 192.0.2.1 as permitted sender)
receiver=mybox.example.org; client-ip=192.0.2.1;
envelope-from="[email protected]"; helo=foo.example.com;

Received-SPF: fail (mybox.example.org: domain of
[email protected] does not designate 192.0.2.1 as permitted sender)
identity=mailfrom; client-ip=192.0.2.1;
envelope-from="[email protected]";

Received-SPF: pass (mybox.example.org: domain of
[email protected] designates 192.0.2.1 as permitted sender)
receiver=mybox.example.org; client-ip=192.0.2.1;
mechanism=ip4:192.0.2.1; envelope-from="[email protected]";
helo=foo.example.com;

9.2. Authentication-Results 标头字段中的 SPF 结果

如第9节所述,Authentication-Results标头字段旨在传达边界MTA进行的测试列表及其结果。该字段的指定元素提供的信息少于Received-SPF字段:

Authentication-Results: myhost.example.org; spf=pass
smtp.mailfrom=example.net

Received-SPF: pass (myhost.example.org: domain of
[email protected] designates 192.0.2.1 as permitted sender)
receiver=mybox.example.org; client-ip=192.0.2.1;
envelope-from="[email protected]"; helo=foo.example.com;

然而,如果需要,可以在Authentication-Results标头字段的"reason"部分添加CFWS并提供等效信息。

例如,扩展的Authentication-Results标头字段可能看起来像(对于本示例中的"MAIL FROM"检查):

Authentication-Results: myhost.example.org; spf=pass
reason="client-ip=192.0.2.1; smtp.helo=foo.example.com"
[email protected]