diff --git a/src/main/kotlin/app/revanced/patches/music/misc/tracking/SanitizeUrlQueryPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/tracking/SanitizeUrlQueryPatch.kt
new file mode 100644
index 000000000..65a0112e7
--- /dev/null
+++ b/src/main/kotlin/app/revanced/patches/music/misc/tracking/SanitizeUrlQueryPatch.kt
@@ -0,0 +1,48 @@
+package app.revanced.patches.music.misc.tracking
+
+import app.revanced.patcher.data.BytecodeContext
+import app.revanced.patcher.patch.annotation.CompatiblePackage
+import app.revanced.patcher.patch.annotation.Patch
+import app.revanced.patches.music.misc.tracking.fingerprints.ShareLinkFormatterFingerprint
+import app.revanced.patches.music.utils.settings.SettingsPatch
+import app.revanced.patches.shared.fingerprints.tracking.CopyTextEndpointFingerprint
+import app.revanced.patches.shared.patch.tracking.AbstractSanitizeUrlQueryPatch
+import app.revanced.util.enum.CategoryType
+import app.revanced.util.integrations.Constants.MUSIC_MISC_PATH
+
+@Patch(
+ name = "Sanitize sharing links",
+ description = "Removes tracking query parameters from the URLs when sharing links.",
+ dependencies = [SettingsPatch::class],
+ compatiblePackages = [
+ CompatiblePackage(
+ "com.google.android.apps.youtube.music",
+ [
+ "6.15.52",
+ "6.20.51",
+ "6.26.51",
+ "6.27.53"
+ ]
+ )
+ ]
+)
+@Suppress("unused")
+object SanitizeUrlQueryPatch : AbstractSanitizeUrlQueryPatch(
+ "$MUSIC_MISC_PATH/SanitizeUrlQueryPatch;",
+ listOf(
+ CopyTextEndpointFingerprint,
+ ShareLinkFormatterFingerprint
+ ),
+ null
+) {
+ override fun execute(context: BytecodeContext) {
+ super.execute(context)
+
+ SettingsPatch.addMusicPreference(
+ CategoryType.MISC,
+ "revanced_sanitize_sharing_links",
+ "true"
+ )
+
+ }
+}
diff --git a/src/main/kotlin/app/revanced/patches/music/misc/tracking/fingerprints/ShareLinkFormatterFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/misc/tracking/fingerprints/ShareLinkFormatterFingerprint.kt
new file mode 100644
index 000000000..3e47cc71d
--- /dev/null
+++ b/src/main/kotlin/app/revanced/patches/music/misc/tracking/fingerprints/ShareLinkFormatterFingerprint.kt
@@ -0,0 +1,38 @@
+package app.revanced.patches.music.misc.tracking.fingerprints
+
+import app.revanced.patcher.fingerprint.MethodFingerprint
+import com.android.tools.smali.dexlib2.Opcode
+import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
+import com.android.tools.smali.dexlib2.iface.reference.FieldReference
+
+/**
+ * Sharing panel of YouTube Music
+ */
+object ShareLinkFormatterFingerprint : MethodFingerprint(
+ returnType = "V",
+ parameters = listOf("L", "Ljava/util/Map;"),
+ opcodes = listOf(
+ Opcode.IGET_OBJECT,
+ Opcode.CHECK_CAST,
+ Opcode.GOTO,
+ Opcode.CONST_STRING,
+ Opcode.INVOKE_VIRTUAL
+ ),
+ customFingerprint = custom@{ methodDef, _ ->
+ if (methodDef.implementation == null)
+ return@custom false
+
+ var count = 0
+ for (instruction in methodDef.implementation!!.instructions) {
+ if (instruction.opcode != Opcode.SGET_OBJECT)
+ continue
+
+ val objectInstruction = instruction as ReferenceInstruction
+ if ((objectInstruction.reference as FieldReference).name != "androidAppEndpoint")
+ continue
+
+ count++
+ }
+ count == 2
+ }
+)
\ No newline at end of file
diff --git a/src/main/resources/music/settings/host/values/strings.xml b/src/main/resources/music/settings/host/values/strings.xml
index 98b088dee..781fde65e 100644
--- a/src/main/resources/music/settings/host/values/strings.xml
+++ b/src/main/resources/music/settings/host/values/strings.xml
@@ -159,6 +159,8 @@ WARNING: Do not enable new player backgrounds while this is enabled."
Shows the dislike count of videos.
Dislikes not available (client API limit reached).
Hidden
+ Removes tracking query parameters from the URLs when sharing links.
+ Sanitize sharing links
Changing default speed to:
Changing default mobile data quality to:
Failed to set quality.