diff --git a/backend/src/app/rpc/commands/binfile.clj b/backend/src/app/rpc/commands/binfile.clj index 79b0bf7cf9..9c852e94ab 100644 --- a/backend/src/app/rpc/commands/binfile.clj +++ b/backend/src/app/rpc/commands/binfile.clj @@ -118,11 +118,10 @@ (def ^:private schema:import-binfile [:and - [:map {:title "import-binfile"} + [:map {:title "import-binfile" :closed true} [:name [:or [:string {:max 250}] [:map-of ::sm/uuid [:string {:max 250}]]]] [:project-id ::sm/uuid] - [:file-id {:optional true} ::sm/uuid] [:version {:optional true} ::sm/int] [:file {:optional true} media/schema:upload] [:upload-id {:optional true} ::sm/uuid]] @@ -131,35 +130,26 @@ (or (some? file) (some? upload-id)))]]) (sv/defmethod ::import-binfile - "Import a penpot file in a binary format. If `file-id` is provided, - an in-place import will be performed instead of creating a new file. - - The in-place imports are only supported for binfile-v3 and when a - .penpot file only contains one penpot file. + "Import a penpot file in a binary format. The file content may be provided either as a multipart `file` upload or as an `upload-id` referencing a completed chunked-upload session, which allows importing files larger than the multipart size limit. " {::doc/added "1.15" - ::doc/changes ["1.20" "Add file-id param for in-place import" - "1.20" "Set default version to 3" - "2.15" "Add upload-id param for chunked upload support"] + ::doc/changes [["1.20" "Set default version to 3"] + ["2.15" "Add upload-id param for chunked upload support"]] ::webhooks/event? true ::sse/stream? true ::sm/params schema:import-binfile} - [{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id project-id version file-id upload-id] :as params}] + [{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id project-id version upload-id] :as params}] (projects/check-edition-permissions! pool profile-id project-id) (let [version (or version 3) params (-> params (assoc :profile-id profile-id) (assoc :version version)) - cfg (cond-> cfg - (uuid? file-id) - (assoc ::bfc/file-id file-id)) - params (if (some? upload-id) (let [file (db/tx-run! cfg media-cmd/assemble-chunks upload-id)] @@ -174,6 +164,5 @@ (with-meta (sse/response (partial import-binfile cfg params)) {::audit/props {:file nil - :file-id file-id :generated-by (:generated-by manifest) :referer (:referer manifest)}}))) diff --git a/backend/test/backend_tests/rpc_binfile_test.clj b/backend/test/backend_tests/rpc_binfile_test.clj new file mode 100644 index 0000000000..ca78dca95c --- /dev/null +++ b/backend/test/backend_tests/rpc_binfile_test.clj @@ -0,0 +1,42 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; Copyright (c) KALEIDOS INC Sucursal en EspaƱa SL + +(ns backend-tests.rpc-binfile-test + (:require + [app.common.schema :as sm] + [app.common.uuid :as uuid] + [app.rpc :as-alias rpc] + [app.rpc.commands.binfile :as binfile] + [backend-tests.helpers :as th] + [clojure.test :as t] + [datoteka.fs :as fs])) + +(t/use-fixtures :once th/state-init) +(t/use-fixtures :each th/database-reset) + +(t/deftest import-binfile-schema-rejects-file-id + ;; N1-06: file-id parameter must be removed from schema for security + ;; The schema should not accept file-id as a valid parameter + (let [schema @#'binfile/schema:import-binfile + validator (sm/lazy-validator schema) + + ;; Valid params without file-id + valid-params {:name "test" + :project-id (uuid/random) + :version 3 + :upload-id (uuid/random)} + + ;; Params with file-id (should be rejected after fix) + params-with-file-id (assoc valid-params :file-id (uuid/random))] + + ;; Valid params without file-id should pass + (t/is (true? (validator valid-params)) + "params without file-id should be valid") + + ;; Params with file-id should fail validation after fix + ;; (Currently this will fail because file-id is still in schema) + (t/is (false? (validator params-with-file-id)) + "params with file-id should be rejected")))