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
remove unintended column
Thiago Araujo da Silva05d5aa852dde
diff --git a/backend/src/db/migrations/20260529204743_create-github-apps.ts b/backend/src/db/migrations/20260529204743_create-github-apps.tsindex e8c96285dc..f0971a40ff 100644--- a/backend/src/db/migrations/20260529204743_create-github-apps.ts+++ b/backend/src/db/migrations/20260529204743_create-github-apps.ts@@ -24,25 +24,9 @@ export async function up(knex: Knex): Promise<void> {await createOnUpdateTrigger(knex, TableName.GitHubApp);}-- if (!(await knex.schema.hasColumn(TableName.AppConnection, "gitHubAppId"))) {- await knex.schema.alterTable(TableName.AppConnection, (t) => {- t.uuid("gitHubAppId").nullable();- t.foreign("gitHubAppId").references("id").inTable(TableName.GitHubApp).onDelete("SET NULL");- t.index("gitHubAppId");- });- }}export async function down(knex: Knex): Promise<void> {- if (await knex.schema.hasColumn(TableName.AppConnection, "gitHubAppId")) {- await knex.schema.alterTable(TableName.AppConnection, (t) => {- t.dropForeign(["gitHubAppId"]);- t.dropIndex("gitHubAppId");- t.dropColumn("gitHubAppId");- });- }-await knex.schema.dropTableIfExists(TableName.GitHubApp);await dropOnUpdateTrigger(knex, TableName.GitHubApp);}diff --git a/backend/src/db/schemas/app-connections.ts b/backend/src/db/schemas/app-connections.tsindex cabcb6b93e..e27ece3b9c 100644--- a/backend/src/db/schemas/app-connections.ts+++ b/backend/src/db/schemas/app-connections.ts@@ -25,8 +25,7 @@ export const AppConnectionsSchema = z.object({projectId: z.string().nullable().optional(),isAutoRotationEnabled: z.boolean().default(false),gatewayPoolId: z.string().uuid().nullable().optional(),- encryptedConfiguration: zodBuffer.nullable().optional(),- gitHubAppId: z.string().uuid().nullable().optional()+ encryptedConfiguration: zodBuffer.nullable().optional()});export type TAppConnections = z.infer<typeof AppConnectionsSchema>;diff --git a/backend/src/services/app-connection/app-connection-dal.ts b/backend/src/services/app-connection/app-connection-dal.tsindex 5926896c0e..275fa1ffb8 100644--- a/backend/src/services/app-connection/app-connection-dal.ts+++ b/backend/src/services/app-connection/app-connection-dal.ts@@ -203,21 +203,21 @@ export const appConnectionDALFactory = (db: TDbClient) => {return parseInt(String(result?.count || "0"), 10);};- // Counts GitHub App method connections per referenced GitHub App. The null bucket corresponds- // to connections using the instance-default (shared) GitHub App.- const countByGitHubApp = async (orgId: string, tx?: Knex) => {+ // Returns the org's GitHub App method connections. Which GitHub App each connection references+ // lives inside the encrypted credentials, so callers decrypt to group/count per app.+ const findGitHubAppMethodConnections = async (orgId: string, tx?: Knex) => {const rows = await (tx || db.replicaNode())(TableName.AppConnection).where(`${TableName.AppConnection}.orgId`, orgId).andWhere(`${TableName.AppConnection}.app`, "github").andWhere(`${TableName.AppConnection}.method`, "github-app")- .groupBy(`${TableName.AppConnection}.gitHubAppId`)- .select(db.ref("gitHubAppId").withSchema(TableName.AppConnection))- .count("id");-- return rows.map((row) => ({- gitHubAppId: (row as { gitHubAppId: string | null }).gitHubAppId,- count: parseInt(String(row.count || "0"), 10)- }));+ .select(+ db.ref("id").withSchema(TableName.AppConnection),+ db.ref("orgId").withSchema(TableName.AppConnection),+ db.ref("projectId").withSchema(TableName.AppConnection),+ db.ref("encryptedCredentials").withSchema(TableName.AppConnection)+ );++ return rows;};return {@@ -228,6 +228,6 @@ export const appConnectionDALFactory = (db: TDbClient) => {countByGatewayId,findByGatewayPoolId,countByGatewayPoolId,- countByGitHubApp+ findGitHubAppMethodConnections};};diff --git a/backend/src/services/app-connection/app-connection-service.ts b/backend/src/services/app-connection/app-connection-service.tsindex 0a49aed44a..b8fc677aa9 100644--- a/backend/src/services/app-connection/app-connection-service.ts+++ b/backend/src/services/app-connection/app-connection-service.ts@@ -107,7 +107,7 @@ import { ValidateFlyioConnectionCredentialsSchema } from "./flyio";import { flyioConnectionService } from "./flyio/flyio-connection-service";import { ValidateGcpConnectionCredentialsSchema } from "./gcp";import { gcpConnectionService } from "./gcp/gcp-connection-service";-import { GitHubConnectionMethod, ValidateGitHubConnectionCredentialsSchema } from "./github";+import { ValidateGitHubConnectionCredentialsSchema } from "./github";import { githubConnectionService } from "./github/github-connection-service";import { ValidateGitHubRadarConnectionCredentialsSchema } from "./github-radar";import { githubRadarConnectionService } from "./github-radar/github-radar-connection-service";@@ -261,17 +261,6 @@ const VALIDATE_APP_CONNECTION_CREDENTIALS_MAP: Record<AppConnection, TValidateAp[AppConnection.F5BigIp]: ValidateF5BigIpConnectionCredentialsSchema};-// Extracts the GitHub App reference to persist in the queryable app_connections.gitHubAppId column.-// Only GitHub App method connections reference a custom app; null means the instance-default (shared) app.-const resolveGitHubAppIdColumn = (- app: AppConnection,- method: string,- credentials: TAppConnection["credentials"] | undefined-): string | null => {- if (app !== AppConnection.GitHub || method !== GitHubConnectionMethod.App) return null;- return (credentials as { gitHubAppId?: string | null } | undefined)?.gitHubAppId ?? null;-};-export const appConnectionServiceFactory = ({appConnectionDAL,permissionService,@@ -555,10 +544,6 @@ export const appConnectionServiceFactory = ({{ identityUaDAL, gitHubAppDAL, kmsService });- // For GitHub App connections we mirror the referenced GitHub App into a queryable FK column so- // we can count/enforce reuse without decrypting credentials. Null = instance-default (shared) app.- const gitHubAppId = resolveGitHubAppIdColumn(app, method, validatedCredentials);-try {const createConnection = async (connectionCredentials: TAppConnection["credentials"]) => {return appConnectionDAL.transaction(async (tx) => {@@ -583,7 +568,6 @@ export const appConnectionServiceFactory = ({encryptedConfiguration,method,app,- gitHubAppId,gatewayId: gatewayPoolId ? null : gatewayId,gatewayPoolId: gatewayPoolId ?? null,projectId,@@ -817,17 +801,11 @@ export const appConnectionServiceFactory = ({}): undefined;- // Keep the queryable GitHub App FK in sync whenever credentials are re-validated on update.- const gitHubAppIdUpdate = updatedCredentials- ? { gitHubAppId: resolveGitHubAppIdColumn(app, method, updatedCredentials) }- : {};-return appConnectionDAL.updateById(connectionId,{orgId: actor.orgId,encryptedCredentials,- ...gitHubAppIdUpdate,...(encryptedConfiguration !== undefined && { encryptedConfiguration }),...(gatewayIdValue !== undefined && { gatewayId: gatewayIdValue }),...(gatewayPoolIdValue !== undefined && { gatewayPoolId: gatewayPoolIdValue }),diff --git a/backend/src/services/github-app/github-app-service.ts b/backend/src/services/github-app/github-app-service.tsindex 6ce995f54b..4176bcdde5 100644--- a/backend/src/services/github-app/github-app-service.ts+++ b/backend/src/services/github-app/github-app-service.ts@@ -1,6 +1,7 @@import { ForbiddenError } from "@casl/ability";import { AxiosError } from "axios";import jwt from "jsonwebtoken";+import { Knex } from "knex";import { OrganizationActionScope } from "@app/db/schemas";import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";@@ -13,6 +14,7 @@ import { BadRequestError, DatabaseError, NotFoundError } from "@app/lib/errors";import { logger } from "@app/lib/logger";import { safeRequest } from "@app/lib/validator/safe-request";import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";+import { decryptAppConnectionCredentials } from "@app/services/app-connection/app-connection-fns";import {assertPlatformGitHubHostAllowed,getGitHubInstanceApiUrl,@@ -35,7 +37,7 @@ import {type TGitHubAppServiceFactoryDep = {gitHubAppDAL: TGitHubAppDALFactory;- appConnectionDAL: Pick<TAppConnectionDALFactory, "countByGitHubApp">;+ appConnectionDAL: Pick<TAppConnectionDALFactory, "findGitHubAppMethodConnections">;permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;keyStore: Pick<TKeyStoreFactory, "setItemWithExpiryNX" | "deleteItem">;@@ -50,6 +52,27 @@ export const gitHubAppServiceFactory = ({kmsService,keyStore}: TGitHubAppServiceFactoryDep) => {+ const countConnectionsByGitHubApp = async (orgId: string, tx?: Knex) => {+ const connections = await appConnectionDAL.findGitHubAppMethodConnections(orgId, tx);++ const counts = new Map<string | null, number>();+ await Promise.all(+ connections.map(async (connection) => {+ const credentials = await decryptAppConnectionCredentials({+ orgId: connection.orgId,+ projectId: connection.projectId,+ encryptedCredentials: connection.encryptedCredentials,+ kmsService+ });++ const gitHubAppId = (credentials as { gitHubAppId?: string | null }).gitHubAppId ?? null;+ counts.set(gitHubAppId, (counts.get(gitHubAppId) ?? 0) + 1);+ })+ );++ return counts;+ };+const listGitHubApps = async ({ orgPermission }: TListGitHubAppsDTO): Promise<TSanitizedGitHubApp[]> => {const { permission } = await permissionService.getOrgPermission({actor: orgPermission.type,@@ -64,8 +87,7 @@ export const gitHubAppServiceFactory = ({const apps = await gitHubAppDAL.find({ orgId: orgPermission.orgId });- const connectionCounts = await appConnectionDAL.countByGitHubApp(orgPermission.orgId);- const countByAppId = new Map(connectionCounts.map(({ gitHubAppId, count }) => [gitHubAppId, count]));+ const countByAppId = await countConnectionsByGitHubApp(orgPermission.orgId);const dbApps: TSanitizedGitHubApp[] = apps.map((app) => ({id: app.id,@@ -200,8 +222,8 @@ export const gitHubAppServiceFactory = ({throw new NotFoundError({ message: `GitHub App with id ${id} not found in this organization.` });}- const connectionCounts = await appConnectionDAL.countByGitHubApp(orgPermission.orgId, tx);- const connectionCount = connectionCounts.find(({ gitHubAppId }) => gitHubAppId === existing.id)?.count ?? 0;+ const connectionCounts = await countConnectionsByGitHubApp(orgPermission.orgId, tx);+ const connectionCount = connectionCounts.get(existing.id) ?? 0;if (connectionCount > 0) {throw new BadRequestError({@@ -369,12 +391,6 @@ export const gitHubAppServiceFactory = ({assertPlatformGitHubHostAllowed(githubHost);- // Claim the (orgId, name) slot before asking GitHub to create the app. Without this, two- // concurrent callbacks for the same name both pass the precheck above, GitHub mints a real app- // for each of them, and the loser of the insert race leaves a live app — whose private key was- // never recorded — orphaned on GitHub. GitHub exposes no API to delete an app, so that orphan- // cannot be cleaned up programmatically; failing the loser here, before the conversion, is the- // only reliable prevention. The lock is released below once the insert settles either way.const nameLockKey = KeyStorePrefixes.GitHubManifestNameLock(orgId, name);const nameLockClaimed = await keyStore.setItemWithExpiryNX(nameLockKey, 60, "1");if (!nameLockClaimed) {@@ -388,8 +404,6 @@ export const gitHubAppServiceFactory = ({let manifestResponse: TGitHubAppManifestResponse;try {const resolvedApiHost = githubHost ? `https://${githubHost}/api/v3` : "https://api.github.com";- // safeRequest validates + DNS-pins the target and disables redirects, so a public host- // cannot redirect this exchange to an internal service (SSRF).const { data } = await safeRequest.post<TGitHubAppManifestResponse>(`${resolvedApiHost}/app-manifests/${encodeURIComponent(code)}/conversions`,{},@@ -425,18 +439,10 @@ export const gitHubAppServiceFactory = ({encryptedPrivateKey: encryptor({ plainText: Buffer.from(manifestResponse.pem) }).cipherTextBlob,slug: manifestResponse.slug,owner,- // Bind the app to the host/instance it was registered against. Every later credential- // operation derives its target host from these stored values rather than from a- // caller-supplied host, so a signed app JWT or the client secret can never be sent to an- // arbitrary host an attacker controls.host: githubHost || null,instanceType});} catch (err) {- // The conversion above already created a real app on GitHub, and GitHub has no API to- // delete an app — only the web UI can. Any failure past this point therefore strands a- // live app whose private key Infisical never stored. Log it and point the user at it so- // it can be removed manually.logger.error({ err, orgId, appId: manifestResponse.id, slug: manifestResponse.slug },`Failed to store GitHub App after manifest conversion; the app must be deleted manually on GitHub [orgId=${orgId}] [appId=${manifestResponse.id}] [slug=${manifestResponse.slug}] [url=${manifestResponse.html_url}]`@@ -452,8 +458,6 @@ export const gitHubAppServiceFactory = ({throw err;}} finally {- // Best-effort release: on success the inserted row enforces uniqueness from here on, and on- // failure an immediate retry should not be blocked for the rest of the lock's TTL.await keyStore.deleteItem(nameLockKey).catch(() => {});}