From e6ad27b114b3de65203c5247ccf12ef00f4c6a41 Mon Sep 17 00:00:00 2001
From: Domenic Denicola A Document
document can have its URL rewritten to a
- URL url if the following algorithm returns true:
Let documentURL be document's URL.
If url and documentURL differ in their If targetURL and documentURL differ in their scheme, username,
password, host, or port
components, then return false.
If url's origin is not same - origin with document's origin, - and url and documentURL differ in their path or query - components, then return false.
+If targetURL's scheme is an
+ HTTP(S) scheme, then return true. (Differences in path, query, and fragment are allowed for http:
and https:
URLs.)
Even when the previous step's condition passes, the origins can mismatch due to - sandboxing causing document's origin - to be opaque, or in cases where - document's origin is inherited from - its creator and doesn't match its URL.
- +If targetURL's scheme is "file
", and targetURL and documentURL differ in their
+ path component, then return false. (Differences in query and fragment
+ are allowed for file:
URLs.)
If targetURL and documentURL differ in their path component or query + components, then return false. (Only differences in fragment are allowed for other types of URLs.)
Return true.
Document 's origin
- | Document 's URL
- | target URL - | can have its URL rewritten - | |||
---|---|---|---|---|---|---|
("https ", "example.com ", null, null)
- | https://example.com/home
- | https://example.com/shop
- | ✅ - | |||
("https ", "example.com ", null, null)
- | https://example.com/home
- | https://user:pass@example.com/home
- | ❌ - | |||
("https ", "example.com ", null, null)
- | about:blank
- | about:blank#hash
- | ✅ - | |||
("https ", "example.com ", null, null)
- | about:blank
- | about:blank?search
- | ❌ - | |||
("https ", "example.com ", null, null)
- | about:blank
- | about:srcdoc
- | ❌ - | |||
("https ", "example.com ", null, null)
- | blob:https://example.com/77becafe-657b-4fdc-8bd3-e83aaa5e8f43
- | blob:https://example.com/anything
- | ✅ - | |||
("https ", "example.com ", null, null)
- | blob:https://example.com/77becafe-657b-4fdc-8bd3-e83aaa5e8f43
- | blob:https://example.org/anything
- | ❌ - | |||
opaque - | https://example.com/home
- | https://example.com/home#about
- | ✅ - | |||
opaque - | https://example.com/home
- | https://example.com/home?page=shop
- | ❌ - | |||
opaque - | https://example.com/home
- | https://example.com/shop
- | ❌ - | |||
opaque - | data:text/html,foo
- | data:text/html,foo#hash
- | ✅ - | |||
opaque - | data:text/html,foo
- | data:text/html,foo?search
- | ❌ - | |||
opaque - | data:text/html,foo
- | data:bar
- | ❌
+
+ document's URL
+ | targetURL
+ | can have its URL rewritten
+ | |
https://example.com/home
+ | https://example.com/home#about
+ | ✅ + | ||||
https://example.com/home
+ | https://example.com/home?page=shop
+ | ✅ + | ||||
https://example.com/home
+ | https://example.com/shop
+ | ✅ + | ||||
https://example.com/home
+ | https://user:pass@example.com/home
+ | ❌ + | ||||
https://example.com/home
+ | http://example.com/home
+ | ❌ + | ||||
file:///path/to/x
+ | file:///path/to/x#hash
+ | ✅ + | ||||
file:///path/to/x
+ | file:///path/to/x?search
+ | ✅ + | ||||
file:///path/to/x
+ | file:///path/to/y
+ | ❌ + | ||||
about:blank
+ | about:blank#hash
+ | ✅ + | ||||
about:blank
+ | about:blank?search
+ | ❌ + | ||||
about:blank
+ | about:srcdoc
+ | ❌ + | ||||
data:text/html,foo
+ | data:text/html,foo#hash
+ | ✅ + | ||||
data:text/html,foo
+ | data:text/html,foo?search
+ | ❌ + | ||||
data:text/html,foo
+ | data:text/html,bar
+ | ❌ + | ||||
data:text/html,foo
+ | data:bar
+ | ❌ + | ||||
blob:https://example.com/77becafe-657b-4fdc-8bd3-e83aaa5e8f43
+ | blob:https://example.com/77becafe-657b-4fdc-8bd3-e83aaa5e8f43#hash
+ | ✅ + | ||||
blob:https://example.com/77becafe-657b-4fdc-8bd3-e83aaa5e8f43
+ | blob:https://example.com/77becafe-657b-4fdc-8bd3-e83aaa5e8f43?search
+ | ❌ + | ||||
blob:https://example.com/77becafe-657b-4fdc-8bd3-e83aaa5e8f43
+ | blob:https://example.com/anything
+ | ❌ + | ||||
blob:https://example.com/77becafe-657b-4fdc-8bd3-e83aaa5e8f43
+ | blob:path
+ | ❌ |
Note how only the URL of the Document
+ matters, and not its origin. They can mismatch in
+ cases like the initial about:blank
+ Document
or in sandboxed iframe
s.