From 5a85d6e78e2fea8e9663b5317f62f4479a5555fa Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sat, 29 Jun 2024 01:26:03 -0300 Subject: [PATCH 1/2] Harder conditions for Sentry patching --- src/plugins/_core/noTrack.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/plugins/_core/noTrack.ts b/src/plugins/_core/noTrack.ts index ef2849bbc..d28440369 100644 --- a/src/plugins/_core/noTrack.ts +++ b/src/plugins/_core/noTrack.ts @@ -93,7 +93,21 @@ export default definePlugin({ // Ensure this is most likely the Sentry WebpackInstance. // Function.g is a very generic property and is not uncommon for another WebpackInstance (or even a React component: ) to include it const { stack } = new Error(); - if (!(stack?.includes("discord.com") || stack?.includes("discordapp.com")) || this.c != null || !String(this).includes("exports:{}")) { + if (!(stack?.includes("discord.com") || stack?.includes("discordapp.com")) || !String(this).includes("exports:{}") || this.c != null) { + return; + } + + const assetPath = stack?.match(/\/assets\/.+?\.js/)?.[0]; + if (!assetPath) { + return; + } + + const srcRequest = new XMLHttpRequest(); + srcRequest.open("GET", assetPath, false); + srcRequest.send(); + + // Final condition to see if this is the Sentry WebpackInstance + if (!srcRequest.responseText.includes("window.DiscordSentry=")) { return; } @@ -102,11 +116,6 @@ export default definePlugin({ configurable: true, get() { - // One more condition to check if this is the Sentry WebpackInstance - if (Array.isArray(this)) { - return { exports: {} }; - } - new Logger("NoTrack", "#8caaee").info("Disabling Sentry by proxying its WebpackInstance cache"); Object.setPrototypeOf(this, new Proxy(this, { get() { @@ -114,8 +123,10 @@ export default definePlugin({ } })); + Reflect.deleteProperty(Function.prototype, "g"); Reflect.deleteProperty(Object.prototype, cacheExtractSym); Reflect.deleteProperty(window, "DiscordSentry"); + return { exports: {} }; } }); @@ -130,6 +141,8 @@ export default definePlugin({ set() { new Logger("NoTrack", "#8caaee").error("Failed to disable Sentry. Falling back to deleting window.DiscordSentry"); + + Reflect.deleteProperty(Function.prototype, "g"); Reflect.deleteProperty(window, "DiscordSentry"); } }); From 332f3e532ba0ff861570f73c35be6044e39204f0 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sat, 29 Jun 2024 02:21:44 -0300 Subject: [PATCH 2/2] Dont depend on modules being an object again --- src/webpack/patchWebpack.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts index 55425431f..eca02dc49 100644 --- a/src/webpack/patchWebpack.ts +++ b/src/webpack/patchWebpack.ts @@ -48,7 +48,7 @@ define(Function.prototype, "m", { // We may also catch Discord bundled libs, React Devtools or other extensions WebpackInstance here. // This ensures we actually got the right ones const { stack } = new Error(); - if (!(stack?.includes("discord.com") || stack?.includes("discordapp.com")) || Array.isArray(originalModules)) { + if (!(stack?.includes("discord.com") || stack?.includes("discordapp.com")) || (stack != null ? /at \d+? \(/.test(stack) : true) || !String(this).includes("exports:{}")) { return; } @@ -66,7 +66,7 @@ define(Function.prototype, "m", { define(this, "p", { value: bundlePath }); clearTimeout(setterTimeout); - if (bundlePath !== "/assets/") return; + if (window.GLOBAL_ENV?.PUBLIC_PATH != null && bundlePath !== window.GLOBAL_ENV.PUBLIC_PATH) return; logger.info("Main Webpack found" + interpolateIfDefined` in ${fileName}` + ", initializing internal references to WebpackRequire"); _initWebpack(this);