Skip to content

Commit 95e07c3

Browse files
Add overriding the prototype back the cases where the page has overloaded us (#301)
1 parent 7f55cc0 commit 95e07c3

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

integration-test/test-runtime-checks.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ describe('Runtime checks: should allow element modification', () => {
224224
}
225225
}
226226
})
227-
// And now with a script that will execute
228227
const scriptResult4 = await page.evaluate(
229228
() => {
230229
function getAttributeValues (el) {
@@ -295,4 +294,34 @@ describe('Runtime checks: should allow element modification', () => {
295294
nodeAndFakeNodeMatch: false
296295
})
297296
})
297+
298+
it('Script that should filter props and attributes', async () => {
299+
const port = server.address().port
300+
const page = await browser.newPage()
301+
await gotoAndWait(page, `http://localhost:${port}/blank.html`, {
302+
site: {
303+
enabledFeatures: ['runtimeChecks']
304+
},
305+
featureSettings: {
306+
runtimeChecks: {
307+
taintCheck: 'enabled',
308+
matchAllDomains: 'enabled',
309+
matchAllStackDomains: 'enabled',
310+
overloadInstanceOf: 'enabled'
311+
}
312+
}
313+
})
314+
const scriptResult5 = await page.evaluate(
315+
() => {
316+
// @ts-expect-error Undefined property for testing
317+
window.scripty5Ran = false
318+
const myScript = document.createElement('script')
319+
myScript.innerText = 'window.scripty5Ran = true'
320+
Object.setPrototypeOf(myScript, HTMLScriptElement.prototype)
321+
document.body.appendChild(myScript)
322+
// @ts-expect-error Undefined property for testing
323+
return window.scripty5Ran
324+
})
325+
expect(scriptResult5).toBe(true)
326+
})
298327
})

src/features/runtime-checks.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class DDGRuntimeChecks extends HTMLElement {
4545
// Solves re-entrancy issues from React
4646
if (this.#connected) return
4747
this.#connected = true
48+
if (!this.transplantElement) {
49+
// Restore the 'this' object with the DDGRuntimeChecks prototype as sometimes pages will overwrite it.
50+
Object.setPrototypeOf(this, DDGRuntimeChecks.prototype)
51+
}
4852
this.transplantElement()
4953
}
5054

0 commit comments

Comments
 (0)