From 2fa56b80abee1bfea4c3435191db88141ab30c87 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] Harder conditions for Sentry patching --- src/plugins/_core/noTrack.ts | 44 ++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/src/plugins/_core/noTrack.ts b/src/plugins/_core/noTrack.ts index ef2849bb..de1c2056 100644 --- a/src/plugins/_core/noTrack.ts +++ b/src/plugins/_core/noTrack.ts @@ -77,8 +77,7 @@ export default definePlugin({ // Because of that, its WebpackInstance doesnt export wreq.m or wreq.c // To circuvent this and disable Sentry we are gonna hook when wreq.g of its WebpackInstance is set. - // When that happens we are gonna obtain a reference to its internal module cache (wreq.c) and proxy its prototype, - // so, when the first require to initialize the Sentry is attempted, we are gonna forcefully throw an error and abort everything. + // When that happens we are gonna forcefully throw an error and abort everything. Object.defineProperty(Function.prototype, "g", { configurable: true, @@ -93,35 +92,30 @@ 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 cacheExtractSym = Symbol("vencord.cacheExtract"); - Object.defineProperty(Object.prototype, cacheExtractSym, { - configurable: true, + const assetPath = stack?.match(/\/assets\/.+?\.js/)?.[0]; + if (!assetPath) { + return; + } - get() { - // One more condition to check if this is the Sentry WebpackInstance - if (Array.isArray(this)) { - return { exports: {} }; - } + const srcRequest = new XMLHttpRequest(); + srcRequest.open("GET", assetPath, false); + srcRequest.send(); - new Logger("NoTrack", "#8caaee").info("Disabling Sentry by proxying its WebpackInstance cache"); - Object.setPrototypeOf(this, new Proxy(this, { - get() { - throw new Error("Sentry successfully disabled"); - } - })); + // Final condition to see if this is the Sentry WebpackInstance + if (!srcRequest.responseText.includes("window.DiscordSentry=")) { + return; + } - Reflect.deleteProperty(Object.prototype, cacheExtractSym); - Reflect.deleteProperty(window, "DiscordSentry"); - return { exports: {} }; - } - }); + new Logger("NoTrack", "#8caaee").info("Disabling Sentry by erroring its WebpackInstance"); - // WebpackRequire our fake module id - this(cacheExtractSym); + Reflect.deleteProperty(Function.prototype, "g"); + Reflect.deleteProperty(window, "DiscordSentry"); + + throw new Error("Sentry successfully disabled"); } }); @@ -130,6 +124,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"); } });