Skip to content

Commit

Permalink
security fix: always force html attachments to be downloaded as oppos…
Browse files Browse the repository at this point in the history
…ed to be shown inline
  • Loading branch information
or-else committed Jan 13, 2024
1 parent 759865e commit f19ab26
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion server/hdl_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ func largeFileServe(wrt http.ResponseWriter, req *http.Request) {
defer rsc.Close()

wrt.Header().Set("Content-Type", fd.MimeType)
if isAttachment, _ := strconv.ParseBool(req.URL.Query().Get("asatt")); isAttachment {
asAttachment, _ := strconv.ParseBool(req.URL.Query().Get("asatt"))
// Force download for html files as a security measure.
asAttachment = asAttachment || strings.Contains(fd.MimeType, "html")
if asAttachment {
wrt.Header().Set("Content-Disposition", "attachment")
}
http.ServeContent(wrt, req, "", fd.UpdatedAt, rsc)
Expand Down

0 comments on commit f19ab26

Please sign in to comment.