Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/231709

Change subject: Avoid throwing SecurityError on window.localStorage access
......................................................................

Avoid throwing SecurityError on window.localStorage access

When cookies are disabled in Firefox, merely referencing window.localStorage is
enough to cause Firefox to throw a SecurityError exception. Avoid it by
wrapping localStorage operations in try / catch, as we already do in
mediawiki.js (and as CentralAuth already does in anon-set.js).

Change-Id: I28399cf8b63328ee34316b785f2d091f6f052224
---
M modules/ext.centralauth.centralautologin.clearcookie.js
M modules/ext.centralauth.centralautologin.js
M modules/inline/anon-remove.js
3 files changed, 9 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralAuth 
refs/changes/09/231709/1

diff --git a/modules/ext.centralauth.centralautologin.clearcookie.js 
b/modules/ext.centralauth.centralautologin.clearcookie.js
index affae5d..1d7d45f 100644
--- a/modules/ext.centralauth.centralautologin.clearcookie.js
+++ b/modules/ext.centralauth.centralautologin.clearcookie.js
@@ -1,8 +1,8 @@
 ( function ( mw ) {
        if ( mw.config.get( 'wgUserName' ) !== null ) {
-               if ( 'localStorage' in window && window.localStorage ) {
+               try {
                        localStorage.removeItem( 'CentralAuthAnon' );
-               }
+               } catch ( e ) {}
                if ( /(^|; )CentralAuthAnon=1/.test( document.cookie ) ) {
                        document.cookie = 'CentralAuthAnon=0; expires=Thu, 01 
Jan 1970 00:00:01 GMT; path=/';
                }
diff --git a/modules/ext.centralauth.centralautologin.js 
b/modules/ext.centralauth.centralautologin.js
index bad59cf..7fc71c6 100644
--- a/modules/ext.centralauth.centralautologin.js
+++ b/modules/ext.centralauth.centralautologin.js
@@ -6,9 +6,11 @@
 
        // Do we already know we're logged out centrally?
        if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'Userlogin' ) {
-               if ( 'localStorage' in window && window.localStorage && 
+localStorage.getItem( 'CentralAuthAnon' ) > new Date().getTime() ) {
-                       return;
-               }
+               try {
+                       if ( +localStorage.getItem( 'CentralAuthAnon' ) > new 
Date().getTime() ) {
+                               return;
+                       }
+               } catch ( e ) {}
 
                // Can't use $.cookie(), because we want to check this at the 
top of
                // the page and that isn't loaded until the bottom.
diff --git a/modules/inline/anon-remove.js b/modules/inline/anon-remove.js
index 1c37492..698a398 100644
--- a/modules/inline/anon-remove.js
+++ b/modules/inline/anon-remove.js
@@ -1,6 +1,6 @@
-if ( 'localStorage' in window && window.localStorage ) {
+try {
        localStorage.removeItem( 'CentralAuthAnon' );
-}
+} catch ( e ) {}
 if ( /(^|; )CentralAuthAnon=/.test( document.cookie ) ) {
        document.cookie = 'CentralAuthAnon=0; expires=Thu, 01 Jan 1970 00:00:01 
GMT; path=/';
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/231709
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I28399cf8b63328ee34316b785f2d091f6f052224
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to