Closed
Bug 1214071
Opened 10 years ago
Closed 9 years ago
Add APIs get/removeCookiesWithOriginAttributes() in nsICookieManager2.idl
Categories
(Core :: Networking: Cookies, defect, P1)
Core
Networking: Cookies
Tracking
()
People
(Reporter: ethan, Assigned: jhao)
References
Details
(Whiteboard: [necko-backlog][oa])
Attachments
(2 files, 9 obsolete files)
|
5.37 KB,
patch
|
jhao
:
review+
|
Details | Diff | Splinter Review |
|
11.61 KB,
patch
|
ehsan.akhgari
:
review+
|
Details | Diff | Splinter Review |
This is a follow-up of bug 1165267 (Use OriginAttributes for nsCookieService).
We shall add two new interfaces in nsICookieManager2.idl to replace the original get/removeCookiesForApp().
- getCookiesForOriginAttributes()
- removeCookiesForOriginAttributes()
| Reporter | ||
Comment 1•10 years ago
|
||
This pair of functions should only be used while uninstalling apps. They are not so critical for now. Set priority as P4.
Assignee: nobody → ettseng
Priority: -- → P4
Target Milestone: --- → FxOS-S10 (30Oct)
| Reporter | ||
Updated•10 years ago
|
Blocks: nsec-origins
| Reporter | ||
Updated•10 years ago
|
Summary: Add APIs get/removeCookiesForOriginAttributes() in nsICookieManager2 → Add APIs get/removeCookiesForOriginAttributes() in nsICookieManager2.idl
| Reporter | ||
Comment 2•10 years ago
|
||
I think we cannot remove the original get/removeCookiesForApp() functions because they are used by extensions. But we could add two new functions for app uninstallation, which is done in dom/apps/Webapps.jsm.
Bobby, could you provide feedback on this IDL change?
Attachment #8672900 -
Flags: feedback?(bobbyholley)
Comment 3•10 years ago
|
||
Comment on attachment 8672900 [details] [diff] [review]
bug-1214071-wip.patch
Review of attachment 8672900 [details] [diff] [review]:
-----------------------------------------------------------------
Looks like only the b2g simulator uses {get,remove}CookiesForApp:
https://mxr.mozilla.org/addons/search?string=getCookiesForApp
https://mxr.mozilla.org/addons/search?string=removeCookiesForApp
So I'd say we should just remove those two methods.
Attachment #8672900 -
Flags: feedback?(bobbyholley) → feedback+
| Reporter | ||
Comment 4•10 years ago
|
||
(In reply to Bobby Holley (:bholley) from comment #3)
> Comment on attachment 8672900 [details] [diff] [review]
> Looks like only the b2g simulator uses {get,remove}CookiesForApp:
> So I'd say we should just remove those two methods.
Thanks Bobby for your prompt response!
I have another question. I don't know how to pass jsval in C++.
Could you give me some hint, such as sample code somewhere?
| Reporter | ||
Updated•10 years ago
|
Flags: needinfo?(bobbyholley)
Comment 5•10 years ago
|
||
If you need to call this from C++, you should have a separate API entry point that doesn't go through XPIDL.
A good example here is the way we create codebase principals. nsIScriptSecurityManager::createCodebasePrincipal is the script-accessible side, and that forwards to BasePrincipal::CreateCodebasePrincipal, which C++ callers use directly.
Flags: needinfo?(bobbyholley)
| Reporter | ||
Comment 6•10 years ago
|
||
(In reply to Bobby Holley (:bholley) from comment #5)
> A good example here is the way we create codebase principals.
> nsIScriptSecurityManager::createCodebasePrincipal is the script-accessible
> side, and that forwards to BasePrincipal::CreateCodebasePrincipal, which C++
> callers use directly.
Thank you Bobby!
I'll follow your way to do this.
| Reporter | ||
Updated•10 years ago
|
Status: NEW → ASSIGNED
make this blocks Bug 1233136 as removeCookiesForOriginAttributes should also consider pattern matching in clear-origin-data.
Blocks: 1233136
| Reporter | ||
Comment 8•10 years ago
|
||
While working on this bug, we found these two lines are not necessary:
https://dxr.mozilla.org/mozilla-central/source/dom/apps/Webapps.jsm#704
permMgr.removePermissionsWithAttributes(JSON.stringify(attrs));
Services.cookies.removeCookiesForApp(localId, false);
nsPermissionManager and nsCookieService both observe the "clear-origin-data" event, which call their RemovePermissionsWithAttributes() and RemoveCookiesForApps() respectively.
I commented out these two lines and ran TreeHerder:
https://treeherder.mozilla.org/#/jobs?repo=try&revision=9b4624f44466
I think we can remove these two lines of codes.
Fabrice, do you have any concern about this?
Flags: needinfo?(fabrice)
| Reporter | ||
Comment 10•9 years ago
|
||
This patch adds RemoveCookiesWithAttributes in nsCookieService.
Basic manual tests was executed.
Need to write some automation test cases.
Attachment #8672900 -
Attachment is obsolete: true
| Reporter | ||
Comment 11•9 years ago
|
||
Comment 12•9 years ago
|
||
Ethan, can you flag this bug for review? Thanks!
| Reporter | ||
Comment 13•9 years ago
|
||
(In reply to Tanvi Vyas [:tanvi] from comment #12)
> Ethan, can you flag this bug for review? Thanks!
Hi Tanvi, sorry I didn't set aside time to write the test patch yet.
And I suppose to raise the review flag when I have test case.
Does this bug block anything on you? Is it at high stake now?
If so, maybe I can try to land the patch first and add test cases as a follow-up.
Flags: needinfo?(tanvi)
Updated•9 years ago
|
Flags: needinfo?(huseby)
Comment 14•9 years ago
|
||
(In reply to Ethan Tseng [:ethan] from comment #13)
> (In reply to Tanvi Vyas [:tanvi] from comment #12)
> > Ethan, can you flag this bug for review? Thanks!
>
> Hi Tanvi, sorry I didn't set aside time to write the test patch yet.
> And I suppose to raise the review flag when I have test case.
> Does this bug block anything on you? Is it at high stake now?
> If so, maybe I can try to land the patch first and add test cases as a
> follow-up.
Hi Ethan,
I'm not sure how or if this blocks the user context id (containers) project, since I'm not familiar with this code. I am needinfo'ing baku to look at this in more detail.
I have also needinfo'ed Dave since I believe he had some comments on the patch.
Flags: needinfo?(tanvi) → needinfo?(amarchesini)
Comment 15•9 years ago
|
||
As far as I can tell, we are not blocked by this. CookieManager is working correctly for containers in desktop and we don't have needs for such methods.
Flags: needinfo?(amarchesini)
| Reporter | ||
Comment 16•9 years ago
|
||
(In reply to Andrea Marchesini (:baku) from comment #15)
> As far as I can tell, we are not blocked by this. CookieManager is working
> correctly for containers in desktop and we don't have needs for such methods.
Thank you Andrea!
Then I'll stick to my original plan to finish this bug with a test patch. Thanks!
Comment 17•9 years ago
|
||
I don't think this patch is needed because:
1) appId is going away.
2) the existing cookie isolation code seems to be doing the right thing already.
Unless I'm missing something, I don't think this change is needed.
Flags: needinfo?(huseby)
Comment 18•9 years ago
|
||
(In reply to Dave Huseby [:huseby] from comment #17)
> I don't think this patch is needed because:
>
> 1) appId is going away.
From where exactly?
| Reporter | ||
Comment 19•9 years ago
|
||
(In reply to Dave Huseby [:huseby] from comment #17)
> I don't think this patch is needed because:
> 1) appId is going away.
> 2) the existing cookie isolation code seems to be doing the right thing
> already.
> Unless I'm missing something, I don't think this change is needed.
As I know, appId is not gone. It is encapsulated in OriginAttribute.
Although Firefox Desktop does not need this patch (seems it uses other ways to clean up cookies), I think this patch is still needed for potential use in the future.
Updated•9 years ago
|
Whiteboard: [necko-backlog]
| Assignee | ||
Updated•9 years ago
|
Assignee: ettseng → jhao
| Reporter | ||
Comment 20•9 years ago
|
||
Unbitrotted the patch.
Jonathan, thanks for taking this bug!
Attachment #8706724 -
Attachment is obsolete: true
Comment 21•9 years ago
|
||
Assume we have pass the following OriginAttributes into the get/removeCookiesForOriginAttributes() method:
usercontext id = 1
appid = 5
Will this get/remove all cookies with appid = 5? Or all cookies with appid =5 && user context =1? I assume the later.
(In reply to Tanvi Vyas - behind on needinfos [:tanvi] from comment #21)
> Assume we have pass the following OriginAttributes into the
> get/removeCookiesForOriginAttributes() method:
> usercontext id = 1
> appid = 5
>
> Will this get/remove all cookies with appid = 5? Or all cookies with appid
> =5 && user context =1? I assume the later.
Yes, it will be the later one. (appId=5 && userContext=1)
It will use OriginAttributesPattern.Matches to do the matching.
http://lxr.mozilla.org/mozilla-central/source/caps/BasePrincipal.h#156
Comment 23•9 years ago
|
||
The devtools might need this because right now Devtools depends on the getCookiesFromHost of the nsICookieManager2 to acquire cookies for a specific host. However, the getCookiesFromHost only use default context id to access cookies which will cause devtools cannot get correct cookies when user context id involves. So devtools should use getCookiesFromOriginAttributes to acquire cookies with correct user context id.
Updated•9 years ago
|
Whiteboard: [necko-backlog] → [necko-backlog][oa]
| Assignee | ||
Comment 24•9 years ago
|
||
Hi Ethan,
In the summary and previous comments, the API's name is "get/removeCookiesForOriginAttributes()", but in your patch, its name is removeCookiesWithAttributes().
Is this intentional?
Flags: needinfo?(ettseng)
| Reporter | ||
Comment 25•9 years ago
|
||
(In reply to Jonathan Hao [:jhao] from comment #24)
> Hi Ethan,
> In the summary and previous comments, the API's name is
> "get/removeCookiesForOriginAttributes()", but in your patch, its name is
> removeCookiesWithAttributes().
> Is this intentional?
Yes, it was intentional.
The reason is because nsIPermissionManager uses the name |removePermissionsWithAttributes|,
and I just wanted to be consistent with it.
However, I think |Attributes| alone is too general so I decided to use |OriginAttributes|.
If there is no objection, let's use |get/removeCookiesWithOriginAttributes|.
Thanks!
Flags: needinfo?(ettseng)
Summary: Add APIs get/removeCookiesForOriginAttributes() in nsICookieManager2.idl → Add APIs get/removeCookiesWithOriginAttributes() in nsICookieManager2.idl
| Assignee | ||
Comment 26•9 years ago
|
||
This is a test for removeCookiesWithOriginAttributes().
By this test, I found a bug in Ethan's patch.
> for (auto iter = mDBState->hostTable.Iter(); !iter.Done(); iter.Next()) {
> nsCookieEntry* entry = iter.Get();
>
> if (!aPattern.Matches(entry->mOriginAttributes)) {
> continue;
> }
>
> // Pattern matches. Delete all cookies within this nsCookieEntry.
> const nsCookieEntry::ArrayType& cookies = entry->GetCookies();
>
> for (nsCookieEntry::IndexType i = 0; i < cookies.Length(); ++i) {
> nsCookie *cookie = cookies[i];
>
> nsAutoCString host;
> cookie->GetHost(host);
>
> nsAutoCString name;
> cookie->GetName(name);
>
> nsAutoCString path;
> cookie->GetPath(path);
>
> // Remove the cookie.
> Remove(host, entry->mOriginAttributes, name, path, false);
> }
>
> }
Removing elements in a data structure while traversing it can cause problems. In fact, I created three cookies in my test, and the second one is not removed because of this bug.
I'll fix this bug, and also add an implementation of GetCookiesWithOriginAttributes() in later patches.
| Assignee | ||
Comment 27•9 years ago
|
||
| Assignee | ||
Comment 28•9 years ago
|
||
I fixed the bug mentioned in Comment 26, and added GetCookiesWithOriginAttributes().
| Assignee | ||
Updated•9 years ago
|
Attachment #8738954 -
Attachment is obsolete: true
| Assignee | ||
Comment 29•9 years ago
|
||
Browser tests for Get/RemoveCookiesWithOriginAttributes().
| Assignee | ||
Updated•9 years ago
|
Attachment #8748556 -
Attachment is obsolete: true
| Reporter | ||
Comment 30•9 years ago
|
||
(In reply to Jonathan Hao [:jhao] from comment #26)
> By this test, I found a bug in Ethan's patch.
> Removing elements in a data structure while traversing it can cause
> problems. In fact, I created three cookies in my test, and the second one is
> not removed because of this bug.
Nice catch!
Thanks, Jonathan!
| Assignee | ||
Comment 31•9 years ago
|
||
Hi Ehsan, could you review these patches? Thanks.
Attachment #8749526 -
Flags: review?(ehsan)
| Assignee | ||
Updated•9 years ago
|
Attachment #8749144 -
Attachment is obsolete: true
| Assignee | ||
Comment 32•9 years ago
|
||
Also this one. Thanks.
Attachment #8749527 -
Flags: review?(ehsan)
| Assignee | ||
Updated•9 years ago
|
Attachment #8749145 -
Attachment is obsolete: true
| Reporter | ||
Updated•9 years ago
|
Priority: P4 → P1
Target Milestone: FxOS-S10 (30Oct) → ---
Comment 33•9 years ago
|
||
Comment on attachment 8749526 [details] [diff] [review]
Replace get/removeCookiesForApp() with get/removeCookiesWithOriginAttributes()
Review of attachment 8749526 [details] [diff] [review]:
-----------------------------------------------------------------
This looks good but I'd like to get an answer about the Remove() question below before r+ing...
::: netwerk/cookie/nsCookieService.cpp
@@ +4347,5 @@
> NS_WARNING("No DBState! Profile already closed?");
> return NS_ERROR_NOT_AVAILABLE;
> }
>
> + if (aPattern.mAppId.WasPassed() && aPattern.mAppId.Value() != NECKO_UNKNOWN_APP_ID) {
I think you meant to check for equality here, not inequality, otherwise you're changing the meaning of this check!
@@ +4420,5 @@
> + nsresult rv = Remove(host, entry->mOriginAttributes, name, path, false);
> + NS_ENSURE_SUCCESS(rv, rv);
> +
> + // If the array size remains the same after removal, something wrong happens
> + // Return to avoid infinite loops
Shouldn't Remove() above return a failure code in this case? I'd like to understand why this check is needed -- did you hit this issue while testing?
::: netwerk/cookie/nsICookieManager2.idl
@@ -132,2 @@
> */
> - void removeCookiesForApp(in unsigned long appId,
This is used by a bunch of b2g add-ons such as the simulators: <https://mxr.mozilla.org/addons/search?string=removeCookiesForApp&find=&findi=&filter=%5E%5B%5E%5C0%5D*%24&hitlimit=&tree=addons> I'm hoping that we won't need to update those consumers...
Attachment #8749526 -
Flags: review?(ehsan)
Updated•9 years ago
|
Attachment #8749527 -
Flags: review?(ehsan) → review+
| Assignee | ||
Comment 34•9 years ago
|
||
(In reply to :Ehsan Akhgari (busy, don't ask for review please) from comment #33)
> @@ +4420,5 @@
> > + nsresult rv = Remove(host, entry->mOriginAttributes, name, path, false);
> > + NS_ENSURE_SUCCESS(rv, rv);
> > +
> > + // If the array size remains the same after removal, something wrong happens
> > + // Return to avoid infinite loops
>
> Shouldn't Remove() above return a failure code in this case? I'd like to
> understand why this check is needed -- did you hit this issue while testing?
Ehsan, thanks for your review.
In Remove(), if we can't find a cookie with the specified (host, origin attributes, name, path), it does not return a failure code, and the outside loop won't terminate. Nonetheless, if removeCookiesWithOriginAttributes() works correctly, this cannot happen because we always pass an existing cookie's information to Remove().
If you think the check is redundant, I can remove it.
| Assignee | ||
Comment 35•9 years ago
|
||
(In reply to :Ehsan Akhgari (busy, don't ask for review please) from comment #33)
> ::: netwerk/cookie/nsICookieManager2.idl
> @@ -132,2 @@
> > */
> > - void removeCookiesForApp(in unsigned long appId,
>
> This is used by a bunch of b2g add-ons such as the simulators:
> <https://mxr.mozilla.org/addons/
> search?string=removeCookiesForApp&find=&findi=&filter=%5E%5B%5E%5C0%5D*%24&hi
> tlimit=&tree=addons> I'm hoping that we won't need to update those
> consumers...
Hi Fabrice,
Do we need to update those b2g add-ons?
Flags: needinfo?(fabrice)
Updated•9 years ago
|
Iteration: --- → 49.2 - May 23
Comment 36•9 years ago
|
||
Hi Jonathan,
No you don't have to update these add-ons.
Flags: needinfo?(fabrice)
| Assignee | ||
Comment 37•9 years ago
|
||
| Assignee | ||
Comment 38•9 years ago
|
||
Update commit message.
| Assignee | ||
Updated•9 years ago
|
Attachment #8749527 -
Attachment is obsolete: true
| Assignee | ||
Comment 39•9 years ago
|
||
Thanks, Fabrice.
Ehsan, please review again. Thanks.
Attachment #8751555 -
Flags: review?(ehsan)
| Assignee | ||
Updated•9 years ago
|
Attachment #8749526 -
Attachment is obsolete: true
| Assignee | ||
Updated•9 years ago
|
Attachment #8751549 -
Flags: review+
| Assignee | ||
Comment 40•9 years ago
|
||
| Assignee | ||
Comment 41•9 years ago
|
||
I saw a build failure on Windows, so I fixed a return type.
Attachment #8751563 -
Flags: review?(ehsan)
| Assignee | ||
Updated•9 years ago
|
Attachment #8751555 -
Attachment is obsolete: true
Attachment #8751555 -
Flags: review?(ehsan)
Updated•9 years ago
|
Attachment #8751563 -
Flags: review?(ehsan) → review+
| Assignee | ||
Updated•9 years ago
|
Keywords: checkin-needed
Comment 42•9 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/7b6472147fdf
https://hg.mozilla.org/integration/mozilla-inbound/rev/29944095078e
Keywords: checkin-needed
Comment 43•9 years ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/7b6472147fdf
https://hg.mozilla.org/mozilla-central/rev/29944095078e
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
status-firefox49:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla49
You need to log in
before you can comment on or make changes to this bug.
Description
•