@@ -104,8 +104,12 @@ func serveFile(w http.ResponseWriter, r *http.Request, path string) {
104
104
//
105
105
// Unlike mime.TypeByExtension, the results are limited to a set of types which
106
106
// should be safe to serve to a browser without introducing XSS vulnerabilities.
107
+ //
108
+ // We handle all of the extensions we allow on files uploaded as attachments to a rageshake,
109
+ // plus 'log' which we do not allow as an attachment, but is used as the extension when serving
110
+ // the logs submitted as `logs` or `compressed-log`.
107
111
func extensionToMimeType (path string ) string {
108
- if strings .HasSuffix (path , ".txt" ) {
112
+ if strings .HasSuffix (path , ".txt" ) || strings . HasSuffix ( path , ".log" ) {
109
113
// anyone uploading text in anything other than utf-8 needs to be
110
114
// re-educated.
111
115
return "text/plain; charset=utf-8"
@@ -236,7 +240,13 @@ func addToArchive(targz *tar.Writer, dfilename string, filename string) error {
236
240
}
237
241
238
242
func serveGzippedFile (w http.ResponseWriter , r * http.Request , path string , size int64 ) {
239
- w .Header ().Set ("Content-Type" , "text/plain; charset=utf-8" )
243
+ cType := "text/plain; charset=utf-8"
244
+ if strings .HasSuffix (path , ".gz" ) {
245
+ // Guess the mime type from the extension as we do in serveFile, but without
246
+ // the .gz header (in practice, either plain text or application/json).
247
+ cType = extensionToMimeType (path [:len (path )- len (".gz" )])
248
+ }
249
+ w .Header ().Set ("Content-Type" , cType )
240
250
241
251
acceptsGzip := false
242
252
splitRune := func (s rune ) bool { return s == ' ' || s == '\t' || s == '\n' || s == ',' }
0 commit comments