From caab66b6530b724ea59c455f6ddfa803d6a30988 Mon Sep 17 00:00:00 2001 From: Joe Babbitt Date: Tue, 29 Apr 2025 17:22:38 -0400 Subject: [PATCH] use punycode URL for redirect page Redirect page content gets encoded as LATIN1, non LATIN characters in URLs get malformed. --- SSO-Auth/WebResponse.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/SSO-Auth/WebResponse.cs b/SSO-Auth/WebResponse.cs index a25ac2e..d642bb2 100644 --- a/SSO-Auth/WebResponse.cs +++ b/SSO-Auth/WebResponse.cs @@ -1,3 +1,5 @@ +using System.Globalization; + namespace Jellyfin.Plugin.SSO_Auth; /// @@ -404,6 +406,14 @@ const sleep = (milliseconds) => { /// A string with the HTML to serve to the client. public static string Generator(string data, string provider, string baseUrl, string mode, bool isLinking = false) { + // Strip out the protocol (http:// or https://) and convert the domain to Punycode + var idnMapping = new IdnMapping(); + var protocolSeparatorIndex = baseUrl.IndexOf("//"); + var protocol = baseUrl.Substring(0, protocolSeparatorIndex + 2); + var domain = baseUrl.Substring(protocolSeparatorIndex + 2); + var punycodeDomain = idnMapping.GetAscii(domain); + var punycodeBaseUrl = protocol + punycodeDomain; + return Base + @" async function link(request) { const jfCredentialsString = localStorage.getItem(""jellyfin_credentials""); @@ -417,7 +427,7 @@ async function link(request) { if (jfUser == null) return; if (jfToken == null) return; - const url = '" + $"{baseUrl}/sso/{mode}/Link/{provider}/" + @"' + jfUser; + const url = '" + $"{punycodeBaseUrl}/sso/{mode}/Link/{provider}/" + @"' + jfUser; return new Promise(resolve => { var xhr = new XMLHttpRequest(); @@ -442,7 +452,7 @@ async function link(request) { async function main() { localStorage.removeItem('jellyfin_credentials'); - document.getElementById('iframe-main').src = '" + baseUrl + @"/web/index.html'; + document.getElementById('iframe-main').src = '" + punycodeBaseUrl + @"/web/index.html'; var data = '" + data + @"'; while (localStorage.getItem(""_deviceId2"") == null || @@ -460,7 +470,7 @@ async function main() { if (" + $"{isLinking}".ToLower() + @") await link(request); - var url = '" + baseUrl + "/sso/" + mode + "/Auth/" + provider + @"'; + var url = '" + punycodeBaseUrl + "/sso/" + mode + "/Auth/" + provider + @"'; let response = await new Promise(resolve => { var xhr = new XMLHttpRequest(); @@ -484,7 +494,7 @@ async function main() { jfCreds['Servers'][0]['UserId'] = responseJson['User']['Id']; localStorage.setItem('jellyfin_credentials', JSON.stringify(jfCreds)); localStorage.setItem('enableAutoLogin', 'true'); - window.location.replace('" + baseUrl + @"/web/index.html'); + window.location.replace('" + punycodeBaseUrl + @"/web/index.html'); } document.addEventListener('DOMContentLoaded', function () {