This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
createElement
on inert document to prevent unexpected subresour…
…ce loads. RELNOTES: n/a PiperOrigin-RevId: 575162808 Change-Id: I555c1d86b3ef7c8fa297931bbb057ad44eba5f99
- Loading branch information
1 parent
11b2f3c
commit da6ff88
Showing
8 changed files
with
111 additions
and
86 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @license | ||
* Copyright The Closure Library Authors. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** | ||
* @fileoverview Exports a method to create an inert document, which will not | ||
* execute JS or make network requests while parsing HTML. | ||
*/ | ||
|
||
goog.module('goog.html.sanitizer.inertDocument'); | ||
goog.module.declareLegacyNamespace(); | ||
|
||
/** | ||
* Creates an DOM Document object that will not execute scripts or make | ||
* network requests while parsing HTML. | ||
* @return {!Document} | ||
*/ | ||
function createInertDocument() { | ||
'use strict'; | ||
return document.implementation.createHTMLDocument(''); | ||
} | ||
|
||
exports = {createInertDocument}; |
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 @@ | ||
/** | ||
* @license | ||
* Copyright The Closure Library Authors. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** @fileoverview testcases for createInertDocument. */ | ||
|
||
goog.module('goog.html.inertDocumentTests'); | ||
goog.setTestOnly(); | ||
|
||
const testSuite = goog.require('goog.testing.testSuite'); | ||
const {createInertDocument} = goog.require('goog.html.sanitizer.inertDocument'); | ||
|
||
testSuite({ | ||
testInertDocument() { | ||
if (!document.implementation.createHTMLDocument) { | ||
return; // skip test | ||
} | ||
|
||
/** | ||
* @suppress {strictMissingProperties} suppression added to enable type | ||
* checking | ||
*/ | ||
window.xssFiredInertDocument = false; | ||
const doc = createInertDocument(); | ||
const script = doc.createElement('script'); | ||
script.text = 'window.xssFiredInertDocument = true'; | ||
doc.body.appendChild(script); | ||
assertFalse(window.xssFiredInertDocument); | ||
}, | ||
}); |
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