This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 22481 - Spec should include rationale for security checks on localStorage
Summary: Spec should include rationale for security checks on localStorage
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-26 17:45 UTC by Bobby Holley (:bholley)
Modified: 2013-07-26 00:13 UTC (History)
4 users (show)

See Also:


Attachments

Description Bobby Holley (:bholley) 2013-06-26 17:45:08 UTC
Hixie explained on IRC that it has to do with per-origin storage mutexes, but that's a bit of a leap to make from just reading the spec. It would be helpful to list that rationale here:

http://www.whatwg.org/specs/web-apps/current-work/#security-localStorage
Comment 1 Ian 'Hixie' Hickson 2013-07-03 16:56:01 UTC
Upon further investigation, the storage mutex rationale here doesn't hold water.

I don't know why it's designed this way.
Comment 2 Ian 'Hixie' Hickson 2013-07-09 20:03:27 UTC
Adam, do you remember why we block scripts that used document.domain from accessing the WebStorage objects from their original origin?
Comment 3 Bobby Holley (:bholley) 2013-07-09 20:53:39 UTC
(In reply to comment #2)
> Adam, do you remember why we block scripts that used document.domain from
> accessing the WebStorage objects from their original origin?

Well, the wouldn't have access to the original origin, right? Shouldn't it just behave like document.cookie and give you the local data from your effective script origin post document.domain?
Comment 4 Ian 'Hixie' Hickson 2013-07-09 23:36:44 UTC
Do we really want the magic document.domain origins to have storage areas? I'm not sure how we'd even explain that to the user.
Comment 5 Bobby Holley (:bholley) 2013-07-09 23:50:19 UTC
(In reply to comment #4)
> Do we really want the magic document.domain origins to have storage areas?
> I'm not sure how we'd even explain that to the user.

I don't follow.

I don't know much about this, but I'd assume that when foo.bar.com sets document.domain to bar.com, document.cookie gives you bar.com's cookies, and window.localStorage gives you bar.com's storage. I haven't tested this in any UA (and haven't even checked what gecko does) FWIW.
Comment 6 Ian 'Hixie' Hickson 2013-07-10 00:26:29 UTC
If your origin is 'http://sub.example.com:80' and you set document.domain to 'example.com', your effective origin becomes 'http://example.com:manual override'.

Other than through document.domain, you can never reach this origin. It doesn't map to any real Web site.
Comment 7 Bobby Holley (:bholley) 2013-07-10 00:45:45 UTC
(In reply to comment #6)
> If your origin is 'http://sub.example.com:80' and you set document.domain to
> 'example.com', your effective origin becomes 'http://example.com:manual
> override'.
> 
> Other than through document.domain, you can never reach this origin. It
> doesn't map to any real Web site.

So, do you get special cookies for http://example.com:manualoverride? If so, then couldn't we do the same localStorage?
Comment 8 Ian 'Hixie' Hickson 2013-07-12 19:43:49 UTC
document.cookie, per spec, is unaffected by document.domain. It sets the cookie against the page's URL (which can change using pushState(), e.g.), not the page's origin. (Cookies are set to a URL with a path, not to an origin like Storage.)
Comment 9 Bobby Holley (:bholley) 2013-07-16 23:02:53 UTC
(In reply to comment #8)
> document.cookie, per spec, is unaffected by document.domain. It sets the
> cookie against the page's URL (which can change using pushState(), e.g.),
> not the page's origin. (Cookies are set to a URL with a path, not to an
> origin like Storage.)

Ah, I see. Are there any other APIs in the spec world that store persistent data? What happens for indexedDB?
Comment 10 Ian 'Hixie' Hickson 2013-07-23 23:34:21 UTC
Good question, I don't know. Sicking?
Comment 11 Jonas Sicking (Not reading bugmail) 2013-07-24 18:45:03 UTC
A page from "http://foo.bar.com" that has set its document.domain to "bar.com" definitely should not be able to access "bar.com"s local-storage data.

The security model of document.domain is that for a page from "http://foo.bar.com" to be able to interact with "bar.com" in any way, something from "bar.com" has to opt in to that. I.e. a page from "*.bar.com" needs to also set its document.domain to "bar.com".

I don't think document.domain should affect the behavior of localStorage at all. It doesn't affect indexedDB or EventSource or XMLHttpRequest at all. I.e. in all those cases do we behave as if document.domain had not been set.

I.e. if a page on "http://foo.bar.com" sets document.domain to "bar.com" and makes a XHR request to a page on "http://foo.bar.com" it is still treated as a same-origin request. And a request to anything on "bar.com" is still treated as a cross-origin request. And if the request uses CORS, we still send "http://foo.bar.com" as origin.

And if that same page accesses window.indexedDB from its own window, it will get data for the "http://foo.bar.com" origin.

If two pages from "http://foo.bar.com" and "http://crow.bar.com" both set their document.domain to "bar.com", and the page from "http://foo.bar.com" accesses otherWindow.indexedDB, where 'otherWindow' refers to the window for the "http://crow.bar.com"-page, that it would get data for the "http://crow.bar.com" page.

I.e. the data that you receive should be based on the window you are getting the indexedDB property from. document.domain only affect which objects you can reach, it doesn't otherwise affect storage or network APIs at all.
Comment 12 Ian 'Hixie' Hickson 2013-07-26 00:12:56 UTC
So basically, remove all the security stuff around Storage... Yeah, that seems reasonable. Ok. Done. This will simplify some of the other discussions, too.
Comment 13 contributor 2013-07-26 00:13:09 UTC
Checked in as WHATWG revision r8090.
Check-in comment: Remove the weird stuff around document.domain and localStorage. It doesn't really do anything anyway.
http://html5.org/tools/web-apps-tracker?from=8089&to=8090