Skip to content

Commit 5e98a91

Browse files
Overload Document.prototype createElement instead of document (#308)
1 parent 55eb1c7 commit 5e98a91

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

integration-test/test-runtime-checks.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,51 @@ describe('Runtime checks: should allow element modification', () => {
385385
srcVal7: 'http://example4.com/'
386386
})
387387
})
388+
389+
it('Script using parent prototype should execute checking', async () => {
390+
const port = server.address().port
391+
const page = await browser.newPage()
392+
await gotoAndWait(page, `http://localhost:${port}/blank.html`, {
393+
site: {
394+
enabledFeatures: ['runtimeChecks']
395+
},
396+
featureSettings: {
397+
runtimeChecks: {
398+
taintCheck: 'enabled',
399+
matchAllDomains: 'enabled',
400+
matchAllStackDomains: 'enabled',
401+
overloadInstanceOf: 'enabled'
402+
}
403+
}
404+
})
405+
// And now with a script that will execute
406+
const scriptResult = await page.evaluate(
407+
() => {
408+
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
409+
window.scriptDocumentPrototypeRan = false
410+
const scriptElement = Document.prototype.createElement.call(window.document, 'script')
411+
scriptElement.innerText = 'window.scriptDocumentPrototypeRan = true'
412+
scriptElement.id = 'scriptDocumentPrototype'
413+
scriptElement.setAttribute('type', 'application/javascript')
414+
document.body.appendChild(scriptElement)
415+
const hadInspectorNode = !!document.querySelector('ddg-runtime-checks')
416+
const instanceofResult = scriptElement instanceof HTMLScriptElement
417+
const scripty = document.querySelector('script#scriptDocumentPrototype')
418+
419+
return {
420+
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
421+
scriptRan: window.scriptDocumentPrototypeRan,
422+
hadInspectorNode,
423+
instanceofResult,
424+
type: scripty.getAttribute('type')
425+
}
426+
}
427+
)
428+
expect(scriptResult).toEqual({
429+
scriptRan: true,
430+
hadInspectorNode: true,
431+
instanceofResult: true,
432+
type: 'application/javascript'
433+
})
434+
})
388435
})

src/features/runtime-checks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ function shouldInterrogate (tagName) {
325325
}
326326

327327
function overrideCreateElement () {
328-
const proxy = new DDGProxy(featureName, document, 'createElement', {
328+
const proxy = new DDGProxy(featureName, Document.prototype, 'createElement', {
329329
apply (fn, scope, args) {
330330
if (args.length >= 1) {
331331
const initialTagName = args[0].toLowerCase()

0 commit comments

Comments
 (0)