Closed
Bug 762409
Opened 12 years ago
Closed 12 years ago
localStorage throws "The operation is insecure." error with document.domain
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
People
(Reporter: luolonghao, Assigned: mayhemer)
References
Details
(Keywords: china-p1)
Attachments
(4 files)
758.49 KB,
image/png
|
Details | |
156.03 KB,
image/png
|
Details | |
1.06 KB,
patch
|
bzbarsky
:
review+
akeybl
:
approval-mozilla-aurora+
akeybl
:
approval-mozilla-beta+
mayhemer
:
checkin+
|
Details | Diff | Splinter Review |
1.62 KB,
application/x-javascript
|
Details |
User Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5
Steps to reproduce:
1. create two HTML files.
1) http://sub.test.com/storage.html
----------------
<!DOCTYPE html>
<meta charset="utf-8" />
<title>nothing here</title>
<script>
document.domain = 'test.com';
</script>
2) http://test.com/cross-storage-test.html
----------------
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>localStorage Test</title>
</head>
<body>
</body>
<script>
document.domain = 'test.com';
window.onload = function() {
var iframe = document.createElement('iframe');
iframe.src = 'http://sub.test.com/storage.html';
iframe.onload = function() {
var win = iframe.contentWindow;
console.log(win);
win.localStorage.setItem('hello', '1234');
console.log(win.localStorage.getItem('hello'));
};
document.body.appendChild(iframe);
};
</script>
</html>
2. open http://test.com/cross-storage-test.html URL.
Actual results:
The operation is insecure.
[Break On This Error]
win.localStorage.setItem('hello', '1234');
Expected results:
print "1234" in console.
Updated•12 years ago
|
Component: Untriaged → DOM
Product: Firefox → Core
QA Contact: untriaged → general
Comment 1•12 years ago
|
||
I believe per spec the storage stuff completely ignores document.domain, so you're trying to setItem across domains...
Assignee | ||
Comment 2•12 years ago
|
||
(In reply to Boris Zbarsky (:bz) from comment #1)
> I believe per spec the storage stuff completely ignores document.domain, so
> you're trying to setItem across domains...
Exactly.
Updated•12 years ago
|
Status: UNCONFIRMED → RESOLVED
Closed: 12 years ago
Resolution: --- → INVALID
Reporter | ||
Comment 3•12 years ago
|
||
Thanks for your reply. but the above code works fine in other browsers and Firefox <= 12.
There is one exception to the same origin rule. A script can set the value of document.domain to a suffix of the current domain. If it does so, the shorter domain is used for subsequent origin checks. For example, assume a script in the document at http://store.company.com/dir/other.html executes the following statement:
document.domain = "company.com";
After that statement executes, the page would pass the origin check with http://company.com/dir/page.html
https://developer.mozilla.org/en/DOM/document.domain
https://developer.mozilla.org/en/Same_origin_policy_for_JavaScript
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
Comment 4•12 years ago
|
||
> There is one exception to the same origin rule.
I'm well aware of how document.domain works. It affects _some_ same-origin checks, but not all. For example, it doesn't affect the same-origin checks that XMLHttpRequest performs. See the difference between "origin" and "effective script origin" in the HTML5 specs.
Honza, was the behavior change here due to a recent spec change?
Comment 5•12 years ago
|
||
It doesn't look like a recent change, and the discussion in bug 495337 (where the behavior change happened) sure sounds like it shouldn't work in other browsers either.... See Adam Barth's comments in particular.
Comment 6•12 years ago
|
||
This seems to be the problem happening on http://show.qq.com/ (QQ is a widely used site in China).
show.qq.com does not work properly in the latest Firefox, I tested on Nightly v16, I've heard that 12 works but not 13, and QQ was in contact mentioning that it might be this bug.
Confirming the issue (not sure if it's a site problem or a Firefox problem yet). I'll try to get a regression window.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Comment 7•12 years ago
|
||
Confirming that show.qq.com works in:
Build identifier: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0a1) Gecko/20111219 Firefox/11.0a1
mozilla-central changeset d75ebb37080e
===
but fails in:
Build identifier: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:16.0) Gecko/16.0 Firefox/16.0a1
(2012-06-12)
mozilla-central changeset 131961e5e0d1
I'll be narrowing this window down.
Comment 8•12 years ago
|
||
Confirming that the site works in 20120223 but not in 20120224 nightly:
http://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=5e756e59a794&tochange=cd120efbe4c6
Bug 495337 is in the regression window and may indeed be the cause.
Comment 9•12 years ago
|
||
I checked Chromium version 21.0.1173.0 (Developer Build 141642) and Safari 5.1.6 and both seem to render the site properly.
Comment 10•12 years ago
|
||
Nominating tracking flags for all known versions - show.qq.com is essentially unusable with this bug.
tracking-firefox13:
--- → ?
tracking-firefox14:
--- → ?
tracking-firefox15:
--- → ?
tracking-firefox16:
--- → ?
Comment 11•12 years ago
|
||
Works in 2012-02-23 nightly.
Comment 12•12 years ago
|
||
Fails to work in 2012-02-24 nightly.
I don't think I'd expect this to be firedrilled for Firefox 13 though..
Updated•12 years ago
|
status-firefox14:
--- → affected
status-firefox15:
--- → affected
status-firefox16:
--- → affected
tracking-firefox13:
? → ---
Comment 13•12 years ago
|
||
Honza, can you double-check the behavior wrt document.domain of other UAs? It's possible the spec just needs to change to reflect market reality...
Updated•12 years ago
|
status-firefox13:
--- → affected
Assignee | ||
Comment 15•12 years ago
|
||
It turns out that the correct check is when at least one of these passes:
- if code base of the storage's principal is the same as the code base of the content page ; we currently do that with SubsumesIgnoringDomain()
- if code base is the same or domain is set to the same value (or not set on both) ; I'm adding Subsumes() additional check
so, finally we have canAccess = subsumesIgnoringDomain || subsumes;
I feel this is right, but Boris, please check this. I may not catch all implications.
Attachment #632897 -
Flags: review?(bzbarsky)
Comment 16•12 years ago
|
||
Honza: can you link to the relevant part of the spec? Or is this not in the spec?
Updated•12 years ago
|
Assignee | ||
Comment 17•12 years ago
|
||
(In reply to Boris Zbarsky (:bz) from comment #16)
> Honza: can you link to the relevant part of the spec? Or is this not in the
> spec?
http://dev.w3.org/html5/webstorage/
--- BEGIN OF CITE ---
4.3.1 Security
User agents must throw a SecurityError exception whenever any of the members of a Storage object originally returned by the localStorage attribute are accessed by scripts whose effective script origin is not the same as the origin of the Document of the Window object on which the localStorage attribute was accessed.
This means Storage objects are neutered when the document.domain attribute is used.
--- END OF CITE ---
I will need help to translate the last sentence...
If it is not a typo and I correctly understand, then the correct check should be:
subject.codeBase == storage.codeBase || subject.domain == storage.codeBase
Les cryptic:
subject.effectiveOrigin == storage.origin
Changes on the document.domain of the document whom localStorage a script tries to access should not be taken into effect. However, that doesn't make much sense to me.
Assignee | ||
Comment 18•12 years ago
|
||
I broke my rule to not refresh bug pages! Sorry for reverting the tracking flags, but I don't have the right to put them back...
Status: NEW → ASSIGNED
Comment 19•12 years ago
|
||
Comment on attachment 632897 [details] [diff] [review]
v1
OK. So the spec does say what comment 17 says it does, yeah. That seems pretty broken to me. Honza, could you test whether this is what other implementations actually do?
Specifically, per the spec given a page at subdomain.foo.com that sets document.domain to foo.com and a page at foo.com, per spec the former should be able to access the localStorage of the latter (but it can only get to it, of course, if the latter also sets document.domain to foo.com).
But given a page at subdomain.foo.com that sets document.domain to foo.com and a page a othersubdomain.foo.com that sets document.domain to foo.com, per spec neither one should be able to access the other's localStorage (nor indeed their own localStorage).
The attached patch doesn't do that, I believe: it would allow access across the two pages in the second example.
I think that's OK as a temporary measure, honestly, and would be pretty safe to ship; I don't expect it to cause any security problems that don't already exist once you've set document.domain to the same value in our existing impl (where we would allow a page to touch its own localStorage after it sets document.domain).
Now _that_ itself might be a security issue, which is why the spec disallows that. But this patch doesn't make it worse.
Attachment #632897 -
Flags: review?(bzbarsky) → review+
Updated•12 years ago
|
Attachment #632897 -
Flags: approval-mozilla-beta+
Attachment #632897 -
Flags: approval-mozilla-aurora+
Comment 20•12 years ago
|
||
Pre-approving for Aurora/Beta since we are considering this patch for 13.0.1.
Assignee | ||
Comment 21•12 years ago
|
||
(In reply to Boris Zbarsky (:bz) from comment #19)
> Comment on attachment 632897 [details] [diff] [review]
> v1
>
> OK. So the spec does say what comment 17 says it does, yeah. That seems
> pretty broken to me. Honza, could you test whether this is what other
> implementations actually do?
Doesn't this actually mean that a page that changes its document.domain would never more be able to access its own local/sessionStorage? I've already tested that this works in all current browsers, so it is against this spec.
>
> Specifically, per the spec given a page at subdomain.foo.com that sets
> document.domain to foo.com and a page at foo.com, per spec the former should
> be able to access the localStorage of the latter (but it can only get to it,
> of course, if the latter also sets document.domain to foo.com).
>
> But given a page at subdomain.foo.com that sets document.domain to foo.com
> and a page a othersubdomain.foo.com that sets document.domain to foo.com,
> per spec neither one should be able to access the other's localStorage (nor
> indeed their own localStorage).
This seems controversial and actually disallows any cross-origin access what I don't observe in Fx or other browser.
Comment 22•12 years ago
|
||
show.qq.com loads all content(iframes) / scripts from imgcache.qq.com, with document.domain = 'qq.com' set on both sides, as I understand.
Comment 23•12 years ago
|
||
(In reply to Alex Keybl [:akeybl] from comment #20)
> Pre-approving for Aurora/Beta since we are considering this patch for 13.0.1.
So there is a possibility of a firedrill! Nominating for tracking-firefox13 as well.
tracking-firefox13:
--- → ?
Comment 24•12 years ago
|
||
Increasing severity since this breaks a major site quite badly.
Severity: normal → major
Updated•12 years ago
|
Comment 25•12 years ago
|
||
Helping move this along by setting checkin-needed for mozilla-inbound since it has r+, but not sure if it's been try'ed.
Keywords: checkin-needed
Assignee | ||
Comment 26•12 years ago
|
||
Comment on attachment 632897 [details] [diff] [review]
v1
https://hg.mozilla.org/mozilla-central/rev/b30e903d23a0
https://hg.mozilla.org/releases/mozilla-aurora/rev/73e2f24294a8
https://hg.mozilla.org/releases/mozilla-beta/rev/99e7284a9773
Attachment #632897 -
Flags: checkin+
Assignee | ||
Comment 27•12 years ago
|
||
(In reply to Gary Kwong [:gkw, :nth10sd] from comment #25)
> not sure if it's been try'ed.
It wasn't, just locally.
Status: ASSIGNED → RESOLVED
Closed: 12 years ago → 12 years ago
Keywords: checkin-needed
Resolution: --- → FIXED
Comment 28•12 years ago
|
||
> Doesn't this actually mean that a page that changes its document.domain would never more
> be able to access its own local/sessionStorage?
Per spec, yes, unless it changes it to the original value of its domain.
> I've already tested that this works in all current browsers
Then the spec probably needs to change.
> show.qq.com loads all content(iframes) / scripts from imgcache.qq.com, with
> document.domain = 'qq.com' set on both sides, as I understand.
Is it trying to access the qq.com localStorage, or the imgcache.qq.com one?
Comment 29•12 years ago
|
||
(In reply to Boris Zbarsky (:bz) from comment #28)
> > show.qq.com loads all content(iframes) / scripts from imgcache.qq.com, with
> > document.domain = 'qq.com' set on both sides, as I understand.
>
> Is it trying to access the qq.com localStorage, or the imgcache.qq.com one?
It is trying to access the localStorage of top window, I think.
Attached is a reduced version of http://imgcache.qq.com/ac/qqshow/qsfl/2_54/core.js, which is referenced in both top show.qq.com and framed imgcache.qq.com pages.
Comment 30•12 years ago
|
||
> https://hg.mozilla.org/mozilla-central/rev/b30e903d23a0
tbpl is largely green! \o/
https://tbpl.mozilla.org/?rev=b30e903d23a0
Updated•12 years ago
|
Flags: in-testsuite?
Comment 31•12 years ago
|
||
It appears that http://show.qq.com/ has worked around this issue, so we do not plan to take a fix for FF13. Any other sites that run into this issue could do the same, but we're not aware of any at this point.
Comment 32•12 years ago
|
||
If this is something we want to get out sooner to users, let's get the beta landing in today before tomorrow's go to build.
Assignee | ||
Comment 33•12 years ago
|
||
(In reply to Lukas Blakk [:lsblakk] from comment #32)
> If this is something we want to get out sooner to users, let's get the beta
> landing in today before tomorrow's go to build.
It has already landed on beta, see comment 26.
Comment 35•12 years ago
|
||
Updating the status flags to remove confusion about what has landed where.
Comment 36•12 years ago
|
||
Verified as fixed with the STR from comment 0 on:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:15.0) Gecko/20100101 Firefox/15.0
Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20100101 Firefox/15.0
Build identifier: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•