Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix: do not allow secrets that start with github_ to try the sync more than once
adilsond657c2cbc525
diff --git a/backend/src/services/secret-sync/github/github-sync-fns.test.ts b/backend/src/services/secret-sync/github/github-sync-fns.test.tsindex 6f9b7623c6..992024b773 100644--- a/backend/src/services/secret-sync/github/github-sync-fns.test.ts+++ b/backend/src/services/secret-sync/github/github-sync-fns.test.ts@@ -276,7 +276,7 @@ describe("GithubSyncFns.syncSecrets", () => {expect(callsWith("PUT")).toHaveLength(1000);});- it.each(["BAD NAME", "BAD-NAME", "1LEADING"])(+ it.each(["BAD NAME", "BAD-NAME", "1LEADING", "GITHUB_TOKEN"])("refuses %s before calling GitHub and names that secret",async (key) => {const error = await runSync(@@ -288,7 +288,7 @@ describe("GithubSyncFns.syncSecrets", () => {expect(error).toMatchObject({shouldRetry: false,secretKey: key,- message: `GitHub does not accept secret names unless they contain only letters, digits, and underscores, and start with a letter or an underscore. Spaces are not allowed. Rename the secrets that failed this check: "${key}".`+ message: `GitHub does not accept secret names unless they contain only letters, digits, and underscores, and start with a letter or an underscore. Spaces are not allowed. Names cannot start with GITHUB_, regardless of case. Rename the secrets that failed this check: "${key}".`});expect((error as SecretSyncError).message).not.toContain("VALID_NAME");expect(requestMock).not.toHaveBeenCalled();@@ -312,6 +312,27 @@ describe("GithubSyncFns.syncSecrets", () => {expect(paginatedMock).not.toHaveBeenCalled();});+ it("refuses a secret that starts with github_ regardless of case", async () => {+ const error = await runSync(+ makeSync(repoConfig(GitHubSyncSecretType.Dependabot)),+ makePayload(["github_token", "VALID_NAME"])+ ).catch((err: unknown) => err);++ expect(error).toMatchObject({+ shouldRetry: false,+ secretKey: "GITHUB_TOKEN",+ message: expect.stringContaining('"GITHUB_TOKEN"')+ });+ expect(requestMock).not.toHaveBeenCalled();+ expect(paginatedMock).not.toHaveBeenCalled();+ });++ it("syncs a secret that contains GITHUB_ but does not start with it", async () => {+ await runSync(makeSync(repoConfig(GitHubSyncSecretType.Dependabot)), makePayload(["MY_GITHUB_TOKEN"]));++ expect(callsWith("PUT")[0].url).toBe("https://api.github.com/repos/acme/app/dependabot/secrets/MY_GITHUB_TOKEN");+ });+it("syncs a secret name that starts with an underscore", async () => {await runSync(makeSync(repoConfig(GitHubSyncSecretType.Dependabot)), makePayload(["_TOKEN"]));diff --git a/backend/src/services/secret-sync/github/github-sync-fns.ts b/backend/src/services/secret-sync/github/github-sync-fns.tsindex 937b4cf686..5392671d95 100644--- a/backend/src/services/secret-sync/github/github-sync-fns.ts+++ b/backend/src/services/secret-sync/github/github-sync-fns.ts@@ -71,12 +71,16 @@ const CODESPACES_ON_GITHUB_SERVER_MESSAGE ="Codespaces secrets are not available on GitHub Enterprise Server. Choose the Actions or Dependabot secret type, or use a GitHub.com connection.";const GITHUB_SECRET_NAME_PATTERN = new RE2(/^[A-Za-z_][A-Za-z0-9_]*$/);+const GITHUB_RESERVED_PREFIX = new RE2(/^GITHUB_/i);const GITHUB_SECRET_NAME_RULE =- "GitHub does not accept secret names unless they contain only letters, digits, and underscores, and start with a letter or an underscore. Spaces are not allowed.";+ "GitHub does not accept secret names unless they contain only letters, digits, and underscores, and start with a letter or an underscore. Spaces are not allowed. Names cannot start with GITHUB_, regardless of case.";++const isGitHubSecretName = (name: string) =>+ GITHUB_SECRET_NAME_PATTERN.test(name) && !GITHUB_RESERVED_PREFIX.test(name);const assertGitHubSecretNames = (names: string[]) => {- const invalidNames = names.filter((name) => !GITHUB_SECRET_NAME_PATTERN.test(name));+ const invalidNames = names.filter((name) => !isGitHubSecretName(name));if (!invalidNames.length) return;throw new SecretSyncError({