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: avoid deletion of sealed values
adilsonccfb6b552d90
diff --git a/backend/src/services/app-connection/railway/railway-connection-constants.ts b/backend/src/services/app-connection/railway/railway-connection-constants.tsindex af03411a41..48080394d0 100644--- a/backend/src/services/app-connection/railway/railway-connection-constants.ts+++ b/backend/src/services/app-connection/railway/railway-connection-constants.ts@@ -26,6 +26,7 @@ export enum RailwayDeploymentStatus {// selecting a deployment to redeploy.export const RAILWAY_NON_REDEPLOYABLE_STATUSES = new Set<string>([RailwayDeploymentStatus.Building,+ RailwayDeploymentStatus.Deploying,RailwayDeploymentStatus.Queued,RailwayDeploymentStatus.Initializing,RailwayDeploymentStatus.Waiting,diff --git a/backend/src/services/app-connection/railway/railway-connection-public-client.ts b/backend/src/services/app-connection/railway/railway-connection-public-client.tsindex 0be81de617..84e1dbfc1d 100644--- a/backend/src/services/app-connection/railway/railway-connection-public-client.ts+++ b/backend/src/services/app-connection/railway/railway-connection-public-client.ts@@ -178,8 +178,9 @@ class RailwayPublicClient {const projectPerWorkspace = await Promise.all(workspaces.me.workspaces.map(async (w) => {const projectsResponse = await this.send(- `{ workspace(workspaceId: "${w.id}") { projects { edges { node { id, name, services { edges { node { id, name } } } environments { edges { node { name, id } } } } } } } }`,- config+ `query workspace($workspaceId: String!) { workspace(workspaceId: $workspaceId) { projects { edges { node { id, name, services { edges { node { id, name } } } environments { edges { node { name, id } } } } } } } }`,+ config,+ { workspaceId: w.id });const projectsData = await RailwayWorkspaceProjectsListSchema.parseAsync(projectsResponse);diff --git a/backend/src/services/secret-sync/railway/railway-sync-fns.ts b/backend/src/services/secret-sync/railway/railway-sync-fns.tsindex 4ddf3b71b7..854285be37 100644--- a/backend/src/services/secret-sync/railway/railway-sync-fns.ts+++ b/backend/src/services/secret-sync/railway/railway-sync-fns.ts@@ -56,8 +56,10 @@ export const RailwaySyncFns = {/*** Syncs secrets to Railway and redeploys the service if needed.*- * Gets existing Railway vars, merges with new secrets (keeping Railway vars if deletion is disabled),- * then replaces every variable with the new values, if variable is not in the secretMap, it is deleted.+ * Upserts the Infisical-managed secrets with `replace: false` so existing Railway variables are+ * never deleted implicitly. Sealed variables (value === null, unreadable by design) cannot be+ * resubmitted, so a `replace: true` payload would silently wipe them — a data-loss bug. When+ * deletion is enabled, drift is removed explicitly via per-key deletes that skip sealed variables.* If there's a service, triggers a redeploy to pick up the changes.*/async syncSecrets(secretSync: TRailwaySyncWithCredentials, secretMap: TSecretMap) {@@ -65,24 +67,18 @@ export const RailwaySyncFns = {const {syncOptions: { disableSecretDeletion }} = secretSync;- const railwaySecrets = await this.getSecrets(secretSync);const config = secretSync.destinationConfig;- const railwaySecretsMap = Object.fromEntries(- Object.entries(railwaySecrets).map(([key, secret]) => [key, secret.value])- );const secretMapMap = Object.fromEntries(Object.entries(secretMap).map(([key, secret]) => [key, secret.value]));- const toReplace = disableSecretDeletion ? { ...railwaySecretsMap, ...secretMapMap } : secretMapMap;-const upserted = await RailwayPublicAPI.upsertCollection(secretSync.connection, {input: {projectId: config.projectId,environmentId: config.environmentId,serviceId: config.serviceId || undefined,skipDeploys: true,- variables: toReplace,- replace: true+ variables: secretMapMap,+ replace: false}});@@ -91,6 +87,34 @@ export const RailwaySyncFns = {message: "Failed to upsert secrets to Railway"});+ // When deletion is enabled (full-mirror), remove only the variables Infisical no longer+ // manages. Explicitly skip sealed variables (value === null) — they are unreadable and must+ // never be deleted — and Railway system variables (RAILWAY_ prefix).+ if (!disableSecretDeletion) {+ const existingVariables = await RailwayPublicAPI.getVariables(secretSync.connection, {+ projectId: config.projectId,+ environmentId: config.environmentId,+ serviceId: config.serviceId || undefined+ });++ const keysToDelete = Object.entries(existingVariables)+ .filter(([key, value]) => value !== null && !key.startsWith("RAILWAY_") && !(key in secretMap))+ .map(([key]) => key);++ for (const name of keysToDelete) {+ // eslint-disable-next-line no-await-in-loop+ await RailwayPublicAPI.deleteVariable(secretSync.connection, {+ input: {+ projectId: config.projectId,+ environmentId: config.environmentId,+ serviceId: config.serviceId || undefined,+ name,+ skipDeploys: true+ }+ });+ }+ }+if (!config.serviceId) return;const latestDeployment = await RailwayPublicAPI.getDeployments(secretSync.connection, {@@ -132,31 +156,32 @@ export const RailwaySyncFns = {},async removeSecrets(secretSync: TRailwaySyncWithCredentials, secretMap: TSecretMap) {- const existing = await this.getSecrets(secretSync);const config = secretSync.destinationConfig;- // Create a new variables object excluding secrets that exist in secretMap- const remainingVariables = Object.fromEntries(- Object.entries(existing)- .filter(([key]) => !(key in secretMap))- .map(([key, secret]) => [key, secret.value])- );-try {- const upserted = await RailwayPublicAPI.upsertCollection(secretSync.connection, {- input: {- projectId: config.projectId,- environmentId: config.environmentId,- serviceId: config.serviceId || undefined,- skipDeploys: true,- variables: remainingVariables,- replace: true- }+ const existingVariables = await RailwayPublicAPI.getVariables(secretSync.connection, {+ projectId: config.projectId,+ environmentId: config.environmentId,+ serviceId: config.serviceId || undefined});- if (!upserted) {- throw new SecretSyncError({- message: "Failed to remove secrets from Railway"+ // Delete only the Infisical-managed variables that exist in Railway. Per-key deletes (instead+ // of a replace: true collection upsert) guarantee sealed variables (value === null) — which+ // are unreadable and cannot be resubmitted — are never wiped.+ const keysToDelete = Object.keys(existingVariables).filter(+ (key) => key in secretMap && existingVariables[key] !== null+ );++ for (const name of keysToDelete) {+ // eslint-disable-next-line no-await-in-loop+ await RailwayPublicAPI.deleteVariable(secretSync.connection, {+ input: {+ projectId: config.projectId,+ environmentId: config.environmentId,+ serviceId: config.serviceId || undefined,+ name,+ skipDeploys: true+ }});}} catch (error) {