Skip to content

Commit dc469ba

Browse files
Add proxy debugging and runtimeChecks interrogation debug messages
1 parent c1999e6 commit dc469ba

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/features/runtime-checks.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* global TrustedScriptURL, TrustedScript */
22

33
import ContentFeature from '../content-feature.js'
4-
import { DDGProxy, getStackTraceOrigins, getStack, matchHostname, injectGlobalStyles, createStyleElement } from '../utils.js'
4+
import { DDGProxy, getStackTraceOrigins, getStack, matchHostname, injectGlobalStyles, createStyleElement, postDebugMessage } from '../utils.js'
55
import { wrapScriptCodeOverload } from './runtime-checks/script-overload.js'
66

77
let stackDomains = []
@@ -351,19 +351,35 @@ function shouldInterrogate (tagName) {
351351
return false
352352
}
353353
if (matchAllStackDomains) {
354+
isInterrogatingDebugMessage('matchedAllStackDomain')
354355
return true
355356
}
356357
if (taintCheck && document.currentScript?.[taintSymbol]) {
358+
isInterrogatingDebugMessage('taintCheck')
357359
return true
358360
}
359361
const stack = getStack()
360362
const scriptOrigins = [...getStackTraceOrigins(stack)]
361-
const isInterestingHost = scriptOrigins.some(origin => {
363+
const interestingHost = scriptOrigins.find(origin => {
362364
return stackDomains.some(rule => matchHostname(origin, rule.domain))
363365
})
366+
const isInterestingHost = !!interestingHost
367+
if (isInterestingHost) {
368+
isInterrogatingDebugMessage('matchedStackDomain', interestingHost, stack, scriptOrigins)
369+
}
364370
return isInterestingHost
365371
}
366372

373+
function isInterrogatingDebugMessage (matchType, matchedStackDomain, stack, scriptOrigins) {
374+
postDebugMessage('runtimeChecks', {
375+
documentUrl: document.location.href,
376+
matchedStackDomain,
377+
matchType,
378+
scriptOrigins,
379+
stack
380+
})
381+
}
382+
367383
function overrideCreateElement () {
368384
const proxy = new DDGProxy(featureName, Document.prototype, 'createElement', {
369385
apply (fn, scope, args) {

src/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ export class DDGProxy {
385385
const isExempt = shouldExemptMethod(this.camelFeatureName)
386386
if (debug) {
387387
postDebugMessage(this.camelFeatureName, {
388+
isProxy: true,
388389
action: isExempt ? 'ignore' : 'restrict',
389390
kind: this.property,
390391
documentUrl: document.location.href,

0 commit comments

Comments
 (0)