diff --git a/backend/src/uxbox/images.clj b/backend/src/uxbox/images.clj index 9af8636de..6f7127a18 100644 --- a/backend/src/uxbox/images.clj +++ b/backend/src/uxbox/images.clj @@ -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)})) diff --git a/backend/src/uxbox/services/mutations/files.clj b/backend/src/uxbox/services/mutations/files.clj index c1723078a..2b5d6a33c 100644 --- a/backend/src/uxbox/services/mutations/files.clj +++ b/backend/src/uxbox/services/mutations/files.clj @@ -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)] diff --git a/backend/src/uxbox/services/mutations/images.clj b/backend/src/uxbox/services/mutations/images.clj index 69ee47e52..d5ad3bcc4 100644 --- a/backend/src/uxbox/services/mutations/images.clj +++ b/backend/src/uxbox/services/mutations/images.clj @@ -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)] diff --git a/backend/src/uxbox/services/mutations/profile.clj b/backend/src/uxbox/services/mutations/profile.clj index 17c8ebc76..9f262a858 100644 --- a/backend/src/uxbox/services/mutations/profile.clj +++ b/backend/src/uxbox/services/mutations/profile.clj @@ -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"}