Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix(app-connection): harden github non-gateway request handling

Vlad Ligai8e59c9f54870
diff --git a/backend/src/services/app-connection/github/github-connection-fns.test.ts b/backend/src/services/app-connection/github/github-connection-fns.test.ts
index f88148fce5..2fac7ed174 100644
--- a/backend/src/services/app-connection/github/github-connection-fns.test.ts
+++ b/backend/src/services/app-connection/github/github-connection-fns.test.ts
@@ -55,6 +55,19 @@ describe("requestWithGitHubGateway — non-gateway SSRF guard", () => {
expect(blockMock).toHaveBeenCalledWith("https://api.github.com/user/repos");
expect(requestMock).toHaveBeenCalledTimes(1);
expect(blockMock.mock.invocationCallOrder[0]).toBeLessThan(requestMock.mock.invocationCallOrder[0]);
+ // Redirects must not be followed, so the request cannot be redirected off the validated host.
+ expect(requestMock).toHaveBeenCalledWith(expect.objectContaining({ maxRedirects: 0 }));
+ });
+
+ it("rejects a request with no URL instead of throwing a raw TypeError", async () => {
+ blockMock.mockResolvedValue(undefined);
+
+ await expect(
+ requestWithGitHubGateway({ gatewayId: null }, {} as any, {} as any, { method: "GET" })
+ ).rejects.toThrow(/missing a target URL/);
+
+ expect(blockMock).not.toHaveBeenCalled();
+ expect(requestMock).not.toHaveBeenCalled();
});
it("does not issue the request when the host guard rejects (non-gateway path)", async () => {
diff --git a/backend/src/services/app-connection/github/github-connection-fns.ts b/backend/src/services/app-connection/github/github-connection-fns.ts
index db05b97ace..7a4a3b3bf5 100644
--- a/backend/src/services/app-connection/github/github-connection-fns.ts
+++ b/backend/src/services/app-connection/github/github-connection-fns.ts
@@ -198,15 +198,20 @@ export const requestWithGitHubGateway = async <T>(
): Promise<AxiosResponse<T>> => {
const { gatewayId } = appConnection;
- const url = new URL(requestConfig.url as string);
+ if (!requestConfig.url) {
+ throw new BadRequestError({ message: "GitHub connection request is missing a target URL" });
+ }
+
+ const url = new URL(requestConfig.url);
// Validate the target host on every request, including the non-gateway path and any
// server-provided pagination URLs, before the request is issued.
await blockLocalAndPrivateIpAddresses(url.toString());
- // If gateway isn't set up, don't proxy request
+ // If gateway isn't set up, don't proxy request. Do not follow redirects here, so the
+ // validated host is the one that is actually contacted.
if (!gatewayId) {
- return httpRequest.request(requestConfig);
+ return httpRequest.request({ ...requestConfig, maxRedirects: 0 });
}
const [targetHost] = await verifyHostInputValidity({ host: url.host, isGateway: true, isDynamicSecret: false });