feat: 生成 Basic Auth 前,对用户名和密码各做一次 URL 解码

This commit is contained in:
xream committed 2026-09-27 10:08:59 +08:00
1 parent 04f44c2ae2
commit 8bf23a634d
2 files changed
+18 -3

No files matched your search

+15
View File
@@ -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: {
+3 -3
View File
@@ -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')}`,
};
}