Skip to content

Commit f528f7d

Browse files
authored
Merge pull request #368 from cavidelizade/fix/attachment-disposition
fix(api): download attachments instead of rendering them inline
2 parents a633fbe + 30fea0c commit f528f7d

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

apps/api/internal/handler/upload.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ func (h *UploadHandler) ServeFile(c *gin.Context) {
187187

188188
c.Header("Content-Type", info.ContentType)
189189
c.Header("X-Content-Type-Options", "nosniff")
190-
c.Header("Content-Disposition", "inline")
190+
// Attachments are arbitrary user files with an unvalidated content-type, so
191+
// force a download instead of rendering them inline: an uploaded .html or
192+
// SVG would otherwise execute on the API origin when opened. The uploads/
193+
// prefix (avatars, covers, logos) is validated as images and stays inline.
194+
disposition := "inline"
195+
if strings.HasPrefix(path, "attachments/") {
196+
disposition = "attachment"
197+
}
198+
c.Header("Content-Disposition", disposition)
191199
c.DataFromReader(http.StatusOK, info.Size, info.ContentType, obj, nil)
192200
}

0 commit comments

Comments
 (0)