Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/mail: mail.ReadMessage in 1.20 cannot parse mbox headers #60332

Closed
nferch opened this issue May 22, 2023 · 6 comments
Closed

net/mail: mail.ReadMessage in 1.20 cannot parse mbox headers #60332

nferch opened this issue May 22, 2023 · 6 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@nferch
Copy link

nferch commented May 22, 2023

What version of Go are you using (go version)?

1.20.3

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""    
GOARCH="amd64"                                                                                                                     
GOBIN=""
GOCACHE="/home/nf/.cache/go-build"
GOENV="/home/nf/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/nf/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/nf/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.20"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.20/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/nf/Projects/mutt-save-hook/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3946607393=/tmp/go-build -gno-record-gcc-switches"

What did you do?

A change introduced in Go 1.20 prevents mail.ReadMessage from being able to handle messages preceded by a mbox header. A mbox header consists of a From header (no colon) preceding the message content https://www.loc.gov/preservation/digital/formats/fdd/fdd000383.shtml

This prevents mail.ReadMessage from being able to read single-message mbox files, or messages piped by MUAs like Mutt.

To reproduce: https://go.dev/play/p/lgqlLBsWBX8?v=goprev

What did you expect to see?

I did not expect my code to behave differently with a newer version of Go.

What did you see instead?

Due to a change in Go (presumably https://cs.opensource.google/go/go/+/42137704fca158f14c4aebff61b54ebeae788a4a), my Go program started reporting an error given identical input.

I believe that the prior behavior of ignoring mbox headers, even if unintended, should be restored in order to prevent programs that depended on it from breaking, to maintain its compatibility with previous versions, and to try and conform to the Robustness principle by handling a common malformed input.

@seankhliao
Copy link
Member

I believe this is from the stricter textproto parser introduced in #53188
related? #58862
https://go.dev/play/p/qNVg2bZCk0K

(side note, the robustness principle is a poor argument)

cc @neild

@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 22, 2023
@Ikke
Copy link

Ikke commented Jun 17, 2023

I believe this is from the stricter textproto parser introduced in #53188

I can confirm. Debugging shows that due to the lack of a ":", the entire line is interpreted as a header field name, and so fails because it contains invalid header field characters.

func canonicalMIMEHeaderKey(a []byte) (_ string, ok bool) {

@ianlancetaylor
Copy link
Member

@gopherbot Please open backport to 1.20.

This stopped working due to the changes in #53188, but those changes don't apply to net/mail.

@gopherbot
Copy link
Contributor

Backport issue(s) opened: #60874 (for 1.20).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/504416 mentions this issue: net/mail: permit more characters in mail headers

@dmitshur dmitshur added this to the Go1.21 milestone Jun 19, 2023
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jun 19, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/504881 mentions this issue: [release-branch.go1.20] net/mail: permit more characters in mail headers

gopherbot pushed a commit that referenced this issue Jun 21, 2023
We parse mail messages using net/textproto. For #53188, we tightened
up the bytes permitted by net/textproto to match RFC 7230.
However, this package uses RFC 5322 which is more permissive.
Restore the permisiveness we used to have, so that older code
continues to work.

For #58862
For #60332
Fixes #60874
Fixes #60875

Change-Id: I5437f5e18a756f6ca61c13c4d8ba727be73eff9a
Reviewed-on: https://go-review.googlesource.com/c/go/+/504881
Run-TryBot: Ian Lance Taylor <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
bradfitz pushed a commit to tailscale/go that referenced this issue Jul 15, 2023
We parse mail messages using net/textproto. For golang#53188, we tightened
up the bytes permitted by net/textproto to match RFC 7230.
However, this package uses RFC 5322 which is more permissive.
Restore the permisiveness we used to have, so that older code
continues to work.

Fixes golang#58862
Fixes golang#60332

Change-Id: I5437f5e18a756f6ca61c13c4d8ba727be73eff9a
Reviewed-on: https://go-review.googlesource.com/c/go/+/504416
Run-TryBot: Ian Lance Taylor <[email protected]>
Run-TryBot: Ian Lance Taylor <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
Auto-Submit: Ian Lance Taylor <[email protected]>
@golang golang locked and limited conversation to collaborators Jun 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants