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
do not assume instalation id
Thiago Araujo da Silva7df3278df5e9
diff --git a/backend/src/services/app-connection/github/github-connection-fns.ts b/backend/src/services/app-connection/github/github-connection-fns.tsindex ba52424ac1..b61d4aa415 100644--- a/backend/src/services/app-connection/github/github-connection-fns.ts+++ b/backend/src/services/app-connection/github/github-connection-fns.ts@@ -816,37 +816,19 @@ export const validateGitHubConnectionCredentials = async (// installations are scoped to this GitHub App since the token is a user-to-server tokenconst { installations } = installationsResp.data;- if (credentials.installationId) {- const { installationId } = credentials;- const matchingInstallation = installations.find((installation) => installation.id === +installationId);-- if (!matchingInstallation) {- throw new ForbiddenRequestError({- message: "User does not have access to the provided installation"- });- }-- resolvedInstallationId = credentials.installationId;- } else {- // already-installed app flow: GitHub doesn't redirect back through the install page, so the- // user only re-authorized via OAuth and the installation must be resolved from their access- if (installations.length === 0) {- throw new BadRequestError({- message:- "The GitHub App has no installations accessible to your GitHub account. Install the app on a GitHub account or organization you have access to, then try again."- });- }-- if (installations.length > 1) {- throw new BadRequestError({- message: `The GitHub App is installed on multiple GitHub accounts accessible to you (${installations- .map((installation) => installation.account.login)- .join(", ")}). Unable to determine which installation to use.`- });- }-- resolvedInstallationId = String(installations[0].id);+ // The installation is selected through GitHub's own install UI and returned to us as an explicit+ // installationId (required) — never auto-resolved from the user's accessible installations, so we+ // can't bind to an account the user merely belongs to rather than one they intended.+ const { installationId } = credentials;+ const matchingInstallation = installations.find((installation) => installation.id === +installationId);++ if (!matchingInstallation) {+ throw new ForbiddenRequestError({+ message: "User does not have access to the provided installation"+ });}++ resolvedInstallationId = installationId;}switch (method) {diff --git a/backend/src/services/app-connection/github/github-connection-schemas.ts b/backend/src/services/app-connection/github/github-connection-schemas.tsindex 1528845af3..de1150a72b 100644--- a/backend/src/services/app-connection/github/github-connection-schemas.ts+++ b/backend/src/services/app-connection/github/github-connection-schemas.ts@@ -27,16 +27,14 @@ export const GitHubConnectionOAuthInputCredentialsSchema = z.union([export const GitHubConnectionAppInputCredentialsSchema = z.union([z.object({code: z.string().trim().min(1, "GitHub App code required"),- // optional: when omitted (already-installed app flow) the installation is resolved from the- // installations accessible to the authorizing user- installationId: z.string().min(1, "GitHub App Installation ID required").optional(),+ installationId: z.string().min(1, "GitHub App Installation ID required"),gitHubAppId: z.string().uuid().nullish(),instanceType: z.literal("server"),host: z.string().trim().min(1, "Host is required for server instance type")}),z.object({code: z.string().trim().min(1, "GitHub App code required"),- installationId: z.string().min(1, "GitHub App Installation ID required").optional(),+ installationId: z.string().min(1, "GitHub App Installation ID required"),gitHubAppId: z.string().uuid().nullish(),instanceType: z.literal("cloud").optional(),host: z.string().trim().optional()diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsxindex 71dee468ba..6f913ca504 100644--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/GitHubConnectionForm.tsx@@ -38,11 +38,7 @@ import {useGetAppConnectionOption} from "@app/hooks/api/appConnections";import { AppConnection } from "@app/hooks/api/appConnections/enums";-import {- fetchGitHubAppInstallationStatus,- TGitHubApp,- useListGitHubApps-} from "@app/hooks/api/gitHubApps";+import { TGitHubApp, useListGitHubApps } from "@app/hooks/api/gitHubApps";import { GitHubFormData } from "../../../OauthCallbackPage/OauthCallbackPage.types";import {@@ -320,29 +316,9 @@ export const GitHubConnectionForm = ({ appConnection, projectId, onSubmit }: Pro// to the instance-default app on the backend.storeConnectionFormData(formData, installState, targetApp?.id ?? undefined);- // GitHub never redirects back from the install page when the app is already installed, so- // installed apps go through the OAuth authorize flow instead — the user re-authorizes- // (auto-approved if previously authorized) and the backend resolves the installation.- // Skipped for the shared app on Infisical Cloud, where installations from unrelated orgs- // make the check meaningless.- if (targetApp?.id || !isInfisicalCloud()) {- try {- const { installed, clientId } = await fetchGitHubAppInstallationStatus({- gitHubAppId: targetApp?.id ?? undefined- });-- if (installed) {- window.location.assign(- `${githubHost}/login/oauth/authorize?client_id=${clientId}&state=${installState}&redirect_uri=${window.location.origin}/organization/app-connections/github/oauth/callback`- );- break;- }- } catch {- // fall through to the install flow — first-time installs must keep working even if- // the status check is unavailable- }- }-+ // Always route through GitHub's install flow so the user explicitly selects the target+ // account; GitHub redirects back with the chosen installation_id, which the backend binds+ // directly (no server-side guessing of which installation to use).window.location.assign(`${githubHost}/${formData.credentials?.instanceType === "server" ? "github-apps" : "apps"}/${slug}/installations/new?state=${installState}`);diff --git a/frontend/src/pages/organization/AppConnections/OauthCallbackPage/OauthCallbackPage.tsx b/frontend/src/pages/organization/AppConnections/OauthCallbackPage/OauthCallbackPage.tsxindex b97de1342a..8f24ade7d1 100644--- a/frontend/src/pages/organization/AppConnections/OauthCallbackPage/OauthCallbackPage.tsx+++ b/frontend/src/pages/organization/AppConnections/OauthCallbackPage/OauthCallbackPage.tsx@@ -365,10 +365,9 @@ export const OAuthCallbackPage = () => {try {const gitHubAppId = (credentials as { gitHubAppId?: string | null } | undefined)?.gitHubAppId;- // Fresh installs return from GitHub with an installation_id. Already-installed apps come- // back through the OAuth authorize flow without one — the stored method tells us it's still- // an App connection (the backend resolves the installation from the user's access).- const isAppMethod = formData.method === GitHubConnectionMethod.App || Boolean(installationId);+ // App connections always route through GitHub's install flow, which returns an installation_id;+ // its presence is what distinguishes an App callback from an OAuth callback.+ const isAppMethod = Boolean(installationId);const appCredentials = {code: code as string,