Skip to content

Commit

Permalink
more cases of forced attachment downloads (vs inline)
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Jan 15, 2024
1 parent f19ab26 commit 6aca44a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions server/hdl_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ func largeFileServe(wrt http.ResponseWriter, req *http.Request) {
wrt.Header().Set("Content-Type", fd.MimeType)
asAttachment, _ := strconv.ParseBool(req.URL.Query().Get("asatt"))
// Force download for html files as a security measure.
asAttachment = asAttachment || strings.Contains(fd.MimeType, "html")
asAttachment = asAttachment ||
strings.Contains(fd.MimeType, "html") ||
strings.Contains(fd.MimeType, "xml") ||
strings.HasPrefix(fd.MimeType, "application/") ||
strings.HasPrefix(fd.MimeType, "text/")
if asAttachment {
wrt.Header().Set("Content-Disposition", "attachment")
}
Expand Down Expand Up @@ -274,7 +278,7 @@ func largeFileReceive(wrt http.ResponseWriter, req *http.Request) {
// If DetectContentType fails, use client-provided content type.
if mimeType == "application/octet-stream" {
if contentType := header.Header.Get("Content-Type"); contentType != "" {
mimeType = contentType
mimeType = strings.ToLower(contentType)
}
}

Expand Down

0 comments on commit 6aca44a

Please sign in to comment.