Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions modules/upload/filetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ func VerifyAllowedContentType(buf []byte, allowedTypes []string) error {
for _, t := range allowedTypes {
t := strings.Trim(t, " ")

if t == "*/*" || t == fileType ||
if t == fileType ||
// Allow wildcard */* to match all mime types
t == "*/*" ||
// Allow directives after type, like 'text/plain; charset=utf-8'
strings.HasPrefix(fileType, t+";") {
strings.HasPrefix(fileType, t+";") ||
// Allow a class whitelist, like 'image/*'
(strings.HasSuffix(t, "/*") && strings.HasPrefix(fileType, strings.TrimRight(t, "*"))) {
return nil
}
}
Expand Down