finish banned mime types
This commit is contained in:
@@ -13,6 +13,7 @@ MINIBIN_MAX_FILE_KIB=97657
|
|||||||
MINIBIN_EXPIRIES=1h,12h,1d,7d,2w,1mo,6mo,1y,5y,0
|
MINIBIN_EXPIRIES=1h,12h,1d,7d,2w,1mo,6mo,1y,5y,0
|
||||||
# when set to true, will normalize mime types
|
# when set to true, will normalize mime types
|
||||||
# the browser could execute to text/plain to prevent it
|
# the browser could execute to text/plain to prevent it
|
||||||
|
# only normalizes when returning content, not on upload
|
||||||
MINIBIN_NORMALIZE_MIME_TYPES=true
|
MINIBIN_NORMALIZE_MIME_TYPES=true
|
||||||
# prevents uploads with these mime types, separated by commas
|
# prevents uploads with these mime types, separated by commas
|
||||||
MINIBIN_BANNED_MIME_TYPES="application/vnd.microsoft.portable-executable,application/java-archive,application/x-executable"
|
MINIBIN_BANNED_MIME_TYPES="application/vnd.microsoft.portable-executable,application/java-archive,application/x-executable"
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"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)
|
http.Error(w, "failed to detect mime type", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if slices.Contains(cfg.BannedMIMETypes, input.MIMEType) {
|
||||||
|
http.Error(w, "content type not allowed", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
input.Reader = file
|
input.Reader = file
|
||||||
input.Filename = header.Filename
|
input.Filename = header.Filename
|
||||||
input.Type = ContentFile
|
input.Type = ContentFile
|
||||||
|
|||||||
Reference in New Issue
Block a user