Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/cli/src/config/extensions/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,9 @@ export async function downloadFile(
new Error('Redirect response missing Location header'),
);
}
downloadFile(res.headers.location, dest, options, redirectCount + 1)
res.resume(); // Drain response body to free the socket

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While adding res.resume() here is correct, the same logic is missing in the error paths within this redirect block. Specifically, if the redirect count is exceeded (line 538) or if the Location header is missing (line 542), the response body is not drained, leading to a socket leak. To ensure robust resource management, the response should be resumed in all cases where the body is not consumed.

const redirectUrl = new URL(res.headers.location, url).toString();
downloadFile(redirectUrl, dest, options, redirectCount + 1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

Following redirects blindly while re-adding the Authorization header poses a security risk. If the request is redirected to a different domain (e.g., a CDN like S3 where GitHub release assets are often stored), the GitHub token will be leaked to that third party. According to GitHub's security best practices, the Authorization header should only be sent to trusted GitHub domains (e.g., github.com or api.github.com) and should be stripped when following redirects to external hosts. The implementation should be updated to only include the Authorization header if the target URL is on a trusted domain. Note that since the token is added at the start of the downloadFile function (lines 528-531), the fix should be applied there. This same issue likely exists in the fetchJson function in github_fetch.ts.

.then(resolve)
.catch(reject);
return;
Expand Down