plik icon indicating copy to clipboard operation
plik copied to clipboard

Wrong Content-Type header for SVG images

Open brabiega opened this issue 3 years ago • 4 comments

When serving SVG files plik server sets

Content-Type | text/xml; charset=utf-8

Tested on Firefox 86.0.1, invalid content type prevents proper display of transparency and probably more elements of SVG files.

Content type should be set to "image/svg+xml" https://www.w3.org/TR/SVG11/mimereg.html

brabiega avatar Mar 28 '21 20:03 brabiega

Thanks for reporting that. The library we use might be unable to properly detect those files.

camathieu avatar Apr 12 '21 12:04 camathieu

Yup, that's the case https://github.com/golang/go/issues/47492

brabiega avatar Aug 01 '21 19:08 brabiega

The funny thing is that mime type is properly set in the DB when upload is created through web GUI (browser sends file type in request body)

POST /upload
{"ttl":2592000,"files":[{"fileName":"zabawka.svg","fileType":"image/svg+xml","fileSize":13243,"reference":"0"}]}

However when later actual file is sent the file type gets detected using net/http.DetectContentType and DB entry is overwritten with wrong fileType. POST /file/<t1>/<t2>/zabawka.svg

brabiega avatar Aug 01 '21 19:08 brabiega

Plik use golang http mime sniffer to resolve content types https://golang.org/pkg/net/http/#DetectContentType

This is a security measure to avoid possibilities to set fake content-types ( img -> exe ). The client library may send the fileType as a useful debug info.

https://github.com/root-gg/plik/issues/172

Le dim. 1 août 2021 à 21:21, BR @.***> a écrit :

The funny thing is that mime type is properly set in the DB when upload is created through web GUI (browser sends file type in request body)

POST /upload

{"ttl":2592000,"files":[{"fileName":"zabawka.svg","fileType":"image/svg+xml","fileSize":13243,"reference":"0"}]}

However when later actual file is sent the file type gets detected using net/http.DetectContentType and DB entry is overwritten with wrong fileType . (POST /file///zabawkaled.svg)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/root-gg/plik/issues/354#issuecomment-890572634, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQ5XPVQ3DCOPLX4BQAKC23T2WNDJANCNFSM4Z6MKBFQ .

camathieu avatar Aug 04 '21 09:08 camathieu