Closed Bug 1321550 Opened 8 years ago Closed 7 years ago

indexedDB includes fragment identifiers in file:// URLs as hostnames

Categories

(Core :: Storage: IndexedDB, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla53
Tracking Status
firefox53 --- fixed

People

(Reporter: miker, Assigned: baku)

References

Details

Attachments

(1 file, 4 obsolete files)

Creating an indexedDB under a file:/// path includes everything after a # for a domain. So going to the following URLs and creating a DB will create three completely separate DBs:

  - file:///some/path/test.html
  - file:///some/path/test.html#test
  - file:///some/path/test.html#/test

The DBs are created at:

  - file++++some+path+test.html
  - file++++some+path+test.html#test
  - file++++some+path+test.html#+test

Chrome and Safari instead group all file:/// indexedDBs into one location with a hostname of file__0. I think our approach is better but surely we should trim the host at the first #?
I need to know what we are supposed to do here so that I can display the correct DB info in the Storage Inspector.
OS: Windows 7 → All
Hardware: x86_64 → All
Version: 36 Branch → unspecified
This is controlled by QuotaManager and not really specific to IndexedDB.  It may be related to how we treat the origin for file URLs in general.  Not sure what our principal code does there.  Jan, what do you think?
Flags: needinfo?(jvarga)
Yeah, this goes through QuotaManager, but we just use what nsIPrincipal::GetOrigin() gives us. We don't do anything special for file:// in QuotaManager.
I'm not an expert on file protocol, there can be a reason why it's treated this way.
We have an IndexedDB bug somewhere about file:// origins being too long.
Flags: needinfo?(jvarga)
I'll take a look at this. It seems that we are retrieving the origin wrongly for file URLs.
Flags: needinfo?(amarchesini)
Flags: needinfo?(amarchesini)
Attached patch filepath.patch (obsolete) — Splinter Review
Assignee: nobody → amarchesini
Attachment #8821149 - Flags: review?(bugs)
Comment on attachment 8821149 [details] [diff] [review]
filepath.patch

nsIURIWithQuery is so mysterious that I don't know when one is supposed to use it. I have no idea if this is right, or whether same kind of check should be done with some other schemes.
(Initial reaction is that adding explicit SchemeIs check is wrong.)

Can't really review this.
Attachment #8821149 - Flags: review?(bugs)
So if this patch was taken (though it is confusing to reuse hostPort for filePath), which all schemes would still fallback to 
nsCOMPtr<nsIStandardURL> standardURL = do_QueryInterface(origin);
NS_ENSURE_TRUE(standardURL, NS_ERROR_FAILURE);
rv = origin->GetAsciiSpec(aOrigin);

?
Do we possibly want to add GetAsciiSpecIgnoringRef and use it there and not GetAsciiSpec?
(In reply to Olli Pettay [:smaug] from comment #8)
> Do we possibly want to add GetAsciiSpecIgnoringRef and use it there and not
> GetAsciiSpec?

This would also be a nice approach. I prefer valentin to take a decision here.
Flags: needinfo?(valentin.gosu)
Yes, GetAsciiSpecIgnoringRef seems to be what we want here.
Flags: needinfo?(valentin.gosu)
Attached patch filepath2.patch (obsolete) — Splinter Review
Attachment #8821149 - Attachment is obsolete: true
Attachment #8821713 - Flags: review?(valentin.gosu)
Comment on attachment 8821713 [details] [diff] [review]
filepath2.patch

Review of attachment 8821713 [details] [diff] [review]:
-----------------------------------------------------------------

::: caps/nsPrincipal.cpp
@@ +182,5 @@
>    // of the spec, and the beginning of the origin attributes) is not present
>    // in the origin string
>    nsCOMPtr<nsIStandardURL> standardURL = do_QueryInterface(origin);
>    NS_ENSURE_TRUE(standardURL, NS_ERROR_FAILURE);
> +  rv = origin->GetAsciiSpecIgnoringRef(aOrigin);

Sorry for changing my mind about this, but after seeing the patch, it seems we're adding a lot of complexity for nothing, even as bug 945240 will eventually fix this.
Anyway, I thing GetAsciiSpec and then truncating at the first `#` should do the same thing, with more or less the same overhead.
Attachment #8821713 - Flags: review?(valentin.gosu)
Attached patch filepath3.patch (obsolete) — Splinter Review
Attachment #8821713 - Attachment is obsolete: true
Attachment #8821734 - Flags: review?(valentin.gosu)
Comment on attachment 8821734 [details] [diff] [review]
filepath3.patch

Review of attachment 8821734 [details] [diff] [review]:
-----------------------------------------------------------------

::: caps/nsPrincipal.cpp
@@ +189,3 @@
>    NS_ENSURE_SUCCESS(rv, rv);
>  
> +  int32_t pos = spec.FindChar('?');

nit: add a comment mentioning why we are doing this.

@@ +190,5 @@
>  
> +  int32_t pos = spec.FindChar('?');
> +  int32_t hashPos = spec.FindChar('#');
> +
> +  if (pos != kNotFound && hashPos != kNotFound && hashPos < pos) {

bug: if pos==kNotFound, we never enter this branch.

Please add tests for this. We need at least 4.
file:///path?query#hash
file:///path#hash
file:///path?query
file:///path#hash?query

@@ +194,5 @@
> +  if (pos != kNotFound && hashPos != kNotFound && hashPos < pos) {
> +    pos = hashPos;
> +  }
> +
> +  if (!aOrigin.Assign(spec, pos != kNotFound ? pos : spec.Length(), fallible)) {

nit: the ternary conditional makes this harder to read.
I would have gone for GetAsciiSpec(aOrigin); find cutoff point. if (pos != kNotFound) aOrigin.Truncate(pos);
Attachment #8821734 - Flags: review?(valentin.gosu)
Attached patch filepath3.patch (obsolete) — Splinter Review
Is there an easy way to write tests for file URL?
Attachment #8821734 - Attachment is obsolete: true
Attachment #8823066 - Flags: review?(valentin.gosu)
Attached patch filepath3.patchSplinter Review
Attachment #8823066 - Attachment is obsolete: true
Attachment #8823066 - Flags: review?(valentin.gosu)
Attachment #8823067 - Flags: review?(valentin.gosu)
Attachment #8823067 - Flags: review?(valentin.gosu) → review+
Jan, do we need some kind of migration or cleanup for origins on disk for our old serialization?
Flags: needinfo?(jvarga)
Pushed by amarchesini@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/974a431df67c
origin should not contain ref part of the URL, r=valentin
(In reply to Ben Kelly [:bkelly] from comment #17)
> Jan, do we need some kind of migration or cleanup for origins on disk for
> our old serialization?

So before this patch we created and used separate origin directories, for example:
file++++some+path+test.html
file++++some+path+test.html#test
file++++some+path+test.html#+test
 
After the patch, only the first one will be used/shared.
So the 2nd and 3rd one won't be ever used again. It would be nice to delete them immediately, but I'm not sure it's worth to do it given that file:// is not used much by typical users. Anyway the unused directories should get removed once the global limit for default/temporary storage is reached.
Flags: needinfo?(jvarga)
https://hg.mozilla.org/mozilla-central/rev/974a431df67c
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla53
Depends on: 1329494
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: