修复生产审查凭据泄露风险并增加持久投递队列
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-09-17 10:17:09 +08:00
1 parent 24670a3c2d
commit bf1e69f480
70 files changed
+1581 -262

No files matched your search

+22 -2
View File
@@ -45,6 +45,22 @@ var EOFError = errors.New("EOF")
var ErrUnsafeRemoteAddress = errors.New("smtp: remote address is not public")
var ErrUnsafePlaintextTarget = errors.New("smtp: plaintext delivery is restricted to localhost")
// DeliveryUncertainError 表示 DATA 已开始,但未取得明确接收或拒绝响应,禁止自动重投。
type DeliveryUncertainError struct {
Cause error
}
func (e *DeliveryUncertainError) Error() string {
return "投递结果不确定,请核对收件结果后再操作: " + e.Cause.Error()
}
func (e *DeliveryUncertainError) Unwrap() error { return e.Cause }
func IsDeliveryUncertain(err error) bool {
var uncertain *DeliveryUncertainError
return errors.As(err, &uncertain)
}
const (
outboundSMTPDialTimeout = 2 * time.Second
outboundSMTPTLSHandshakeTimeout = 2 * time.Second
@@ -554,10 +570,14 @@ func (c *Client) Data() (io.WriteCloser, error) {
func finishDelivery(c *Client, w io.WriteCloser, msg []byte) error {
if _, err := w.Write(msg); err != nil {
return err
return &DeliveryUncertainError{Cause: err}
}
if err := w.Close(); err != nil {
return err
var rejection *textproto.Error
if errors.As(err, &rejection) && rejection.Code >= 400 && rejection.Code <= 599 {
return err
}
return &DeliveryUncertainError{Cause: err}
}
// The final 250 response to DATA transfers responsibility for the message.
+15
View File
@@ -219,6 +219,10 @@ func startSMTPTransactionServer(t *testing.T, dataResponse string, holdWithoutQu
done <- fmt.Errorf("message body was not received: %q", body)
return
}
if dataResponse == "" {
done <- nil
return
}
if err := text.PrintfLine("%s", dataResponse); err != nil {
done <- err
return
@@ -244,6 +248,17 @@ func startSMTPTransactionServer(t *testing.T, dataResponse string, holdWithoutQu
return listener.Addr().String(), done
}
func TestLostFinalDATAResponseIsUncertain(t *testing.T) {
addr, done := startSMTPTransactionServer(t, "", false)
err := SendMailUnsafe("localhost", addr, nil, "sender@example.com", "example.com", []string{"recipient@example.net"}, []byte("Subject: test\r\n\r\nbody\r\n"))
if !IsDeliveryUncertain(err) {
t.Fatalf("error=%v, want uncertain delivery", err)
}
if err := <-done; err != nil {
t.Fatal(err)
}
}
func expectSMTPCommand(conn *textproto.Conn, prefix string) error {
line, err := conn.ReadLine()
if err != nil {