From 8bf23a634d923fea8d20d4e4aebd5ac7f7563396 Mon Sep 17 00:00:00 2001 From: xream Date: Sun, 27 Sep 2026 10:08:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=94=9F=E6=88=90=20Basic=20Auth=20?= =?UTF-8?q?=E5=89=8D=EF=BC=8C=E5=AF=B9=E7=94=A8=E6=88=B7=E5=90=8D=E5=92=8C?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E5=90=84=E5=81=9A=E4=B8=80=E6=AC=A1=20URL=20?= =?UTF-8?q?=E8=A7=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/test/vendor/open-api.spec.js | 15 +++++++++++++++ backend/src/vendor/open-api.js | 6 +++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/backend/src/test/vendor/open-api.spec.js b/backend/src/test/vendor/open-api.spec.js index 7faa854c..716dac3c 100644 --- a/backend/src/test/vendor/open-api.spec.js +++ b/backend/src/test/vendor/open-api.spec.js @@ -209,6 +209,21 @@ describe('open-api HTTP adapter', function () { }); }); + it('decodes URL credentials once before creating Basic authentication', async function () { + for (const [userinfo, credentials] of [ + ['user%40name:p%40ss%3A%2520', 'user@name:p@ss:%20'], + ['user:pass', 'user:pass'], + ['user%40name', 'user@name:'], + [':p%40ss', ':p@ss'], + ]) { + await HTTP().get(`https://${userinfo}@example.test/subscription`); + + expect(requestOptions.headers.authorization).to.equal( + `Basic ${Buffer.from(credentials).toString('base64')}`, + ); + } + }); + it('keeps an explicit Accept header in Node.js', async function () { await HTTP({ headers: { diff --git a/backend/src/vendor/open-api.js b/backend/src/vendor/open-api.js index 93bdcd74..07ae2edb 100644 --- a/backend/src/vendor/open-api.js +++ b/backend/src/vendor/open-api.js @@ -534,9 +534,9 @@ export function HTTP(defaultOptions = { baseURL: '' }) { opts.headers = { ...(opts.headers || {}), Authorization: `Basic ${Buffer.from( - `${url.username || ''}:${ - url.password || '' - }`, + `${decodeURIComponent( + url.username, + )}:${decodeURIComponent(url.password)}`, ).toString('base64')}`, }; }