Skip to content

Add test to verify that document.currentScript.src should not get clobbered by a DOM element with name='currentScript'. #48536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Test that document.currentScript should not be possible to get clobbered via a DOM element with name='currentScript'</title>
<link rel=help href="https://html.spec.whatwg.org/multipage/#dom-document-currentscript">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<img name='currentScript' src='http://some_possibly_malevolent_address_that_clobbers_document_currentScript.com/foo.js'>
<script>
test(function() {
assert_true(document.currentScript.tagName === 'SCRIPT'); // In particular, should not be "IMG" from the DOM element
assert_true(!document.currentScript.src.includes('malevolent_address')); // Should not have gotten the URL address from IMG element
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use assert_false.

assert_true(document.currentScript.src == ''); // In fact, since this is an inline <script> element, .src should be empty.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert_equals would give a clearer error message here.

}, "Document.currentScript should not get clobbered by a DOM element with name='currentScript' attribute");
</script>