From 8eb8290fc46bf61e9c8f0e4ea90bcede999624b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mitja=20=C5=A0everkar?= Date: Wed, 20 Nov 2024 04:00:53 +0100 Subject: [PATCH] Fix URL encoding on Subsonic (#850) * Revert "Encode credential for subsonic stream/coverart (#841)" This reverts commit 8ec4551b46ff532d3790f23faa63f7ee472ffa33. * Properly URL encode credentials on Subsonic Previous commit (8ec4551b46ff532d3790f23faa63f7ee472ffa33) has been reverted, as it has encoded even equal signs (=), and and signs (&), which should not have been encoded. Nextcloud Music has subsequently failed to receive separate username and password and has therefore failed whilst authenticating the user. Example of URL beforehand: https://cloud.example.com/index.php/apps/music/subsonic/rest/stream.view?id=track-4936&v=1.13.0&c=feishin_&u%3Dtest-test%40example.com%26p%3Dpassword Example of URL now: https://cloud.example.com/index.php/apps/music/subsonic/rest/stream.view?id=track-4936&v=1.13.0&c=feishin_&u=test-test%40example.com&p=password --- src/renderer/api/subsonic/subsonic-controller.ts | 4 ++-- src/renderer/api/subsonic/subsonic-normalize.ts | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/renderer/api/subsonic/subsonic-controller.ts b/src/renderer/api/subsonic/subsonic-controller.ts index f80df62e..4ecfef6c 100644 --- a/src/renderer/api/subsonic/subsonic-controller.ts +++ b/src/renderer/api/subsonic/subsonic-controller.ts @@ -65,7 +65,7 @@ export const SubsonicController: ControllerEndpoint = { const cleanServerUrl = `${url.replace(/\/$/, '')}/rest`; if (body.legacy) { - credential = `u=${body.username}&p=${body.password}`; + credential = `u=${encodeURIComponent(body.username)}&p=${encodeURIComponent(body.password)}`; credentialParams = { p: body.password, u: body.username, @@ -73,7 +73,7 @@ export const SubsonicController: ControllerEndpoint = { } else { const salt = randomString(12); const hash = md5(body.password + salt); - credential = `u=${body.username}&s=${salt}&t=${hash}`; + credential = `u=${encodeURIComponent(body.username)}&s=${encodeURIComponent(salt)}&t=${encodeURIComponent(hash)}`; credentialParams = { s: salt, t: hash, diff --git a/src/renderer/api/subsonic/subsonic-normalize.ts b/src/renderer/api/subsonic/subsonic-normalize.ts index 3465fec9..43a4aad4 100644 --- a/src/renderer/api/subsonic/subsonic-normalize.ts +++ b/src/renderer/api/subsonic/subsonic-normalize.ts @@ -24,15 +24,14 @@ const getCoverArtUrl = (args: { return null; } - const url = + return ( `${args.baseUrl}/rest/getCoverArt.view` + `?id=${args.coverArtId}` + - `&${encodeURIComponent(args.credential || '')}` + + `&${args.credential}` + '&v=1.13.0' + '&c=feishin' + - `&size=${size}`; - - return url; + `&size=${size}` + ); }; const normalizeSong = ( @@ -49,7 +48,7 @@ const normalizeSong = ( size: size || 300, }) || null; - const streamUrl = `${server?.url}/rest/stream.view?id=${item.id}&v=1.13.0&c=feishin_${deviceId}&${encodeURIComponent(server?.credential || '')}`; + const streamUrl = `${server?.url}/rest/stream.view?id=${item.id}&v=1.13.0&c=feishin_${deviceId}&${server?.credential}`; return { album: item.album || '',