Cannot delete cookies that do not have a domain, set by local file:-URLs
Categories
(WebExtensions :: General, defect, P3)
Tracking
(Not tracked)
People
(Reporter: ysard_git, Unassigned)
References
Details
(Whiteboard: [necko-triaged])
Comment 1•7 years ago
|
||
Updated•7 years ago
|
Comment 3•7 years ago
|
||
First of all, I'm sorry for the response time I completely forgot this issue.
Then, actually I managed to delete these cookies from about:preferences#privacy
, it is a reporting error and I'm sorry about that.
However, the problem of deleting from the web-ext cookies API seems very real.
Let's design this html page to save somewhere and open it in Firefox:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<p>hello world</p>
<script>
document.cookie = "username=John Doe; expires=Thu, 31 Dec 2031 12:00:00 UTC; path=/";
document.cookie = "useralias=JohnDoe";
</script>
</body>
</html>
it creates 2 cookies with empty domains whose description is as returned by browser.cookies.getAll():
domain: ""
expirationDate: 1956484800
firstPartyDomain: ""
hostOnly: true
httpOnly: false
name: "username"
path: "/"
sameSite: "no_restriction"
secure: false
session: false
storeId: "firefox-default"
value: "John Doe"
domain: ""
firstPartyDomain: ""
hostOnly: true
httpOnly: false
name: "useralias"
path: "/poc/"
sameSite: "no_restriction"
secure: false
session: true
storeId: "firefox-default"
value: "JohnDoe"
The API described on this page: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/cookies/remove
does not allow me to specify an unexpected property like "domain".
Here is the error:
"Error removing / saving cookie:": Error: "Type error for parameter details (Unexpected property" domain ") for cookies.remove."
It also does not allow me to specify an empty url to delete these famous cookies, let's take the following code:
let cookie = {
firstPartyDomain: "",
name: "username",
storeId: "firefox-default",
url: "http:///",
};
let cookie = {
firstPartyDomain: "",
name: "username",
storeId: "firefox-default",
url: "",
};
browser.cookies.remove(cookie).then((deleted_cookie) => {
console.log({"Removed:": deleted_cookie});
});
Actual result from the console:
"Object { Removed: null }"
But as you said, and as the documentation says: "If a cookie matching the details parameter could not be found, the promise is fulfilled with null."
So, my question is: What value am I supposed to set to the "url" property for browser.cookie.remove()
to find my cookie and agree to delete it?
Thanks.
To clarify a point:
I am also unable to delete these cookies from the devtools/storage tool.
Thanks.
Comment 6•6 years ago
|
||
document.cookie = "username=John Doe; expires=Thu, 31 Dec 2031 12:00:00 UTC; path=/"; document.cookie = "useralias=JohnDoe";
This operation should create 2 cookies with valid domain and firstPartyDomain values.
Is this page exposed via web-extension? or is it a normal http request?
Not sure this is an actual firefox bug. I could delete locally created cookies by specifying an adjusted url:
function getCookieRemoveURL(cookie) {
if (cookie.domain.length === 0)
return `file://${cookie.path}`;
const rawDomain = cookie.domain.startsWith(".") ? cookie.domain.substr(1) : cookie.domain;
return (cookie.secure ? "https://" : "http://") + rawDomain + cookie.path;
}
Comment 8•5 years ago
|
||
This seems to be more a web-extension issue. Luca, do you mind to take a look?
Comment 9•5 years ago
|
||
(In reply to Andrea Marchesini [:baku] from comment #8)
This seems to be more a web-extension issue. Luca, do you mind to take a look?
Cookies created from file urls does have an empty host
property internally (which becomes an empty domain
property when the cookies API implementation translates from the representation used internally in firefox into the one expected from this API), and the cookies API requires the caller to set an url
in the calls to browser.cookies.remove
(along with name
).
Currently these cookies created from file urls should be successfully removed by computing the file://
url (e.g. as suggested by Lusito in comment 7, but I haven't checked yet if the computed file url has to be different on the Windows platform), and I verified that this is actually the case.
I also quickly gave it a try on Chrome (to evaluate chrome compatibility issues related to this behavior, especially if we will agree to apply some changes to make it clearer than it is right now), but it seems that the cookies created the file urls are not being listed at all.
In my opinion a reasonable fix would be to compute the url that we expect internally and return it as the url
property of the cookie details returned by the cookies API, this would allow the extensions to remove these cookies by just using the url got from the API itself.
I'm moving this issue to the WebExtensions::General component, and I'm clearing its priority to re-triage it as a WebExtensions API bug.
Updated•5 years ago
|
Updated•3 years ago
|
Comment 10•2 years ago
|
||
Hello there,
If you are unable to delete cookies.
You can try these steps
Open browser settings
Locate the security section
Access the cookies settings
Identify the cookies without domain
Then delete that
I hope this is helpful for you
Comment 12•1 year ago
|
||
Even if an extension has access to file:-URLs, it is unable to set such cookies because the implementation rejects anything other than http/https, at https://searchfox.org/mozilla-central/rev/2c61e59a48af27c100c2dd2756b5efad573dbc71/toolkit/components/extensions/parent/ext-cookies.js#142
The fact that cookies from file:/// does not have a domain is mentioned at bug 209964.
Description
•