fix extension check

This commit is contained in:
Benny~ 2020-03-01 15:33:54 +08:00
parent d514865b64
commit a9dd261702
No known key found for this signature in database
GPG Key ID: 6CD0DBDA5235D481

View File

@ -138,18 +138,23 @@ func Convert(ImgPath string, AllowedTypes []string, QUALITY string) func(c *fibe
}
// check ext
// TODO: should remove this function. Check in Nginx.
// TODO: may remove this function. Check in Nginx.
var allowed = false
for _, ext := range AllowedTypes {
haystack := strings.ToLower(ImgFilename)
needle := strings.ToLower("." + ext)
if strings.HasSuffix(haystack, needle) {
allowed = true
break
} else {
c.Send("File extension not allowed!")
c.SendStatus(403)
return
allowed = false
}
}
if !allowed {
c.Send("File extension not allowed!")
c.SendStatus(403)
return
}
// Check the original image for existence,
if !imageExists(RawImageAbs) {