Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Cap winrm gateway RPC response and refine windows pki sync doc

Carlos Monastyrskiea7898a0eb2f
diff --git a/backend/src/lib/gateway-v2/winrm-rpc.ts b/backend/src/lib/gateway-v2/winrm-rpc.ts
index 5ba18403aa..f1d73df130 100644
--- a/backend/src/lib/gateway-v2/winrm-rpc.ts
+++ b/backend/src/lib/gateway-v2/winrm-rpc.ts
@@ -39,6 +39,8 @@ export type WinRmRpcResponse<T> = WinRmRpcSuccess<T> | WinRmRpcFailure;
// gateway-side timeout surfaces as its structured error rather than an opaque client timeout.
export const WINRM_RPC_TIMEOUT_MS = 150_000;
+const MAX_WINRM_RPC_RESPONSE_BYTES = 1024 * 1024;
+
export const callWinRmEndpoint = async <T>(args: {
port: number;
endpoint: WinRmRpcEndpoint;
@@ -46,6 +48,15 @@ export const callWinRmEndpoint = async <T>(args: {
}): Promise<WinRmRpcResponse<T>> => {
const payload = JSON.stringify(args.body);
return new Promise<WinRmRpcResponse<T>>((resolve, reject) => {
+ let settled = false;
+ let deadlineTimer: NodeJS.Timeout;
+ const finish = (run: () => void) => {
+ if (settled) return;
+ settled = true;
+ clearTimeout(deadlineTimer);
+ run();
+ };
+
const req = http.request(
{
host: "127.0.0.1",
@@ -61,45 +72,75 @@ export const callWinRmEndpoint = async <T>(args: {
},
(res) => {
const chunks: Buffer[] = [];
- res.on("data", (chunk: Buffer) => chunks.push(chunk));
+ let received = 0;
+ res.on("data", (chunk: Buffer) => {
+ received += chunk.length;
+ if (received > MAX_WINRM_RPC_RESPONSE_BYTES) {
+ req.destroy();
+ finish(() =>
+ resolve({
+ ok: false,
+ status: res.statusCode ?? 0,
+ errorMessage: `Gateway response exceeded ${MAX_WINRM_RPC_RESPONSE_BYTES} bytes`
+ })
+ );
+ return;
+ }
+ chunks.push(chunk);
+ });
res.on("end", () => {
const text = Buffer.concat(chunks).toString("utf8");
const status = res.statusCode ?? 0;
if (!text) {
- resolve({ ok: false, status, errorMessage: `Empty response body from Gateway (status ${status})` });
+ finish(() =>
+ resolve({ ok: false, status, errorMessage: `Empty response body from Gateway (status ${status})` })
+ );
return;
}
let parsed: unknown;
try {
parsed = JSON.parse(text);
} catch {
- resolve({ ok: false, status, errorMessage: `Malformed response body from Gateway: ${text.slice(0, 256)}` });
+ finish(() =>
+ resolve({
+ ok: false,
+ status,
+ errorMessage: `Malformed response body from Gateway: ${text.slice(0, 256)}`
+ })
+ );
return;
}
if (status >= 200 && status < 300) {
const { result } = parsed as { result?: T };
if (result === undefined) {
- resolve({ ok: false, status, errorMessage: "Gateway response missing `result` field" });
+ finish(() => resolve({ ok: false, status, errorMessage: "Gateway response missing `result` field" }));
return;
}
- resolve({ ok: true, status, result });
+ finish(() => resolve({ ok: true, status, result }));
return;
}
const errEnv = (parsed as { error?: { message?: string } }).error;
- resolve({ ok: false, status, errorMessage: errEnv?.message ?? `Gateway returned HTTP ${status}` });
+ finish(() =>
+ resolve({ ok: false, status, errorMessage: errEnv?.message ?? `Gateway returned HTTP ${status}` })
+ );
});
res.on("error", (err) => {
logger.warn({ err }, `WinRM RPC response stream error [port=${args.port}]`);
- reject(err);
+ finish(() => reject(err));
});
}
);
+ // The socket `timeout` above resets on every byte, so a slow but steady stream never trips it.
+ // This timer caps total wall-clock regardless of activity.
+ deadlineTimer = setTimeout(() => {
+ req.destroy(new Error(`WinRM RPC exceeded the ${WINRM_RPC_TIMEOUT_MS}ms deadline`));
+ }, WINRM_RPC_TIMEOUT_MS);
req.on("timeout", () => {
req.destroy(new Error(`WinRM RPC timed out after ${WINRM_RPC_TIMEOUT_MS}ms`));
});
req.on("error", (err) => {
logger.warn({ err }, `WinRM RPC request error [port=${args.port}]`);
- reject(err);
+ finish(() => reject(err));
});
req.write(payload);
req.end();
diff --git a/docs/documentation/platform/pki/applications/certificate-syncs/windows-server.mdx b/docs/documentation/platform/pki/applications/certificate-syncs/windows-server.mdx
index c04f08b5ce..9a3192b736 100644
--- a/docs/documentation/platform/pki/applications/certificate-syncs/windows-server.mdx
+++ b/docs/documentation/platform/pki/applications/certificate-syncs/windows-server.mdx
@@ -112,6 +112,15 @@ When syncing certificates, Infisical asks the Gateway to open a WinRM session to
When certificate removal is enabled and a certificate is removed from the sync, revoked, or expired, Infisical deletes exactly the files it delivered for that certificate.
+## Security
+
+Delivery runs over the Gateway inside your network, so traffic never crosses the public internet, and the certificate stays encrypted in transit in both connection modes:
+
+<Note>
+ - **HTTP mode (default)** encrypts the certificate on the wire with NTLM message sealing and needs no server certificate to manage. This is the zero-configuration posture most Windows hosts already ship with.
+ - **HTTPS mode** adds TLS, so the Gateway also verifies the host's identity and encrypts the full session. Keep certificate verification enabled so it only connects to a host presenting a valid, trusted certificate.
+</Note>
+
## Using Synced Certificates with IIS Centralized Certificate Store
IIS can serve a synced PKCS#12 certificate directly from a local folder through the Centralized Certificate Store (CCS). To wire this up, set the sync to deliver into the CCS folder and make the two sides agree: