diff options
author | Antoine GIRARD <sapk@users.noreply.github.com> | 2019-07-07 04:25:05 +0200 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-07-06 22:25:05 -0400 |
commit | f369788347167a47a8fc162e086b92048ff0a43f (patch) | |
tree | f959bd40d1a33761b0fa8a25bb956b4e24d3b044 /routers/repo/attachment.go | |
parent | 75d44143863e90a7aeff30a3f40128f144df94dd (diff) | |
download | gitea-f369788347167a47a8fc162e086b92048ff0a43f.tar.gz gitea-f369788347167a47a8fc162e086b92048ff0a43f.zip |
Refactor filetype is not allowed errors (#7309)
Diffstat (limited to 'routers/repo/attachment.go')
-rw-r--r-- | routers/repo/attachment.go | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index 8913e63015..a07a2a8ace 100644 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -6,13 +6,13 @@ package repo import ( "fmt" - "net/http" "strings" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/upload" ) func renderAttachmentSettings(ctx *context.Context) { @@ -42,21 +42,10 @@ func UploadAttachment(ctx *context.Context) { if n > 0 { buf = buf[:n] } - fileType := http.DetectContentType(buf) - allowedTypes := strings.Split(setting.AttachmentAllowedTypes, ",") - allowed := false - for _, t := range allowedTypes { - t := strings.Trim(t, " ") - if t == "*/*" || t == fileType { - allowed = true - break - } - } - - if !allowed { - log.Info("Attachment with type %s blocked from upload", fileType) - ctx.Error(400, ErrFileTypeForbidden.Error()) + err = upload.VerifyAllowedContentType(buf, strings.Split(setting.AttachmentAllowedTypes, ",")) + if err != nil { + ctx.Error(400, err.Error()) return } |