mirror of
https://github.com/penpot/penpot.git
synced 2025-01-09 08:20:45 -05:00
✨ Check actual image content for valid mime type
This commit is contained in:
parent
700e99a25d
commit
a3490ea36d
4 changed files with 11 additions and 4 deletions
|
@ -10,6 +10,7 @@
|
|||
[clojure.java.io :as io]
|
||||
[clojure.spec.alpha :as s]
|
||||
[datoteka.core :as fs]
|
||||
[uxbox.common.exceptions :as ex]
|
||||
[uxbox.common.data :as d]
|
||||
[uxbox.common.spec :as us]
|
||||
[uxbox.util.storage :as ust]
|
||||
|
@ -108,8 +109,12 @@
|
|||
(ByteArrayInputStream. thumbnail-data)))))
|
||||
|
||||
(defn info
|
||||
[path]
|
||||
[content-type path]
|
||||
(let [instance (Info. (str path))]
|
||||
(when-not (= content-type (.getProperty instance "Mime type"))
|
||||
(ex/raise :type :validation
|
||||
:code :image-type-mismatch
|
||||
:hint "Seems like you are uploading a file whose content does not match the extension."))
|
||||
{:width (.getImageWidth instance)
|
||||
:height (.getImageHeight instance)}))
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@
|
|||
:code :image-type-not-allowed
|
||||
:hint "Seems like you are uploading an invalid image."))
|
||||
|
||||
(let [image-opts (images/info (:tempfile content))
|
||||
(let [image-opts (images/info (:content-type content) (:tempfile content))
|
||||
image-path (imgs/persist-image-on-fs content)
|
||||
thumb-opts imgs/thumbnail-options
|
||||
thumb-path (imgs/persist-image-thumbnail-on-fs thumb-opts image-path)]
|
||||
|
|
|
@ -146,7 +146,8 @@
|
|||
(ex/raise :type :validation
|
||||
:code :image-type-not-allowed
|
||||
:hint "Seems like you are uploading an invalid image."))
|
||||
(let [image-opts (images/info (:tempfile content))
|
||||
|
||||
(let [image-opts (images/info (:content-type content) (:tempfile content))
|
||||
image-path (persist-image-on-fs content)
|
||||
thumb-opts thumbnail-options
|
||||
thumb-path (persist-image-thumbnail-on-fs thumb-opts image-path)]
|
||||
|
|
|
@ -291,7 +291,8 @@
|
|||
(ex/raise :type :validation
|
||||
:code :image-type-not-allowed
|
||||
:hint "Seems like you are uploading an invalid image."))
|
||||
(let [thumb-opts {:width 256
|
||||
(let [image-opts (images/info (:content-type file) (:tempfile file))
|
||||
thumb-opts {:width 256
|
||||
:height 256
|
||||
:quality 75
|
||||
:format "webp"}
|
||||
|
|
Loading…
Reference in a new issue