diff --git a/.env.example b/.env.example index a04493b..ba949c4 100644 --- a/.env.example +++ b/.env.example @@ -13,6 +13,7 @@ MINIBIN_MAX_FILE_KIB=97657 MINIBIN_EXPIRIES=1h,12h,1d,7d,2w,1mo,6mo,1y,5y,0 # when set to true, will normalize mime types # the browser could execute to text/plain to prevent it +# only normalizes when returning content, not on upload MINIBIN_NORMALIZE_MIME_TYPES=true # prevents uploads with these mime types, separated by commas MINIBIN_BANNED_MIME_TYPES="application/vnd.microsoft.portable-executable,application/java-archive,application/x-executable" diff --git a/handlers.go b/handlers.go index 86f236c..4c43813 100644 --- a/handlers.go +++ b/handlers.go @@ -15,6 +15,7 @@ import ( "net/http" "os" "path/filepath" + "slices" "strings" "time" "unicode/utf8" @@ -119,6 +120,10 @@ func uploadHandler(db *gorm.DB, cfg Config, pages *template.Template, qts []stri http.Error(w, "failed to detect mime type", http.StatusInternalServerError) return } + if slices.Contains(cfg.BannedMIMETypes, input.MIMEType) { + http.Error(w, "content type not allowed", http.StatusBadRequest) + return + } input.Reader = file input.Filename = header.Filename input.Type = ContentFile