From 80dea409c623504dd5197410eec58b4a8cf2dd56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elena=20Torr=C3=B3?= Date: Thu, 3 Sep 2026 12:15:35 +0200 Subject: [PATCH] :bug: Fix share-link viewers unable to load file fragments (#11484) --- backend/src/app/rpc/commands/files.clj | 18 ++++++++++++++---- frontend/src/app/main/data/viewer.cljs | 11 ++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/backend/src/app/rpc/commands/files.clj b/backend/src/app/rpc/commands/files.clj index 435b83afff..b7d04a29a3 100644 --- a/backend/src/app/rpc/commands/files.clj +++ b/backend/src/app/rpc/commands/files.clj @@ -241,6 +241,18 @@ (some-> (db/get cfg :file-data {:file-id file-id :id fragment-id :type "fragment"}) (update :data blob/decode))) +(defn- check-fragment-scope! + "Checks that the fragment is reachable from the pages authorized by + the share-link. Raises a :not-found exception if the fragment is not reachable." + [cfg file-id fragment-id pages] + (let [fdata (-> (bfc/get-file cfg file-id :read-only? true) + (get :data) + (update :pages-index select-keys pages))] + (when-not (contains? (feat.fdata/get-used-pointer-ids fdata) fragment-id) + (ex/raise :type :not-found + :code :object-not-found + :hint "object not found")))) + (sv/defmethod ::get-file-fragment "Retrieve a file fragment by its ID. Only authenticated users." {::doc/added "1.17" @@ -250,11 +262,9 @@ [cfg {:keys [::rpc/profile-id file-id fragment-id share-id]}] (db/run! cfg (fn [cfg] (let [perms (perms/get-file-read-permissions cfg profile-id file-id share-id)] - (when (= :share-link (:type perms)) - (ex/raise :type :not-found - :code :object-not-found - :hint "object not found")) (check-read-permissions! perms) + (when (= :share-link (:type perms)) + (check-fragment-scope! cfg file-id fragment-id (:pages perms))) (-> (get-file-fragment cfg file-id fragment-id) (rph/with-http-cache long-cache-duration)))))) diff --git a/frontend/src/app/main/data/viewer.cljs b/frontend/src/app/main/data/viewer.cljs index f847cd862d..c5f20ce24d 100644 --- a/frontend/src/app/main/data/viewer.cljs +++ b/frontend/src/app/main/data/viewer.cljs @@ -326,11 +326,12 @@ (filter #(= page-id (:page-id %))) (d/index-by :id) (assoc state :comment-threads))) - (on-error [{:keys [type] :as err}] - (if (or (= :authentication type) - (= :not-found type)) - (rx/empty) - (rx/throw err)))] + (on-error [cause] + (let [{:keys [type]} (ex-data cause)] + (if (or (= :authentication type) + (= :not-found type)) + (rx/empty) + (rx/throw cause))))] (ptk/reify ::fetch-comment-threads ptk/WatchEvent