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 exfiltration
Thiago Araujo da Silva4516fb8d3abf
diff --git a/backend/src/db/migrations/20260529204743_create-github-apps.ts b/backend/src/db/migrations/20260529204743_create-github-apps.tsindex 098ddd8fc0..ce018c8b70 100644--- a/backend/src/db/migrations/20260529204743_create-github-apps.ts+++ b/backend/src/db/migrations/20260529204743_create-github-apps.ts@@ -16,6 +16,11 @@ export async function up(knex: Knex): Promise<void> {t.binary("encryptedPrivateKey").notNullable();t.string("slug").notNullable();t.string("owner").nullable();+ // Host + instance type the app was registered against. These are bound to the app so that+ // credential operations (signing app JWTs, using the client secret) always target the host+ // the app belongs to, never a host supplied by the caller at request time.+ t.string("host").nullable();+ t.string("instanceType").notNullable().defaultTo("cloud");t.timestamps(true, true, true);t.unique(["orgId", "name"]);});diff --git a/backend/src/db/schemas/github-apps.ts b/backend/src/db/schemas/github-apps.tsindex c6c8e2c1a9..82616f6463 100644--- a/backend/src/db/schemas/github-apps.ts+++ b/backend/src/db/schemas/github-apps.ts@@ -19,6 +19,8 @@ export const GithubAppsSchema = z.object({encryptedPrivateKey: zodBuffer,slug: z.string(),owner: z.string().nullable().optional(),+ host: z.string().nullable().optional(),+ instanceType: z.string().default("cloud"),createdAt: z.date(),updatedAt: z.date()});diff --git a/backend/src/services/app-connection/github/github-connection-fns.ts b/backend/src/services/app-connection/github/github-connection-fns.tsindex 6d4f986b14..b367a980ef 100644--- a/backend/src/services/app-connection/github/github-connection-fns.ts+++ b/backend/src/services/app-connection/github/github-connection-fns.ts@@ -34,6 +34,11 @@ type TResolvedGitHubAppCredentials = {clientId: string;clientSecret: string;privateKey: string;+ // Host/instance the app is bound to. Populated for org-managed apps (resolved by id) so callers+ // can target the app's own host instead of a caller-supplied one. Null for the instance-default+ // app configured via env vars, where callers fall back to their own host handling.+ host: string | null;+ instanceType: "cloud" | "server" | null;};export const resolveGitHubAppCredentials = async (@@ -64,7 +69,9 @@ export const resolveGitHubAppCredentials = async (slug: app.slug,clientId: app.clientId,clientSecret: decryptor({ cipherTextBlob: app.encryptedClientSecret }).toString(),- privateKey: decryptor({ cipherTextBlob: app.encryptedPrivateKey }).toString()+ privateKey: decryptor({ cipherTextBlob: app.encryptedPrivateKey }).toString(),+ host: app.host ?? null,+ instanceType: (app.instanceType as "cloud" | "server" | undefined) ?? "cloud"};}@@ -93,7 +100,10 @@ export const resolveGitHubAppCredentials = async (slug: INF_APP_CONNECTION_GITHUB_APP_SLUG,clientId: INF_APP_CONNECTION_GITHUB_APP_CLIENT_ID,clientSecret: INF_APP_CONNECTION_GITHUB_APP_CLIENT_SECRET,- privateKey: INF_APP_CONNECTION_GITHUB_APP_PRIVATE_KEY+ privateKey: INF_APP_CONNECTION_GITHUB_APP_PRIVATE_KEY,+ // The instance-default app isn't host-bound here; callers keep their existing host handling.+ host: null,+ instanceType: null};};@@ -276,11 +286,23 @@ export const uninstallGitHubAppInstallation = async (throw new InternalServerError({ message: "Cannot uninstall a non-app GitHub connection" });}- const { appId, privateKey } = await resolveGitHubAppCredentials(+ const {+ appId,+ privateKey,+ host: appHost,+ instanceType: appInstanceType+ } = await resolveGitHubAppCredentials({ gitHubAppId: appConnection.credentials.gitHubAppId, orgId: appConnection.orgId },deps);+ // Bind the signed app JWT to the app's own host, never the host recorded on the connection.+ const effectiveCredentials = appConnection.credentials.gitHubAppId+ ? { host: appHost ?? undefined, instanceType: appInstanceType ?? "cloud" }+ : { host: appConnection.credentials.host, instanceType: appConnection.credentials.instanceType };++ assertPlatformGitHubHostAllowed(effectiveCredentials.host);+const appPrivateKey = privateKey.split("\n").map((line) => line.trim())@@ -291,7 +313,7 @@ export const uninstallGitHubAppInstallation = async (algorithm: "RS256"});- const apiBaseUrl = await getGitHubInstanceApiUrl(appConnection);+ const apiBaseUrl = await getGitHubInstanceApiUrl({ credentials: effectiveCredentials });const { installationId } = appConnection.credentials;const effectiveGatewayId = await gatewayPoolService.resolveEffectiveGatewayId({@@ -344,13 +366,24 @@ export const getGitHubAppAuthToken = async (throw new InternalServerError({ message: "Cannot generate GitHub App token for non-app connection" });}- assertPlatformGitHubHostAllowed(appConnection.credentials.host);-- const { appId, privateKey } = await resolveGitHubAppCredentials(+ const {+ appId,+ privateKey,+ host: appHost,+ instanceType: appInstanceType+ } = await resolveGitHubAppCredentials({ gitHubAppId: appConnection.credentials.gitHubAppId, orgId: appConnection.orgId },deps);+ // For an org-managed app, target the host the app is bound to rather than the host stored on the+ // connection — the signed app JWT must never leave for a host that isn't the app's own.+ const effectiveCredentials = appConnection.credentials.gitHubAppId+ ? { host: appHost ?? undefined, instanceType: appInstanceType ?? "cloud" }+ : { host: appConnection.credentials.host, instanceType: appConnection.credentials.instanceType };++ assertPlatformGitHubHostAllowed(effectiveCredentials.host);+const appPrivateKey = privateKey.split("\n").map((line) => line.trim())@@ -365,7 +398,7 @@ export const getGitHubAppAuthToken = async (const appJwt = crypto.jwt().sign(payload, appPrivateKey, { algorithm: "RS256" });- const apiBaseUrl = await getGitHubInstanceApiUrl(appConnection);+ const apiBaseUrl = await getGitHubInstanceApiUrl({ credentials: effectiveCredentials });const { installationId } = appConnection.credentials;const effectiveGatewayId = await gatewayPoolService.resolveEffectiveGatewayId({@@ -697,6 +730,24 @@ export const validateGitHubConnectionCredentials = async () => {const { credentials, method } = config;+ // For org-managed GitHub App connections, bind the connection to the host/instance the app was+ // registered against BEFORE any credential is used or any request host is derived. Without this,+ // a user could create an app-method connection that references an existing app but supplies a+ // custom host they control, causing the app's client secret / signed JWT to be sent there.+ let resolvedAppCredentials: TResolvedGitHubAppCredentials | undefined;+ if (method === GitHubConnectionMethod.App) {+ resolvedAppCredentials = await resolveGitHubAppCredentials(+ { gitHubAppId: credentials.gitHubAppId, orgId: config.orgId },+ deps+ );++ if (credentials.gitHubAppId) {+ const mutableCredentials = credentials as { host?: string; instanceType: "cloud" | "server" };+ mutableCredentials.host = resolvedAppCredentials.host ?? undefined;+ mutableCredentials.instanceType = resolvedAppCredentials.instanceType ?? "cloud";+ }+ }+const apiBaseUrl = await getGitHubInstanceApiUrl(config);const gatewayConnectionDetails = config.gatewayId? await getGitHubGatewayConnectionDetails(config.gatewayId, apiBaseUrl, gatewayV2Service)@@ -744,12 +795,9 @@ export const validateGitHubConnectionCredentials = async (let clientSecret: string | undefined;if (method === GitHubConnectionMethod.App) {- const resolved = await resolveGitHubAppCredentials(- { gitHubAppId: credentials.gitHubAppId, orgId: config.orgId },- deps- );- clientId = resolved.clientId;- clientSecret = resolved.clientSecret;+ // Resolved above so the host could be bound before any credential use.+ clientId = resolvedAppCredentials!.clientId;+ clientSecret = resolvedAppCredentials!.clientSecret;} else {clientId = INF_APP_CONNECTION_GITHUB_OAUTH_CLIENT_ID;clientSecret = INF_APP_CONNECTION_GITHUB_OAUTH_CLIENT_SECRET;diff --git a/backend/src/services/github-app/github-app-service.ts b/backend/src/services/github-app/github-app-service.tsindex 6a59dc4459..190f27c4e2 100644--- a/backend/src/services/github-app/github-app-service.ts+++ b/backend/src/services/github-app/github-app-service.ts@@ -5,12 +5,11 @@ import { OrganizationActionScope } from "@app/db/schemas";import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";import { getConfig } from "@app/lib/config/env";-import { request } from "@app/lib/config/request";import { crypto } from "@app/lib/crypto";import { DatabaseErrorCode } from "@app/lib/error-codes";import { BadRequestError, DatabaseError, NotFoundError } from "@app/lib/errors";import { logger } from "@app/lib/logger";-import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";+import { safeRequest } from "@app/lib/validator/safe-request";import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";import {assertPlatformGitHubHostAllowed,@@ -262,14 +261,12 @@ export const gitHubAppServiceFactory = ({assertPlatformGitHubHostAllowed(githubHost);- if (githubHost) {- await blockLocalAndPrivateIpAddresses(`https://${githubHost}`);- }-let manifestResponse: TGitHubAppManifestResponse;try {const resolvedApiHost = githubHost ? `https://${githubHost}/api/v3` : "https://api.github.com";- const { data } = await request.post<TGitHubAppManifestResponse>(+ // 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`,{},{@@ -304,7 +301,13 @@ export const gitHubAppServiceFactory = ({encryptedClientSecret: encryptor({ plainText: Buffer.from(manifestResponse.client_secret) }).cipherTextBlob,encryptedPrivateKey: encryptor({ plainText: Buffer.from(manifestResponse.pem) }).cipherTextBlob,slug: manifestResponse.slug,- owner+ 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) {if (err instanceof DatabaseError && (err.error as { code: string })?.code === DatabaseErrorCode.UniqueViolation) {@@ -348,15 +351,29 @@ export const gitHubAppServiceFactory = ({ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Read, OrgPermissionSubjects.Settings);- assertPlatformGitHubHostAllowed(host);-- const { appId, clientId, privateKey } = await resolveGitHubAppCredentials(+ const {+ appId,+ clientId,+ privateKey,+ host: appHost,+ instanceType: appInstanceType+ } = await resolveGitHubAppCredentials({ gitHubAppId: gitHubAppId ?? null, orgId: orgPermission.orgId },{ gitHubAppDAL, kmsService });+ // For an org-managed app, the request only identifies which app to use — its host/instance are+ // bound to the stored app record. Ignoring the caller-supplied host here is what prevents a+ // settings reader from pointing the app's signed JWT at a host they control to exfiltrate it.+ const effectiveHost = gitHubAppId ? (appHost ?? undefined) : host;+ const effectiveInstanceType = gitHubAppId ? (appInstanceType ?? "cloud") : instanceType;++ assertPlatformGitHubHostAllowed(effectiveHost);+// validates the host against local/private addresses internally- const apiBaseUrl = await getGitHubInstanceApiUrl({ credentials: { host, instanceType } });+ const apiBaseUrl = await getGitHubInstanceApiUrl({+ credentials: { host: effectiveHost, instanceType: effectiveInstanceType }+ });const appPrivateKey = privateKey.split("\n")@@ -369,7 +386,9 @@ export const gitHubAppServiceFactory = ({});try {- const { data } = await request.get<{ id: number }[]>(`https://${apiBaseUrl}/app/installations`, {+ // safeRequest validates + DNS-pins the target and disables redirects, so a public host+ // cannot redirect this request to an internal service (SSRF).+ const { data } = await safeRequest.get<{ id: number }[]>(`https://${apiBaseUrl}/app/installations`, {params: { per_page: 1 },headers: {Accept: "application/vnd.github+json",