From cfffcdf0b74a445b3b9e8aa7be2f99a0c875015f Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 27 Feb 2023 14:44:46 -0800 Subject: [PATCH] GUACAMOLE-1745: Ensure deep copies of session storage are created only if necessary. --- .../storage/services/sessionStorageFactory.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/guacamole/src/main/frontend/src/app/storage/services/sessionStorageFactory.js b/guacamole/src/main/frontend/src/app/storage/services/sessionStorageFactory.js index 9ca7b0db7..da53cdfe9 100644 --- a/guacamole/src/main/frontend/src/app/storage/services/sessionStorageFactory.js +++ b/guacamole/src/main/frontend/src/app/storage/services/sessionStorageFactory.js @@ -70,11 +70,22 @@ angular.module('storage').factory('sessionStorageFactory', ['$injector', functio if (typeof template === 'function') getter = template; - // Otherwise, always create a deep copy - else - getter = function getCopy() { - return angular.copy(template); + // Otherwise, create and maintain a deep copy (automatically cached to + // avoid "infdig" errors) + else { + var cached = angular.copy(template); + getter = function getIndependentCopy() { + + // Reset to template only if changed externally, such that + // session storage values can be safely used in scope watches + // even if not logged in + if (!_.isEqual(cached, template)) + cached = angular.copy(template); + + return cached; + }; + } /** * The current value of this storage, or undefined if not yet set.