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

mime: ParseMediaType should not return an error if mediatype is empty #69551

Open
aldenquimby opened this issue Sep 20, 2024 · 5 comments
Open
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@aldenquimby
Copy link

Go version

go version 1.23.0

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/alden/Library/Caches/go-build'
GOENV='/Users/alden/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/alden/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/alden/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.23.1/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.23.1/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.1'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/alden/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/dev/null'
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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/_h/_w_mjtt91s1dws8zlxnnjpzm0000gn/T/go-build1772735711=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I have a file server that returns Content-Disposition headers like this: ;filename*=UTF-8''hello-world.pdf

Example: https://go.dev/play/p/rxRNVZGDOQu

What did you see happen?

mime.ParseMediaType fails with the error "mime: no media type" (from here in code)

What did you expect to see?

  • mime.ParseMediaType succeeds, returning mediatype "" and params["filename"] hello-world.pdf
  • Note that all modern browsers and email clients parse a blank mediatype correctly
  • rfc6266 and rfc2183 both say Unknown or unhandled disposition types SHOULD be handled by recipients the same way as "attachment", and presumably an empty string disposition type fits into that
gulien added a commit to gotenberg/gotenberg that referenced this issue Sep 20, 2024
gulien added a commit to gotenberg/gotenberg that referenced this issue Sep 20, 2024
gulien added a commit to gotenberg/gotenberg that referenced this issue Sep 20, 2024
@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 20, 2024
@cagedmantis cagedmantis added this to the Backlog milestone Sep 20, 2024
@cagedmantis
Copy link
Contributor

cc @neild

@ianlancetaylor ianlancetaylor changed the title mime: ParseMediaType should not throw if mediatype is empty mime: ParseMediaType should not return an error if mediatype is empty Sep 20, 2024
@ianlancetaylor
Copy link
Member

What should mime.ParseMediaType("") return?

@aldenquimby
Copy link
Author

aldenquimby commented Sep 20, 2024

What should mime.ParseMediaType("") return?

@ianlancetaylor it's hard for me to tell from the spec, but I believe that would be invalid and should throw. The chromium parsing code starts here, for reference: https://github.com/chromium/chromium/blob/main/net/http/http_content_disposition.cc#L397

They appear to treat the disposition type and filename parsing separately. And the only completely invalid header is when there is no disposition type or filename

@Zxilly
Copy link
Member

Zxilly commented Sep 22, 2024

If we follow the logic in https://github.com/chromium/chromium/blob/04b3bd7342eb7ca8f114c7a5c5e466d802f9522b/net/http/http_content_disposition.cc#L350-L377, maybe we should set it to inline if we met an empty media type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants