Closed Bug 1695703 Opened 4 years ago Closed 4 years ago

Removing one imap account password sets all imap servers' userAuthenticated property to false

Categories

(MailNews Core :: Networking: IMAP, defect)

defect
Not set
normal

Tracking

(thunderbird_esr78 wontfix)

RESOLVED FIXED
88 Branch
Tracking Status
thunderbird_esr78 --- wontfix

People

(Reporter: alta88, Assigned: addons)

References

(Regression)

Details

(Whiteboard: [STR comment 12])

Attachments

(3 files, 2 obsolete files)

+++ This bug was initially created as a clone of Bug #516464 +++

The patch in Bug 516464 fails to test either the subject argument (to get the right server) or the data argument (for type of change) on a "passwordmgr-storage-changed" notification.

Flags: needinfo?(addons)
Regressed by: 516464

Hmm, looks like I messed up with the review back then. Please contact the manager in charge now. Unbelievable that no one has complained since TB 60.

Flags: needinfo?(addons)
Component: Security → Networking: IMAP
Product: Thunderbird → MailNews Core

It undoubtedly manifests as 'cannot get new messages' or 'cannot sign into imap' and the connection is very non obvious.

I just deleted a stored IMAP password for one account and it seems to work fine. It prompts me for the password for new folder connections for that account and doesn't seems to affect other accounts. Am I missing something?
In my testing I often do this type of thing and haven't noticed a problem.

In console, issue gFolderDisplay.displayedFolder.server.QueryInterface(Ci.nsIImapServerSink).userAuthenticated;
while each (of 2 for example) account's Inbox folder is selected; the result for both will be true if signed in.
Then remove from password manager one of the accounts, test again. Both will be false. And if you look at the code it's obvious that both instances of nsIMsgIncomingServer have an observer that gets the notification and does not test who it's for. And it's then necessary to restart, as getting new messages or reselecting the folders doesn't wfm.

(In reply to alta88 from comment #0)

The patch in Bug 516464 fails to test either the subject argument (to get the right server) or the data argument (for type of change) on a "passwordmgr-storage-changed" notification.

Looking at
https://searchfox.org/mozilla-central/rev/c24ecdc6f5025ea7e60d0691673de030bd5bf411/toolkit/components/passwordmgr/LoginHelper.jsm#1519
and
https://searchfox.org/mozilla-central/search?q=notifyStorageChanged&redirect=false
data appears to be "add/remove/modifyLogin", etc. and the subject is a nsILoginMetaInfo:
https://searchfox.org/mozilla-central/source/toolkit/components/passwordmgr/storage-json.js#214
which has an origin:
https://searchfox.org/mozilla-central/rev/c24ecdc6f5025ea7e60d0691673de030bd5bf411/toolkit/components/passwordmgr/storage-json.js#254.

So as far as I can can see, the code snippet needed is:

nsCOMPtr<nsILoginMetaInfo> login = do_QueryInterface(subject);
nsAutoString origin;
login->GetOrigin(origin);

and then dump out that origin and see whether we can compare it to a property of nsIMsgIncomingServer. And if it doesn't match, ignore the call.

Can you try that, Gene?

This patch shows that comment #5 was mostly wrong. Yes, we get a nsILoginMetaInfo, but that's not useful for anything:
https://searchfox.org/mozilla-central/source/toolkit/components/passwordmgr/nsILoginMetaInfo.idl
It does not have an origin attribute.

I've run out of ideas here. Any hints welcome.

Attachment #9206588 - Attachment is patch: true

Isn't it like this: The ForgetSessionPassword() removes the password from some local "cache". Since the observer is called for all servers, that affects all servers, so as per the bug summary, they all go to unauthenticated. That's not an issue for servers storing the password in the password manager, they will just fetch it again. Only users who don't use the password manager will be affected. (Disclaimer: This could be totally wrong.)

The notification sends an nsLoginInfo which certainly has an origin and it should be very easy to compare to the server url.

https://searchfox.org/mozilla-central/source/toolkit/components/passwordmgr/storage-json.js#275
https://searchfox.org/mozilla-central/source/toolkit/components/passwordmgr/LoginInfo.jsm#16

Attached patch 1695703-reset-password-check.patch (obsolete) (deleted) — Splinter Review
Attachment #9206588 - Attachment is obsolete: true
Attachment #9206679 - Flags: review?(benc)
Comment on attachment 9206679 [details] [diff] [review] 1695703-reset-password-check.patch Review of attachment 9206679 [details] [diff] [review]: ----------------------------------------------------------------- ::: mailnews/compose/src/SmtpServer.jsm @@ +27,5 @@ > > observe(subject, topic, data) { > if (topic == "passwordmgr-storage-changed") { > + // Check that the notification is for this server. > + if (subject && subject.hostname != "smtp://" + this.hostname) { Or better: if ((subject instanceof Ci.nsILoginInfo) && subject.hostname != "smtp://" + this.hostname)

You should also check that data is "removeLogin". It could conceivably be an add or change also. Also note that imap overrides ForgetSessionPassword().

Well, does the overriding matter? If we don't call it, we don't call it, overridden or not. What am I missing?
As for the action: In case of a change we want to forget the cached password, no? I don't know how the add case would look like. The user adds the server string and a password in the password manager? Then we won't have anything cached so far, so forgetting what we don't have won't hurt.

It may not matter, but is more.. robust. The override, just for imap, does one thing: sets userAuthenticated to false.

Sorry, but I don't see what needs to be more robust here. If we get a notification that targets our server, we forget anything we have by calling ForgetSessionPassword(). With the patch that won't be called unnecessarily any more, so no resetting of userAuthenticated will take place. That fixes the bug you reported.

Updated as per comment #10.

Attachment #9206679 - Attachment is obsolete: true
Attachment #9206679 - Flags: review?(benc)
Attachment #9206723 - Flags: review?(benc)

What I'm saying is that for "passwordmgr-storage-changed" notification, you're assuming it will always mean ForgetSessionPassword() in both the base case and override case. Have you considered whether that is always the correct action, even if the data value is not "removeLogin"? So that we can avoid having a Third attempt here - what happens when an "addLogin" is potentially notified?

Hmm, I believe I have considered the actions which aren't "removeLogin" (comment #12 and #14). In case of a notification of a change, we equally need to forget out value. "addLogin" seems hypothetical, the user would have to go into the password manager and fill in the provider, username and password. Even if they do, forgetting what we have (nothing) is not going to do any harm. I don't want to distinguish the different notification cases. Which danger do you see in "addLogin"?

Comment on attachment 9206723 [details] [diff] [review] 1695703-reset-password-check.patch (landed, comment #20) Review of attachment 9206723 [details] [diff] [review]: ----------------------------------------------------------------- LGTM. I think it's fair to treat 'addLogin' as if it were 'modifyLogin' anyway (which it kind of is, in such a case, even if the password manager doesn't know it).
Attachment #9206723 - Flags: review?(benc) → review+

Can you please set "checkin-needed-tb" for me, I can't edit the flags.

Pushed by geoff@darktrojan.net:
https://hg.mozilla.org/comm-central/rev/a70d4c11b52f
Check server before resetting password. r=benc

Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Assignee: nobody → addons
Target Milestone: --- → 88 Branch

Looks like the dreaded "third attempt" was necessary after all. Apologies!
Please set the checkin flag after the review.

Attachment #9206859 - Flags: review?(benc)
Comment on attachment 9206723 [details] [diff] [review] 1695703-reset-password-check.patch (landed, comment #20) > >diff --git a/mailnews/compose/src/SmtpServer.jsm b/mailnews/compose/src/SmtpServer.jsm >--- a/mailnews/compose/src/SmtpServer.jsm >+++ b/mailnews/compose/src/SmtpServer.jsm >@@ -22,16 +22,23 @@ function SmtpServer() { > } > > SmtpServer.prototype = { > QueryInterface: ChromeUtils.generateQI(["nsISmtpServer"]), > classID: Components.ID("{3a75f5ea-651e-4696-9813-848c03da8bbd}"), > > observe(subject, topic, data) { > if (topic == "passwordmgr-storage-changed") { >+ // Check that the notification is for this server. >+ if ( >+ subject instanceof Ci.nsILoginInfo && >+ subject.hostname != "smtp://" + this.hostname >+ ) { >+ return; >+ } > // When the state of the password manager changes we need to clear the > // password from the cache in case the user just removed it. > this.password = ""; > } > }, well this isn't right, it should be !(subject instanceof Ci.nsILoginInfo) ||

The JS code matches the C++ code:

+    nsCOMPtr<nsILoginInfo> loginInfo = do_QueryInterface(aSubject);
+    if (loginInfo) {
[snip]
+      if (!fullName.Equals(NS_ConvertUTF16toUTF8(hostnameInfo))) return NS_OK;

The logic is that if we don't receive a nsILoginInfo here, we proceed as before resetting the password. One could argue that in case we don't receive the nsILoginInfo targeting our server, we shouldn't reset. In practice we will always receive the nsILoginInfo so it doesn't matter.

Ben, please let me know if you prefer alta88's variation and I'll roll the change to both JS and C++ code into the follow-up.

Comment on attachment 9206859 [details] [diff] [review] 1695703-follow-up-mailbox-pop3.patch (landed, comment #32) Review of attachment 9206859 [details] [diff] [review]: ----------------------------------------------------------------- The patch more directly matches the existing code as it is, and it's a fix, so I'm happy for it to land now. But it does feel a little ambiguous because of the generic, fuzzy nature of observe(). How about something like (in JS form here, but same applies to C++): ``` observe(subject, topic, data) { if (topic == "passwordmgr-storage-changed" && subject instanceof Ci.nsILoginInfo && subject.hostname == "smtp://" + this.hostname ) { this.password = ""; } } }, ``` (If nobody else is interested I'm happy to do this in a followup followup :- )
Attachment #9206859 - Flags: review?(benc) → review+

Let's fix it now then.

Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Attachment #9206723 - Attachment description: 1695703-reset-password-check.patch → 1695703-reset-password-check.patch (landed, comment #20)
Attachment #9206859 - Attachment is obsolete: true

Third time lucky?

Attachment #9207096 - Flags: review?(benc)
Attachment #9207096 - Flags: feedback?(alta88)
Attachment #9207096 - Flags: feedback?(alta88) → feedback+
Attachment #9207096 - Flags: review?(benc) → review+

Pushed by thunderbird@calypsoblue.org:
https://hg.mozilla.org/comm-central/rev/f1ca6ee69568
Follow-up: Password manager stores mailbox: instead of pop3:. Also check more specifically. r=benc

Status: REOPENED → RESOLVED
Closed: 4 years ago4 years ago
Resolution: --- → FIXED

Sigh, that now causes test failures. In test_smtpServer.js we have

  // Trigger the change event of password manager.
  Services.logins.setLoginSavingEnabled("smtp://localhost", false);
  equal(server.password, "", "Password should be cleared.");

Looks like this now no longer triggers the password reset. I'll take a look.

Status: RESOLVED → REOPENED
Resolution: FIXED → ---

OK, dumping out this dump(=== ${subject instanceof Ci.nsILoginInfo} |${subject.hostname}| |${this.hostname}| ${data}\n); gives:
=== false |undefined| || hostSavingDisabled
So we have no nsILoginInfo. I suggest we go back to my initial suggestion to only check the hostname when we can.

Whoever comes here first:
Please back out https://hg.mozilla.org/comm-central/rev/f1ca6ee69568 and land the earlier version in attachment 9206859 [details] [diff] [review].

P.S.: BMO is painfully slow right now :-( - Acutally, I get a 503.

Attachment #9206859 - Attachment description: 1695703-follow-up-mailbox-pop3.patch → 1695703-follow-up-mailbox-pop3.patch - Please land this.
Attachment #9206859 - Attachment is obsolete: false
Attachment #9207096 - Attachment description: 1695703-follow-up-mailbox-pop3.patch → 1695703-follow-up-mailbox-pop3.patch - please backout this
Attachment #9207096 - Attachment description: 1695703-follow-up-mailbox-pop3.patch - please backout this → 1695703-follow-up-mailbox-pop3.patch - Backed out

Is there any issue with landing attachment 9206859 [details] [diff] [review]? See comment #24 for the review. Unfortunately Ben's suggestion was implemented and caused the test failure, so we need that original follow-up patch now. Without it, resetting a password for a POP3 account doesn't work at all.

Flags: needinfo?(geoff)
Attachment #9207096 - Attachment description: 1695703-follow-up-mailbox-pop3.patch - Backed out → 1695703-follow-up-mailbox-pop3.patch - Backed out (caused test failure, see comment 29)

Pushed by thunderbird@calypsoblue.org:
https://hg.mozilla.org/comm-central/rev/3a4a3d4aa393
Follow-up: Password manager stores mailbox: instead of pop3:. r=benc

Status: REOPENED → RESOLVED
Closed: 4 years ago4 years ago
Resolution: --- → FIXED
Flags: needinfo?(geoff)

Comment on attachment 9206859 [details] [diff] [review]
1695703-follow-up-mailbox-pop3.patch (landed, comment #32)

This should conclude the work here. In case anyone isn't happy with this solution, please file a follow-up bug.

Attachment #9206859 - Attachment description: 1695703-follow-up-mailbox-pop3.patch - Please land this. → 1695703-follow-up-mailbox-pop3.patch (landed, comment #32)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: