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
improvement: address feedback
Scott Wilson330900cc2855
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.tsindex 7bab9202b0..41b6110630 100644--- a/backend/src/ee/services/audit-log/audit-log-types.ts+++ b/backend/src/ee/services/audit-log/audit-log-types.ts@@ -2214,6 +2214,7 @@ interface AddIdentityOidcAuthEvent {metadata: {identityId: string;templateId?: string | null;+ templateName?: string;oidcDiscoveryUrl: string;caCert: string;boundIssuer: string;diff --git a/backend/src/ee/services/identity-auth-template/identity-auth-template-enums.ts b/backend/src/ee/services/identity-auth-template/identity-auth-template-enums.tsindex 322f8fd52a..a155552520 100644--- a/backend/src/ee/services/identity-auth-template/identity-auth-template-enums.ts+++ b/backend/src/ee/services/identity-auth-template/identity-auth-template-enums.ts@@ -28,6 +28,8 @@ export const TEMPLATE_VALIDATION_MESSAGES = {DISCOVERY_URL_REQUIRED: "OIDC discovery URL is required",DISCOVERY_URL_WELL_KNOWN_SUFFIX:"Remove the /.well-known/openid-configuration suffix from the OIDC discovery URL. Infisical appends it automatically.",+ DISCOVERY_URL_QUERY_OR_FRAGMENT:+ "Remove the query string or fragment from the OIDC discovery URL. Infisical appends /.well-known/openid-configuration to it, which would land inside them.",ISSUER_REQUIRED: "Issuer is required"}} as const;diff --git a/backend/src/ee/services/identity-auth-template/identity-auth-template-schemas.test.ts b/backend/src/ee/services/identity-auth-template/identity-auth-template-schemas.test.tsnew file mode 100644index 0000000000..7c37a82b54--- /dev/null+++ b/backend/src/ee/services/identity-auth-template/identity-auth-template-schemas.test.ts@@ -0,0 +1,52 @@+import { describe, expect, it, vi } from "vitest";++import { oidcTemplateFieldsSchema } from "./identity-auth-template-schemas";++vi.mock("@app/lib/config/env", () => ({+ getConfig: () => ({ isDevelopmentMode: false, ALLOW_INTERNAL_IP_CONNECTIONS: false })+}));++const parseDiscoveryUrl = (oidcDiscoveryUrl: string) =>+ oidcTemplateFieldsSchema.safeParse({+ oidcDiscoveryUrl,+ boundIssuer: "https://issuer.example.com",+ boundAudiences: "https://github.com/acme"+ });++// the login flow builds the document URL by concatenation, so whatever a template stores+// has to survive having "/.well-known/openid-configuration" appended to it+describe("oidcTemplateFieldsSchema discovery URL", () => {+ it("strips trailing slashes so the appended suffix cannot double up the separator", () => {+ const result = parseDiscoveryUrl("https://idp.example.com/realms/acme//");++ expect(result.success).toBe(true);+ expect(result.success && result.data.oidcDiscoveryUrl).toBe("https://idp.example.com/realms/acme");+ });++ it.each([+ ["https://idp.example.com/.well-known/openid-configuration"],+ ["https://idp.example.com/.well-known/openid-configuration/"]+ ])("rejects an already-suffixed URL: %s", (url) => {+ const result = parseDiscoveryUrl(url);++ expect(result.success).toBe(false);+ expect(result.success === false && result.error.issues[0].message).toContain("Infisical appends it automatically");+ });++ it.each([["https://idp.example.com?tenant=acme"], ["https://idp.example.com#acme"]])(+ "rejects a URL whose suffix would land inside a query or fragment: %s",+ (url) => {+ const result = parseDiscoveryUrl(url);++ expect(result.success).toBe(false);+ expect(result.success === false && result.error.issues[0].message).toContain("query string or fragment");+ }+ );++ it("accepts a plain issuer base unchanged", () => {+ const result = parseDiscoveryUrl("https://idp.example.com/realms/acme");++ expect(result.success).toBe(true);+ expect(result.success && result.data.oidcDiscoveryUrl).toBe("https://idp.example.com/realms/acme");+ });+});diff --git a/backend/src/ee/services/identity-auth-template/identity-auth-template-schemas.ts b/backend/src/ee/services/identity-auth-template/identity-auth-template-schemas.tsindex 1ab4d0fe57..a2e91cecf3 100644--- a/backend/src/ee/services/identity-auth-template/identity-auth-template-schemas.ts+++ b/backend/src/ee/services/identity-auth-template/identity-auth-template-schemas.ts@@ -70,10 +70,20 @@ export const oidcTemplateFieldsSchema = z.object({.url().min(1, TEMPLATE_VALIDATION_MESSAGES.OIDC.DISCOVERY_URL_REQUIRED).max(2048)- // the login flow appends the suffix itself, so a URL stored with it would fetch- // <url>/.well-known/openid-configuration/.well-known/openid-configuration and fail- // at every login; the identity attach route predates this check, but a template is- // authored once and copied everywhere, so it must not store the broken form+ // the login flow builds the document URL by string concatenation, so anything that+ // cannot carry a trailing path segment breaks every login: a query or fragment would+ // swallow the suffix (<url>?a=b/.well-known/openid-configuration). The identity attach+ // route predates these checks, but a template is authored once and copied everywhere,+ // so it must not store a form that cannot work+ .refine((val) => {+ const parsed = new URL(val);+ return !parsed.search && !parsed.hash;+ }, TEMPLATE_VALIDATION_MESSAGES.OIDC.DISCOVERY_URL_QUERY_OR_FRAGMENT)+ // a trailing slash concatenates to a double slash, which providers that route on the+ // exact path (Keycloak realms, for one) 404. Normalized rather than rejected: pasting+ // a URL with one is not a mistake worth failing the form over+ .transform((val) => val.replace(/\/+$/, ""))+ // checked after the strip so the trailing-slash spelling is caught too.refine((val) => !val.endsWith("/.well-known/openid-configuration"),TEMPLATE_VALIDATION_MESSAGES.OIDC.DISCOVERY_URL_WELL_KNOWN_SUFFIX@@ -122,9 +132,13 @@ export const kubernetesTemplateFieldsResponseSchema = kubernetesTemplateFieldsBahasTokenReviewerJwt: z.boolean().describe("Whether a token reviewer JWT is stored for this template")});-// OIDC templates hold no write-only credentials, so the response is the stored shape;-// audiences are re-declared as a plain string so the response schema carries no transform+// OIDC templates hold no write-only credentials, so the response is the stored shape.+// The two normalized fields are re-declared as plain strings so no request-side transform+// or refinement runs on serialization and one stored row cannot fail a list responseexport const oidcTemplateFieldsResponseSchema = oidcTemplateFieldsSchema.extend({+ oidcDiscoveryUrl: z+ .string()+ .describe("The URL used to retrieve the OpenID Connect configuration from the identity provider"),boundAudiences: z.string().default("")diff --git a/backend/src/ee/services/identity-auth-template/identity-auth-template-service.test.ts b/backend/src/ee/services/identity-auth-template/identity-auth-template-service.test.tsindex c3c672b621..9017d3efa4 100644--- a/backend/src/ee/services/identity-auth-template/identity-auth-template-service.test.ts+++ b/backend/src/ee/services/identity-auth-template/identity-auth-template-service.test.ts@@ -1,6 +1,7 @@import { createMongoAbility } from "@casl/ability";import { beforeEach, describe, expect, it, vi } from "vitest";+import { BadRequestError } from "@app/lib/errors";import { IdentityKubernetesAuthTokenReviewMode } from "@app/services/identity-kubernetes-auth/identity-kubernetes-auth-types";import { IdentityAuthTemplateMethod } from "./identity-auth-template-enums";@@ -10,6 +11,16 @@ vi.mock("@app/lib/config/env", () => ({getConfig: () => ({ isDevelopmentMode: false, ALLOW_INTERNAL_IP_CONNECTIONS: false })}));+// every other host in the suite is a literal IP, which skips resolution entirely, so a+// blanket rejection only ever fires for the unresolvable case below+vi.mock("node:dns/promises", () => ({+ default: {+ lookup: vi.fn(() =>+ Promise.reject(Object.assign(new Error("getaddrinfo ENOTFOUND idp.invalid"), { code: "ENOTFOUND" }))+ )+ }+}));+const ORG_ID = "org-id";const TEMPLATE_ID = "template-id";const GATEWAY_ID = "gateway-id";@@ -317,6 +328,20 @@ describe("identityAuthTemplateServiceFactory oidc templates", () => {expect(identityOidcAuthDAL.updateByTemplateId).not.toHaveBeenCalled();});+ it("reports an unresolvable discovery host as a client error rather than a 500", async () => {+ const { service, identityOidcAuthDAL } = createOidcService();++ const error = await patchTemplate(service, { oidcDiscoveryUrl: "https://idp.invalid" }).catch(+ (err: unknown) => err+ );++ expect(error).toBeInstanceOf(BadRequestError);+ expect((error as BadRequestError).message).toContain(+ "Could not resolve the host of the OIDC discovery URL 'https://idp.invalid'"+ );+ expect(identityOidcAuthDAL.updateByTemplateId).not.toHaveBeenCalled();+ });+it("audits the propagation as an OIDC auth update", async () => {const { service, auditLogCreate } = createOidcService();diff --git a/backend/src/ee/services/identity-auth-template/identity-auth-template-service.ts b/backend/src/ee/services/identity-auth-template/identity-auth-template-service.tsindex ef52c49a32..64a97139ee 100644--- a/backend/src/ee/services/identity-auth-template/identity-auth-template-service.ts+++ b/backend/src/ee/services/identity-auth-template/identity-auth-template-service.ts@@ -106,6 +106,19 @@ export const identityAuthTemplateServiceFactory = ({return { ...template, templateFields: redacted } as TSanitizedIdentityAuthTemplate;};+ // blockLocalAndPrivateIpAddresses lets a DNS failure escape as-is, so a typo'd or+ // not-yet-published discovery host would 500 instead of telling the author what to fix+ const $validateOidcDiscoveryHost = async (oidcDiscoveryUrl: string) => {+ try {+ await blockLocalAndPrivateIpAddresses(oidcDiscoveryUrl);+ } catch (error) {+ if (error instanceof BadRequestError) throw error;+ throw new BadRequestError({+ message: `Could not resolve the host of the OIDC discovery URL '${oidcDiscoveryUrl}'. Check the URL and that the host resolves from Infisical.`+ });+ }+ };+// audit the platform-driven rewrite of linked identities; runs after the propagation// transaction commits so the tx never waits on Redis, chunked to bound concurrencyconst $templatePropagationEvent = (@@ -346,7 +359,7 @@ export const identityAuthTemplateServiceFactory = ({if (authMethod === IdentityAuthTemplateMethod.OIDC) {// parity with the identity attach flow: a template-authored discovery URL must not// let the backend dial local or private addresses- await blockLocalAndPrivateIpAddresses((templateFields as TOidcTemplateFields).oidcDiscoveryUrl);+ await $validateOidcDiscoveryHost((templateFields as TOidcTemplateFields).oidcDiscoveryUrl);}const { encryptor } = await kmsService.createCipherPairWithDataKey({@@ -512,7 +525,7 @@ export const identityAuthTemplateServiceFactory = ({// every propagation rather than only when the patch touches it (login re-validates// before dialing, but the template must never store a URL its author could not// have set directly)- await blockLocalAndPrivateIpAddresses(merged.oidcDiscoveryUrl);+ await $validateOidcDiscoveryHost(merged.oidcDiscoveryUrl);oidcPropagationData = {oidcDiscoveryUrl: merged.oidcDiscoveryUrl,boundIssuer: merged.boundIssuer,diff --git a/backend/src/server/routes/v1/identity-oidc-auth-router.ts b/backend/src/server/routes/v1/identity-oidc-auth-router.tsindex 9c79390008..8b13babe48 100644--- a/backend/src/server/routes/v1/identity-oidc-auth-router.ts+++ b/backend/src/server/routes/v1/identity-oidc-auth-router.ts@@ -270,6 +270,7 @@ export const registerIdentityOidcAuthRouter = async (server: FastifyZodProvider)metadata: {identityId: identityOidcAuth.identityId,templateId: identityOidcAuth.templateId,+ templateName: identityOidcAuth.templateName,oidcDiscoveryUrl: identityOidcAuth.oidcDiscoveryUrl,caCert: identityOidcAuth.caCert,boundIssuer: identityOidcAuth.boundIssuer,@@ -400,6 +401,7 @@ export const registerIdentityOidcAuthRouter = async (server: FastifyZodProvider)metadata: {identityId: identityOidcAuth.identityId,templateId: identityOidcAuth.templateId,+ templateName: identityOidcAuth.templateName,oidcDiscoveryUrl: identityOidcAuth.oidcDiscoveryUrl,caCert: identityOidcAuth.caCert,boundIssuer: identityOidcAuth.boundIssuer,diff --git a/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts b/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.tsindex 90628cb8c3..1dd60c3141 100644--- a/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts+++ b/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts@@ -770,7 +770,12 @@ export const identityOidcAuthServiceFactory = ({return doc;});await identityAccessTokenService.invalidateTrustedIpsCache(identityId, IdentityAuthMethod.OIDC_AUTH);- return { ...identityOidcAuth, orgId: identityMembershipOrg.scopeOrgId, caCert: resolvedCaCert };+ return {+ ...identityOidcAuth,+ orgId: identityMembershipOrg.scopeOrgId,+ caCert: resolvedCaCert,+ templateName: template?.name+ };};const updateOidcAuth = async (dto: TUpdateOidcAuthDTO) => {@@ -972,11 +977,19 @@ export const identityOidcAuthServiceFactory = ({? decryptor({ cipherTextBlob: updatedOidcAuth.encryptedCaCertificate }).toString(): "";+ // a re-asserted or untouched link skips the load above, so resolve the name the audit+ // log needs rather than leaving the reader with a bare uuid+ const linkedTemplate =+ updatedOidcAuth.templateId && template?.id !== updatedOidcAuth.templateId+ ? await identityAuthTemplateDAL.findByIdAndOrgId(updatedOidcAuth.templateId, identityMembershipOrg.scopeOrgId)+ : template;+await identityAccessTokenService.invalidateTrustedIpsCache(identityId, IdentityAuthMethod.OIDC_AUTH);return {...updatedOidcAuth,orgId: identityMembershipOrg.scopeOrgId,- caCert: updatedCACert+ caCert: updatedCACert,+ templateName: updatedOidcAuth.templateId ? linkedTemplate?.name : undefined};};diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAuthTemplateModal.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAuthTemplateModal.tsxindex 25b00a2b04..1ca25ee396 100644--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAuthTemplateModal.tsx+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAuthTemplateModal.tsx@@ -125,8 +125,21 @@ const schema = zcode: z.ZodIssueCode.custom,message: "OIDC discovery URL must be a valid URL"});+ } else {+ const { search, hash } = new URL(data.oidcDiscoveryUrl);+ if (search || hash) {+ ctx.addIssue({+ path: ["oidcDiscoveryUrl"],+ code: z.ZodIssueCode.custom,+ message: "Please remove the query string or fragment."+ });+ }}- if (data.oidcDiscoveryUrl.endsWith("/.well-known/openid-configuration")) {+ // the server strips trailing slashes before it checks, so match it or the two+ // disagree on ".../.well-known/openid-configuration/"+ if (+ data.oidcDiscoveryUrl.replace(/\/+$/, "").endsWith("/.well-known/openid-configuration")+ ) {ctx.addIssue({path: ["oidcDiscoveryUrl"],code: z.ZodIssueCode.custom,