Skip to content

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

fix(github-org-sync): fail sync instead of applying partial member list when team lookup returns null

Devin AI336ead1639dd
diff --git a/backend/src/ee/services/github-org-sync/github-org-sync-service.test.ts b/backend/src/ee/services/github-org-sync/github-org-sync-service.test.ts
index 0ac7e07820..9e8947170b 100644
--- a/backend/src/ee/services/github-org-sync/github-org-sync-service.test.ts
+++ b/backend/src/ee/services/github-org-sync/github-org-sync-service.test.ts
@@ -1,6 +1,8 @@
import { Octokit } from "@octokit/core";
import { describe, expect, test, vi } from "vitest";
+import { BadRequestError } from "@app/lib/errors";
+
import { fetchGithubOrgTeams } from "./github-org-sync-service";
type TVariables = { cursor: string | null; slug?: string; teamsPageSize?: number; membersPageSize?: number };
@@ -67,6 +69,17 @@ describe("fetchGithubOrgTeams", () => {
expect(graphql).toHaveBeenCalledTimes(3);
});
+ test("fails instead of returning a partial member list when the team disappears mid-pagination", async () => {
+ const { octokit } = buildOctokit((query) => {
+ if (query.includes("query orgTeams")) {
+ return { organization: { teams: page([team("big", ["u1"], "m1")], null) } };
+ }
+ return { organization: { team: null } };
+ });
+
+ await expect(fetchGithubOrgTeams(octokit, "acme")).rejects.toThrow(BadRequestError);
+ });
+
test("passes a per-request abort signal", async () => {
const { octokit, graphql } = buildOctokit(() => ({ organization: { teams: page([], null) } }));
diff --git a/backend/src/ee/services/github-org-sync/github-org-sync-service.ts b/backend/src/ee/services/github-org-sync/github-org-sync-service.ts
index 187414bc35..c6d554b92c 100644
--- a/backend/src/ee/services/github-org-sync/github-org-sync-service.ts
+++ b/backend/src/ee/services/github-org-sync/github-org-sync-service.ts
@@ -181,17 +181,20 @@ export const fetchGithubOrgTeams = async (octokit: Pick<Octokit, "graphql">, org
membersPageSize: GITHUB_TEAM_MEMBERS_PAGE_SIZE
});
const connection = data.organization.team?.members;
- if (!connection) break;
+ if (!connection) {
+ throw new BadRequestError({
+ message: `GitHub team '${team.slug}' was renamed or deleted while its members were being listed. Please run the sync again.`
+ });
+ }
team.members.push(...connection.edges.map((edge) => edge.node.login));
team.membersCursor = nextCursor(connection.pageInfo);
membersPage += 1;
}
if (team.membersCursor) {
- logger.warn(
- { org, team: team.slug, fetchedMembers: team.members.length },
- "GitHub org team sync hit the page cap; team member list truncated"
- );
+ throw new BadRequestError({
+ message: `GitHub team '${team.slug}' has more members than can be synced (${GITHUB_MAX_PAGES * GITHUB_TEAM_MEMBERS_PAGE_SIZE} member limit).`
+ });
}
}
@@ -758,6 +761,7 @@ export const githubOrgSyncServiceFactory = ({
const octokit = new Octokit({ auth: orgAccessToken });
const githubTeams = await fetchGithubOrgTeams(octokit, config.githubOrgName).catch((err) => {
+ if (err instanceof BadRequestError) throw err;
logger.error(err, "GitHub GraphQL error for batched team sync");
const gitHubError = err as GitHubApiError;