mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-28 15:33:47 +00:00
feat: 生成 Basic Auth 前,对用户名和密码各做一次 URL 解码
This commit is contained in:
2 files changed
+18
-3
No files matched your search
+15
@@ -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: {
|
||||
|
||||
Vendored
+3
-3
@@ -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')}`,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user