Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions packages/cli/src/config/extensions/github_fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,24 @@ describe('fetchJson', () => {
).resolves.toEqual({ permanent: true });
});

it('should reject with "Too many redirects" after 10 redirects', async () => {
// Each call returns a redirect to the same URL, simulating an infinite loop
for (let i = 0; i <= 10; i++) {
getMock.mockImplementationOnce((_url, _options, callback) => {
const res = new EventEmitter() as IncomingMessage;
res.statusCode = 302;
res.headers = { location: 'https://example.com/loop' };
(callback as (res: IncomingMessage) => void)(res);
res.emit('end');
return new EventEmitter() as ClientRequest;
});
}

await expect(fetchJson('https://example.com/loop')).rejects.toThrow(
'Too many redirects',
);
});

it('should reject on non-200/30x status code', async () => {
getMock.mockImplementationOnce((_url, _options, callback) => {
const res = new EventEmitter() as IncomingMessage;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/config/extensions/github_fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function fetchJson<T>(
if (!res.headers.location) {
return reject(new Error('No location header in redirect response'));
}
fetchJson<T>(res.headers.location, redirectCount++)
fetchJson<T>(res.headers.location, 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

The fetchJson function includes the GITHUB_TOKEN in the Authorization header for all requests. When following redirects (301/302), the function recursively calls itself with the new URL from the location header, which results in the token being sent to the new destination. If a trusted host redirects to an untrusted domain, the sensitive GitHub token will be leaked to the external party.

Remediation: Implement a check to ensure that the Authorization header is only included if the target URL (including redirect locations) belongs to a trusted domain (e.g., github.com). For cross-origin redirects, the token should be stripped. This aligns with the repository requirement to sanitize environment usage and prevent exfiltration of sensitive data.

References
  1. Sanitize the environment used for variable expansion in HTTP headers to prevent malicious extensions from exfiltrating sensitive system environment variables.

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