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
cors check
x032205f302d94d92ee
diff --git a/backend/src/ee/routes/v1/pam-recording-config-router.ts b/backend/src/ee/routes/v1/pam-recording-config-router.tsindex 842f9fe74d..fcddbb4f5b 100644--- a/backend/src/ee/routes/v1/pam-recording-config-router.ts+++ b/backend/src/ee/routes/v1/pam-recording-config-router.ts@@ -71,14 +71,15 @@ export const registerPamRecordingConfigRouter = async (server: FastifyZodProvideparams: z.object({ projectId: z.string().uuid() }),body: UpsertBodySchema,response: {- 200: z.object({ config: SanitizedConfigSchema })+ 200: z.object({ config: SanitizedConfigSchema, corsProbeUrl: z.string().nullable() })}},onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),handler: async (req) => {let config;+ let corsProbeUrl: string | null = null;try {- ({ config } = await server.services.pamProjectRecordingConfig.upsertConfig(+ ({ config, corsProbeUrl } = await server.services.pamProjectRecordingConfig.upsertConfig({ projectId: req.params.projectId, ...req.body },req.permission));@@ -116,7 +117,7 @@ export const registerPamRecordingConfigRouter = async (server: FastifyZodProvide}});- return { config };+ return { config, corsProbeUrl };}});diff --git a/backend/src/ee/services/pam-project-recording-config/pam-project-recording-config-service.ts b/backend/src/ee/services/pam-project-recording-config/pam-project-recording-config-service.tsindex d6d7f919fa..486d5a85ae 100644--- a/backend/src/ee/services/pam-project-recording-config/pam-project-recording-config-service.ts+++ b/backend/src/ee/services/pam-project-recording-config/pam-project-recording-config-service.ts@@ -15,7 +15,10 @@ import { TKmsServiceFactory } from "@app/services/kms/kms-service";import { PamRecordingStorageBackend } from "../pam-session-recording-storage/pam-session-recording-storage-enums";import { PAM_RECORDING_STORAGE_FACTORY_MAP } from "../pam-session-recording-storage/pam-session-recording-storage-factory";-import { TPamRecordingResolvedConfig } from "../pam-session-recording-storage/pam-session-recording-storage-types";+import {+ normalizeKeyPrefix,+ TPamRecordingResolvedConfig+} from "../pam-session-recording-storage/pam-session-recording-storage-types";import { TPamProjectRecordingConfigDALFactory } from "./pam-project-recording-config-dal";import {TDeletePamRecordingConfigDTO,@@ -112,44 +115,57 @@ export const pamProjectRecordingConfigServiceFactory = ({input.region as never);+ const resolvedConfig: TPamRecordingResolvedConfig = {+ backend: PamRecordingStorageBackend.AwsS3,+ bucket: input.bucket,+ region: input.region,+ keyPrefix: input.keyPrefix ?? null,+ awsCredentials: awsConfig.credentials+ };+const provider = PAM_RECORDING_STORAGE_FACTORY_MAP[input.storageBackend]();- await provider.validateConfig({- config: {- backend: PamRecordingStorageBackend.AwsS3,- bucket: input.bucket,- region: input.region,- keyPrefix: input.keyPrefix ?? null,- awsCredentials: awsConfig.credentials- }- });+ await provider.validateConfig({ config: resolvedConfig });- return { ok: true as const };+ return { ok: true as const, resolvedConfig };};const upsertConfig = async (input: TUpsertPamRecordingConfigDTO, actor: OrgServiceActor) => {- await testConfig(input, actor);+ const { resolvedConfig } = await testConfig(input, actor);const existing = await pamProjectRecordingConfigDAL.findByProjectId(input.projectId);+ let config;if (existing) {- const updated = await pamProjectRecordingConfigDAL.updateById(existing.id, {+ config = await pamProjectRecordingConfigDAL.updateById(existing.id, {+ storageBackend: input.storageBackend,+ connectionId: input.connectionId,+ bucket: input.bucket,+ region: input.region,+ keyPrefix: input.keyPrefix ?? null+ });+ } else {+ config = await pamProjectRecordingConfigDAL.create({+ projectId: input.projectId,storageBackend: input.storageBackend,connectionId: input.connectionId,bucket: input.bucket,region: input.region,keyPrefix: input.keyPrefix ?? null});- return { config: updated };}- const created = await pamProjectRecordingConfigDAL.create({- projectId: input.projectId,- storageBackend: input.storageBackend,- connectionId: input.connectionId,- bucket: input.bucket,- region: input.region,- keyPrefix: input.keyPrefix ?? null- });- return { config: created };+ let corsProbeUrl: string | null = null;+ if (resolvedConfig) {+ try {+ const probeKey = `${normalizeKeyPrefix(resolvedConfig.keyPrefix)}.cors-probe`;+ const provider = PAM_RECORDING_STORAGE_FACTORY_MAP[input.storageBackend]();+ const { url } = await provider.mintPresignedGet({ config: resolvedConfig, objectKey: probeKey });+ corsProbeUrl = url;+ } catch {+ // Non-fatal -- the config is already saved+ }+ }++ return { config, corsProbeUrl };};const deleteConfig = async ({ projectId }: TDeletePamRecordingConfigDTO, actor: OrgServiceActor) => {diff --git a/frontend/src/hooks/api/pam/recording-config/mutations.tsx b/frontend/src/hooks/api/pam/recording-config/mutations.tsxindex 139f4ff025..790389f5bc 100644--- a/frontend/src/hooks/api/pam/recording-config/mutations.tsx+++ b/frontend/src/hooks/api/pam/recording-config/mutations.tsx@@ -9,11 +9,11 @@ export const useUpsertPamRecordingConfig = () => {const queryClient = useQueryClient();return useMutation({mutationFn: async ({ projectId, ...body }: TUpsertPamRecordingConfigDTO) => {- const { data } = await apiRequest.post<{ config: TPamRecordingConfig }>(- `/api/v1/pam/projects/${projectId}/recording-config`,- body- );- return data.config;+ const { data } = await apiRequest.post<{+ config: TPamRecordingConfig;+ corsProbeUrl: string | null;+ }>(`/api/v1/pam/projects/${projectId}/recording-config`, body);+ return data;},onSuccess: async (_data, vars) => {await queryClient.invalidateQueries({diff --git a/frontend/src/pages/pam/SettingsPage/components/PamRecordingConfigTab.tsx b/frontend/src/pages/pam/SettingsPage/components/PamRecordingConfigTab.tsxindex e5be77c51c..c1d7785768 100644--- a/frontend/src/pages/pam/SettingsPage/components/PamRecordingConfigTab.tsx+++ b/frontend/src/pages/pam/SettingsPage/components/PamRecordingConfigTab.tsx@@ -95,12 +95,27 @@ export const PamRecordingConfigTab = () => {}, [recordingConfig.data, awsConnections, reset]);const onSave = handleSubmit(async (values) => {- await upsertMutation.mutateAsync({+ const { corsProbeUrl } = await upsertMutation.mutateAsync({projectId,...values,keyPrefix: values.keyPrefix?.trim() ? values.keyPrefix : null});createNotification({ type: "success", text: "Session recording configuration saved" });++ if (corsProbeUrl) {+ try {+ await fetch(corsProbeUrl, { mode: "cors" });+ } catch {+ createNotification(+ {+ title: "Bucket CORS not configured",+ type: "warning",+ text: "Session playback requires the bucket to allow GET requests from this origin. Add a CORS rule for this domain on your S3 bucket."+ },+ { autoClose: 10000 }+ );+ }+ }});const onDelete = async () => {