Skip to content

Define behavior for file:// documents' origin. #3099

Open
@mikewest

Description

@mikewest

The text as https://html.spec.whatwg.org/#sandboxOrigin defines a document's origin in the case that "the Document's URL's scheme is a network scheme" and for data: schemes, but declines to define behavior for non-network schemes like file:. Unsurprisingly, different browsers have made different choices here. When a document is loaded from file:///directory/file.html:

  • Edge
    • returns file:// for location.origin (it doesn't yet implement window.origin)
    • allows DOM access to file:///directory/other-file.html, file:///directory/subdirectory/file.html, and file:///parent-directory.html when framed.
    • shares localStorage across all file: URLs
    • times out for reasons I can't figure out when fetch() is called on file: URLs.
  • Firefox
    • returns null for window.origin
    • allows DOM access to both file:///directory/other-file.html and file:///directory/subdirectory/file.html, and disallows DOM access to file:///parent-directory.html when framed.
    • localStorage seems scoped to the same-or-sub directory as well.
    • allows fetch() to access content from file:///directory/other-file.html and file:///directory/subdirectory/file.html, and returns a network error when fetching from file:///parent-directory.html
  • Safari
    • returns null for window.origin
    • opens Finder windows rather than framing file:///directory/other-file.html, file:///directory/subdirectory/file.html, and file:///parent-directory.html (that is, <iframe src="file:///whatever/directory/file.html"></iframe> stays in about:blank and pops a Finder window to /whatever/directory/)
    • blocks localStorage for all file: URLs
    • returns a network error when calling fetch() on file:///directory/other-file.html, file:///directory/subdirectory/file.html, and file:///parent-directory.html.
  • Chrome
    • returns null for window.origin
    • disallows DOM access to file:///directory/other-file.html, file:///directory/subdirectory/file.html, and file:///parent-directory.html when framed.
    • shares localStorage across all file: URLs
    • returns a network error when calling fetch() on file:///directory/other-file.html, file:///directory/subdirectory/file.html, and file:///parent-directory.html.

I wonder if we could get more alignment if we talked about it a bit. There seems to be general agreement that the page should have an opaque origin, but a little bit of disagreement about what that should mean. I'd kinda like to keep Chrome's behavior for DOM access and Fetch, for instance, as it protects against scanning the entire disk or a user's downloads directory. I'm less enthusiastic about Chrome's localStorage behavior. I'd prefer Safari's, I think, but could live with something less draconian if there's good reason to.

@annevk, @travisleithead, @johnwilander: Would y'all mind looping in relevant folks (or having opinions yourselves? :) )?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions