Skip to content

Commit 113acfe

Browse files
block artifact download redirects
1 parent 15e95de commit 113acfe

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/lib/bundle.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,22 @@ describe('streamUrlToFile retry', () => {
667667
expect(calls).toBe(1);
668668
});
669669

670+
it('disables automatic redirects so unsafe redirect targets cannot bypass URL validation', async () => {
671+
const dir = mkdtempSync(join(tmpdir(), 'stream-test-'));
672+
const dest = join(dir, 'out.bin');
673+
const redirects: Array<RequestInit['redirect']> = [];
674+
const fetchImpl = async (_url: Parameters<typeof globalThis.fetch>[0], init?: RequestInit) => {
675+
redirects.push(init?.redirect);
676+
return new Response('hello', { status: 200 });
677+
};
678+
679+
await streamUrlToFile('https://example.com/x', dest, fetchImpl as typeof globalThis.fetch, {
680+
sleep: noSleep,
681+
});
682+
683+
expect(redirects).toEqual(['error']);
684+
});
685+
670686
it('sleeps between retries', async () => {
671687
const sleepDelays: number[] = [];
672688
const fetchImpl = async () => {

src/lib/bundle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ export async function streamUrlToFile(
715715
for (let attempt = 1; attempt <= STREAM_URL_MAX_RETRIES; attempt++) {
716716
let response: Response;
717717
try {
718-
response = await fetchImpl(url);
718+
response = await fetchImpl(url, { redirect: 'error' });
719719
} catch (err) {
720720
const message = err instanceof Error ? err.message : String(err);
721721
if (attempt < STREAM_URL_MAX_RETRIES) {

0 commit comments

Comments
 (0)