Ver Fonte

HUE-5703 [security] Upgrade totalStorage and pass along a secure cookie fallback in apiHelper

Enrico Berti há 8 anos atrás
pai
commit
e20d91afb1

+ 10 - 7
desktop/core/src/desktop/static/desktop/ext/js/jquery/plugins/jquery.total-storage.min.js

@@ -1,4 +1,4 @@
-/*
+/**
  * TotalStorage
  *
  * Copyright (c) 2012 Jared Novack & Upstatement (upstatement.com)
@@ -12,11 +12,14 @@
  * @name $.totalStorage
  * @cat Plugins/Cookie
  * @author Jared Novack/jared@upstatement.com
- * @version 1.1.2
+ * @version 1.1.3
  * @url http://upstatement.com/blog/2012/01/jquery-local-storage-done-right-and-easy/
  */
-
-(function(c,h){var d="undefined"===typeof window.localStorage?h:window.localStorage,e;e="undefined"==typeof d||"undefined"==typeof window.JSON?!1:!0;c.totalStorage=function(b,a){return c.totalStorage.impl.init(b,a)};c.totalStorage.setItem=function(b,a){return c.totalStorage.impl.setItem(b,a)};c.totalStorage.getItem=function(b){return c.totalStorage.impl.getItem(b)};c.totalStorage.getAll=function(){return c.totalStorage.impl.getAll()};c.totalStorage.deleteItem=function(b){return c.totalStorage.impl.deleteItem(b)};
-c.totalStorage.impl={init:function(b,a){return"undefined"!=typeof a?this.setItem(b,a):this.getItem(b)},setItem:function(b,a){if(!e)try{return c.cookie(b,a),a}catch(g){console.log("Local Storage not supported by this browser. Install the cookie plugin on your site to take advantage of the same functionality. You can get it at https://github.com/carhartl/jquery-cookie")}var f=JSON.stringify(a);d.setItem(b,f);return this.parseResult(f)},getItem:function(b){if(!e)try{return this.parseResult(c.cookie(b))}catch(a){return null}b=
-d.getItem(b);return this.parseResult(b)},deleteItem:function(b){if(!e)try{return c.cookie(b,null),!0}catch(a){return!1}d.removeItem(b);return!0},getAll:function(){var b=[];if(e)for(var a in d)a.length&&b.push({key:a,value:this.parseResult(d.getItem(a))});else try{var g=document.cookie.split(";");for(a=0;a<g.length;a++){var f=g[a].split("=")[0];b.push({key:f,value:this.parseResult(c.cookie(f))})}}catch(h){return null}return b},parseResult:function(b){var a;try{a=JSON.parse(b),"undefined"==typeof a&&
-(a=b),"true"==a&&(a=!0),"false"==a&&(a=!1),parseFloat(a)==a&&"object"!=typeof a&&(a=parseFloat(a))}catch(c){a=b}return a}}})(jQuery);
+!function(t,e){var o,r,n="test"
+if("localStorage"in window)try{r="undefined"==typeof window.localStorage?e:window.localStorage,o="undefined"!=typeof r&&"undefined"!=typeof window.JSON,window.localStorage.setItem(n,"1"),window.localStorage.removeItem(n)}catch(t){o=!1}t.totalStorage=function(e,o,r){return t.totalStorage.impl.init(e,o,r)},t.totalStorage.setItem=function(e,o,r){return t.totalStorage.impl.setItem(e,o,r)},t.totalStorage.getItem=function(e){return t.totalStorage.impl.getItem(e)},t.totalStorage.getAll=function(){return t.totalStorage.impl.getAll()},t.totalStorage.deleteItem=function(e){return t.totalStorage.impl.deleteItem(e)},t.totalStorage.impl={init:function(t,e,o){return"undefined"!=typeof e?this.setItem(t,e,o):this.getItem(t)},setItem:function(e,n,a){if(!o)try{return t.cookie(e,n,a),n}catch(t){console.log("Local Storage not supported by this browser. Install the cookie plugin on your site to take advantage of the same functionality. You can get it at https://github.com/carhartl/jquery-cookie")}var l=JSON.stringify(n)
+return r.setItem(e,l),this.parseResult(l)},getItem:function(e){if(!o)try{return this.parseResult(t.cookie(e))}catch(t){return null}var n=r.getItem(e)
+return this.parseResult(n)},deleteItem:function(e){if(!o)try{return t.cookie(e,null),!0}catch(t){return!1}return r.removeItem(e),!0},getAll:function(){var e=[]
+if(o)for(var n in r)n.length&&e.push({key:n,value:this.parseResult(r.getItem(n))})
+else try{for(var a=document.cookie.split(";"),l=0;l<a.length;l++){var i=a[l].split("="),u=i[0]
+e.push({key:u,value:this.parseResult(t.cookie(u))})}}catch(t){return null}return e},parseResult:function(t){var e
+try{e=JSON.parse(t),"undefined"==typeof e&&(e=t),"true"==e&&(e=!0),"false"==e&&(e=!1),parseFloat(e)==e&&"object"!=typeof e&&(e=parseFloat(e))}catch(o){e=t}return e}}}(jQuery)

+ 2 - 2
desktop/core/src/desktop/static/desktop/js/apiHelper.js

@@ -129,10 +129,10 @@ var ApiHelper = (function () {
     var cachedData = $.totalStorage("hue.user.settings." + self.getTotalStorageUserPrefix(owner)) || {};
     if (typeof value !== 'undefined' && value !== null) {
       cachedData[id] = value;
-      $.totalStorage("hue.user.settings." + self.getTotalStorageUserPrefix(owner), cachedData);
+      $.totalStorage("hue.user.settings." + self.getTotalStorageUserPrefix(owner), cachedData, { secure: window.location.protocol.indexOf('https') > -1 });
     } else if (cachedData[id]) {
       delete cachedData[id];
-      $.totalStorage("hue.user.settings." + self.getTotalStorageUserPrefix(owner), cachedData);
+      $.totalStorage("hue.user.settings." + self.getTotalStorageUserPrefix(owner), cachedData, { secure: window.location.protocol.indexOf('https') > -1 });
     }
   };