From 3be07cccedc2c7259c8d8ef26e57c9c927b6448d Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 18 Aug 2026 14:37:51 +0200 Subject: [PATCH] :bug: Add minimum validation for total-chunks in upload session (#11104) The create-upload-session RPC method accepted total-chunks values of 0 or negative numbers without validation, creating inconsistent session state. Add {:min 1} constraint to the schema to reject invalid values at input validation. Closes #11103 AI-assisted-by: qwen3.7-plus --- backend/src/app/rpc/commands/media.clj | 2 +- backend/test/backend_tests/rpc_media_test.clj | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/backend/src/app/rpc/commands/media.clj b/backend/src/app/rpc/commands/media.clj index 4cf3c68029..3dff04fa10 100644 --- a/backend/src/app/rpc/commands/media.clj +++ b/backend/src/app/rpc/commands/media.clj @@ -294,7 +294,7 @@ (def ^:private schema:create-upload-session [:map {:title "create-upload-session"} - [:total-chunks ::sm/int]]) + [:total-chunks [::sm/int {:min 1}]]]) (def ^:private schema:create-upload-session-result [:map {:title "create-upload-session-result"} diff --git a/backend/test/backend_tests/rpc_media_test.clj b/backend/test/backend_tests/rpc_media_test.clj index d230b03769..d22eabe64b 100644 --- a/backend/test/backend_tests/rpc_media_test.clj +++ b/backend/test/backend_tests/rpc_media_test.clj @@ -718,6 +718,24 @@ (t/is (= :max-quote-reached (-> out :error ex-data :code))) (t/is (= "upload-chunks-per-session" (-> out :error ex-data :target)))))) +(t/deftest chunked-upload-invalid-total-chunks + ;; total-chunks must be at least 1; zero and negative values are rejected + ;; with a :validation error. + (let [prof (th/create-profile* 1)] + ;; zero total-chunks + (let [out (th/command! {::th/type :create-upload-session + ::rpc/profile-id (:id prof) + :total-chunks 0})] + (t/is (some? (:error out))) + (t/is (= :validation (-> out :error ex-data :type)))) + + ;; negative total-chunks + (let [out (th/command! {::th/type :create-upload-session + ::rpc/profile-id (:id prof) + :total-chunks -1})] + (t/is (some? (:error out))) + (t/is (= :validation (-> out :error ex-data :type)))))) + (t/deftest chunked-upload-invalid-chunk-index ;; Both a negative index and an index >= total-chunks must be ;; rejected with a :validation / :invalid-chunk-index error.