From 9b192cfd8e1853aad2ef89660a55b7e2fe254027 Mon Sep 17 00:00:00 2001 From: Ian Bicking Date: Wed, 5 Oct 2016 14:29:31 -0500 Subject: [PATCH] Fix #1704, check for the user auth cookie when checking if the browser is logged in. --- addon/lib/get-cookies.js | 10 +++++++++- addon/lib/user.js | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/addon/lib/get-cookies.js b/addon/lib/get-cookies.js index e03a9d0522..446bcbcbcd 100644 --- a/addon/lib/get-cookies.js +++ b/addon/lib/get-cookies.js @@ -1,6 +1,8 @@ -const { Ci } = require("chrome"); +const { Ci, Cc } = require("chrome"); const { Services } = require("resource://gre/modules/Services.jsm"); const { URL } = require("sdk/url"); +const cookieService = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService); +const { newURI } = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); function getCookieObjects(host) { let result = []; @@ -50,3 +52,9 @@ exports.safeCookieSummary = function (host) { return `Could not capture cookies for ${host}: ${e}`; } }; + +exports.hasCookieForBackend = function (backend) { + let backendUrl = newURI(backend, null, null); + let cookieString = cookieService.getCookieStringFromHttp(backendUrl, backendUrl, null); + return cookieString.search(/user=/) != -1; +}; diff --git a/addon/lib/user.js b/addon/lib/user.js index 907ba8aff8..18f444a5ec 100644 --- a/addon/lib/user.js +++ b/addon/lib/user.js @@ -8,6 +8,7 @@ const { URL } = require('sdk/url'); const { FxAccountsOAuthClient } = Cu.import("resource://gre/modules/FxAccountsOAuthClient.jsm", {}); const { FxAccountsProfileClient } = Cu.import("resource://gre/modules/FxAccountsProfileClient.jsm", {}); const { deviceInfo } = require('./deviceinfo'); +const { hasCookieForBackend } = require("./get-cookies"); let initialized = false; let sentryPublicDSN = ""; @@ -44,7 +45,7 @@ exports.deleteEverything = function () { }; exports.isInitialized = function () { - return initialized; + return initialized && hasCookieForBackend(require("./main").getBackend()); }; let cachedBackend, cachedReason; // eslint-disable-line no-unused-vars