]> source.dussan.org Git - gitea.git/commitdiff
Disable content sniffing on `PlainTextBytes` (#18359)
authorGusted <williamzijl7@hotmail.com>
Sat, 22 Jan 2022 18:32:35 +0000 (18:32 +0000)
committerGitHub <noreply@github.com>
Sat, 22 Jan 2022 18:32:35 +0000 (13:32 -0500)
- Disable the browser's function to "sniff" for the content-type on the
provided plain text, this will prevent the possible usage of
user-controlled data being sent, which could be malicious.

Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
modules/context/context.go

index 998eafe965fcd5c665c0dc839f85e20eec7cc1a8..0cbdfa023c6b62eaf23fead7f5fd1412e03341e7 100644 (file)
@@ -292,6 +292,7 @@ func (ctx *Context) PlainTextBytes(status int, bs []byte) {
        }
        ctx.Resp.WriteHeader(status)
        ctx.Resp.Header().Set("Content-Type", "text/plain;charset=utf-8")
+       ctx.Resp.Header().Set("X-Content-Type-Options", "nosniff")
        if _, err := ctx.Resp.Write(bs); err != nil {
                log.Error("Write bytes failed: %v", err)
        }