Skip to content

Commit 0fc0b69

Browse files
authored
fix(install-source): preserve URL credential validation error (#1762)
* fix(install-source): preserve URL credential validation error * test(install-source): cover URL credential validation error
1 parent 52ef4ca commit 0fc0b69

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/platforms/__tests__/install-source-download.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ test('download errors do not disclose URL credentials or query values', async ()
7171
headers: { authorization: 'private-header' },
7272
signal: new AbortController().signal,
7373
}).catch((caught: unknown) => caught);
74+
assert.match((error as Error).message, /credentials are not allowed/i);
7475
const serialized = JSON.stringify(error);
7576
for (const secret of ['private-user', 'private-pass', 'private-query', 'private-header']) {
7677
assert.equal(serialized.includes(secret), false, secret);

src/platforms/install-source-download.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,15 @@ function readHeader(
179179
}
180180

181181
function parseSourceUrl(raw: string): URL {
182+
let parsed: URL;
182183
try {
183-
const parsed = new URL(raw);
184-
if (parsed.username || parsed.password) {
185-
throw new AppError('INVALID_ARGS', 'Source URL credentials are not allowed');
186-
}
187-
return parsed;
184+
parsed = new URL(raw);
188185
} catch {
189186
throw new AppError('INVALID_ARGS', 'Invalid source URL');
190187
}
188+
189+
if (parsed.username || parsed.password) {
190+
throw new AppError('INVALID_ARGS', 'Source URL credentials are not allowed');
191+
}
192+
return parsed;
191193
}

0 commit comments

Comments
 (0)