Skip to content

Add proxy debugging and runtimeChecks interrogation debug messages #440

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

Merged
merged 3 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
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
20 changes: 18 additions & 2 deletions src/features/runtime-checks.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global TrustedScriptURL, TrustedScript */

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

let stackDomains = []
Expand Down Expand Up @@ -351,19 +351,35 @@ function shouldInterrogate (tagName) {
return false
}
if (matchAllStackDomains) {
isInterrogatingDebugMessage('matchedAllStackDomain')
return true
}
if (taintCheck && document.currentScript?.[taintSymbol]) {
isInterrogatingDebugMessage('taintCheck')
return true
}
const stack = getStack()
const scriptOrigins = [...getStackTraceOrigins(stack)]
const isInterestingHost = scriptOrigins.some(origin => {
const interestingHost = scriptOrigins.find(origin => {
return stackDomains.some(rule => matchHostname(origin, rule.domain))
})
const isInterestingHost = !!interestingHost
if (isInterestingHost) {
isInterrogatingDebugMessage('matchedStackDomain', interestingHost, stack, scriptOrigins)
}
return isInterestingHost
}

function isInterrogatingDebugMessage (matchType, matchedStackDomain, stack, scriptOrigins) {
postDebugMessage('runtimeChecks', {
documentUrl: document.location.href,
matchedStackDomain,
matchType,
scriptOrigins,
stack
})
}

function overrideCreateElement () {
const proxy = new DDGProxy(featureName, Document.prototype, 'createElement', {
apply (fn, scope, args) {
Expand Down
1 change: 1 addition & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ export class DDGProxy {
const isExempt = shouldExemptMethod(this.camelFeatureName)
if (debug) {
postDebugMessage(this.camelFeatureName, {
isProxy: true,
action: isExempt ? 'ignore' : 'restrict',
kind: this.property,
documentUrl: document.location.href,
Expand Down
5 changes: 4 additions & 1 deletion unit-test/verify-artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import { cwd } from '../scripts/script-utils.js'
const ROOT = join(cwd(import.meta.url), '..')
const BUILD = join(ROOT, 'build')
const APPLE_BUILD = join(ROOT, 'Sources/ContentScopeScripts/dist')
const CSS_OUTPUT_SIZE = 560000
let CSS_OUTPUT_SIZE = 560000
const CSS_OUTPUT_SIZE_CHROME = CSS_OUTPUT_SIZE * 1.45 // 45% larger for Chrome MV2 due to base64 encoding
if (process.platform === 'win32') {
CSS_OUTPUT_SIZE = CSS_OUTPUT_SIZE * 1.1 // 10% larger for Windows due to line endings
}

const checks = {
android: [
Expand Down