Skip to content

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

bot reviews

xb837bb03ff73
diff --git a/backend/src/ee/services/pam-discovery/pam-discovery-fns.ts b/backend/src/ee/services/pam-discovery/pam-discovery-fns.ts
index 7791fdece2..26050f296a 100644
--- a/backend/src/ee/services/pam-discovery/pam-discovery-fns.ts
+++ b/backend/src/ee/services/pam-discovery/pam-discovery-fns.ts
@@ -80,9 +80,10 @@ export const sweepReachableTargets = async (
): Promise<Set<string>> => {
if (!targets.length) return new Set();
+ const [host] = await verifyHostInputValidity({ host: targets[0].host, isGateway: true, isDynamicSecret: false });
const platform = await gatewayV2Service.getPlatformConnectionDetailsByGatewayId({
gatewayId,
- targetHost: targets[0].host,
+ targetHost: host,
targetPort: targets[0].port
});
if (!platform) throw new BadRequestError({ message: "Unable to connect to gateway" });
@@ -92,7 +93,7 @@ export const sweepReachableTargets = async (
return withGatewayV2Proxy(
(proxyPort) =>
new Promise<Set<string>>((resolve, reject) => {
- const socket = net.connect({ host: "localhost", port: proxyPort });
+ const socket = net.connect({ host: "127.0.0.1", port: proxyPort });
let buffer = "";
const timer = setTimeout(() => {
socket.destroy();
diff --git a/backend/src/ee/services/pam-discovery/unix/unix-discovery-factory.ts b/backend/src/ee/services/pam-discovery/unix/unix-discovery-factory.ts
index bac41d323d..89ea2b04a8 100644
--- a/backend/src/ee/services/pam-discovery/unix/unix-discovery-factory.ts
+++ b/backend/src/ee/services/pam-discovery/unix/unix-discovery-factory.ts
@@ -23,6 +23,7 @@ const SSH_EXEC_TIMEOUT_MS = 20 * 1000;
const SCAN_CONCURRENCY = 64;
const SWEEP_DIAL_TIMEOUT_MS = 3 * 1000;
const MAX_TARGET_HOSTS = 65536;
+const MAX_SWEEP_TARGETS = 65536;
const PASSWD_MARKER = "__INFISICAL_PASSWD__";
const DEFAULT_UID_MIN = 1000;
const DEFAULT_UID_MAX = 60000;
@@ -222,6 +223,11 @@ export const unixDiscoveryFactory: TPamDiscoveryFactory = ({
const usablePorts = [...new Set(accounts.filter(isUsableAccount).map((a) => a.port))];
const sweepTargets = targets.flatMap((host) => usablePorts.map((port) => ({ host, port })));
+ if (sweepTargets.length > MAX_SWEEP_TARGETS) {
+ throw new BadRequestError({
+ message: `Scan expands to ${sweepTargets.length} host-port combinations, exceeding the limit of ${MAX_SWEEP_TARGETS}. Reduce the target ranges or the number of distinct credential ports.`
+ });
+ }
const open = await sweepReachableTargets(sweepTargets, gatewayId, gatewayV2Service, SWEEP_DIAL_TIMEOUT_MS);
const hostsToScan = targets.filter(
diff --git a/backend/src/lib/gateway-v2/gateway-v2.ts b/backend/src/lib/gateway-v2/gateway-v2.ts
index 828956abde..5b245e386f 100644
--- a/backend/src/lib/gateway-v2/gateway-v2.ts
+++ b/backend/src/lib/gateway-v2/gateway-v2.ts
@@ -244,7 +244,8 @@ export const setupRelayServer = async ({
reject(err);
});
- server.listen(0, () => {
+ // bind to loopback only so the ephemeral relay port is not reachable from other hosts/interfaces
+ server.listen(0, "127.0.0.1", () => {
const address = server.address();
if (!address || typeof address === "string") {
server.close();
diff --git a/backend/src/lib/gateway-v2/ssh-rpc.ts b/backend/src/lib/gateway-v2/ssh-rpc.ts
index a8ad3886d5..4d5f6f27c8 100644
--- a/backend/src/lib/gateway-v2/ssh-rpc.ts
+++ b/backend/src/lib/gateway-v2/ssh-rpc.ts
@@ -18,6 +18,8 @@ export type SshExecResponse = SshExecSuccess | SshExecFailure;
export const SSH_EXEC_RPC_TIMEOUT_MS = 120_000;
+const MAX_SSH_EXEC_RESPONSE_BYTES = 16 * 1024 * 1024;
+
// calls the gateway's ssh-exec handler over the local relay proxy; the gateway performs the ssh login (any auth
// method, including certificates the node client can't present) and returns the command output
export const callSshExec = (args: {
@@ -43,7 +45,15 @@ export const callSshExec = (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_SSH_EXEC_RESPONSE_BYTES) {
+ res.destroy(new Error(`SSH exec response exceeded ${MAX_SSH_EXEC_RESPONSE_BYTES} bytes`));
+ return;
+ }
+ chunks.push(chunk);
+ });
res.on("end", () => {
const text = Buffer.concat(chunks).toString("utf8");
const status = res.statusCode ?? 0;