-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HTML: forbid data: and javascript: URLs in the <base> element
For whatwg/html#9665.
- Loading branch information
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
html/semantics/document-metadata/the-base-element/base-data.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!-- Please update base-javascript.html together with this --> | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title><base> and data: URLs</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<base href="data:/,test"> | ||
<base href="https://example.com/"> | ||
<div id=log></div> | ||
<script> | ||
test(() => { | ||
const link = document.createElement("a"); | ||
link.href = "blah"; | ||
assert_equals(link.href, new URL("blah", document.URL).href); | ||
}, "First <base> has a data: URL so fallback is used"); | ||
|
||
test(() => { | ||
document.querySelector("base").remove(); | ||
const link = document.createElement("a"); | ||
link.href = "blah"; | ||
assert_equals(link.href, new URL("blah", "https://example.com/").href); | ||
}, "First <base> is removed so second is used"); | ||
|
||
test(() => { | ||
const base = document.createElement("base"); | ||
base.href = "data:/,more-test"; | ||
document.head.prepend(base); | ||
const link = document.createElement("a"); | ||
link.href = "blah"; | ||
assert_equals(link.href, new URL("blah", document.URL).href); | ||
}, "Dynamically inserted first <base> has a data: URL so fallback is used"); | ||
</script> |
32 changes: 32 additions & 0 deletions
32
html/semantics/document-metadata/the-base-element/base-javascript.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!-- Please update base-data.html together with this --> | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title><base> and javascript: URLs</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<base href="javascript:/,test"> | ||
<base href="https://example.com/"> | ||
<div id=log></div> | ||
<script> | ||
test(() => { | ||
const link = document.createElement("a"); | ||
link.href = "blah"; | ||
assert_equals(link.href, new URL("blah", document.URL).href); | ||
}, "First <base> has a javascript: URL so fallback is used"); | ||
|
||
test(() => { | ||
document.querySelector("base").remove(); | ||
const link = document.createElement("a"); | ||
link.href = "blah"; | ||
assert_equals(link.href, new URL("blah", "https://example.com/").href); | ||
}, "First <base> is removed so second is used"); | ||
|
||
test(() => { | ||
const base = document.createElement("base"); | ||
base.href = "javascript:/,more-test"; | ||
document.head.prepend(base); | ||
const link = document.createElement("a"); | ||
link.href = "blah"; | ||
assert_equals(link.href, new URL("blah", document.URL).href); | ||
}, "Dynamically inserted first <base> has a javascript: URL so fallback is used"); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters