[openssh-commits] [openssh] 10/18: upstream: fix leak of authentication socket to intermediate

git+noreply at mindrot.org git+noreply at mindrot.org
Wed Nov 25 19:56:05 AEDT 2026


This is an automated email from the git hooks/post-receive script.

djm pushed a commit to branch master
in repository openssh.

commit b9fd7ee552f8360c29f622a3039b59fc0c7d8e9a
Author: djm at openbsd.org <djm at openbsd.org>
AuthorDate: Wed Nov 25 07:42:28 2026 +0000

    upstream: fix leak of authentication socket to intermediate
    
    ProxyCommand that would occur only when the IdentityAgent option was used to
    choose a different agent socket than the default $SSH_AUTH_SOCK
    
    Anthropic ANT-2026-CZKE7DTG
    
    OpenBSD-Commit-ID: 30d55c363f4ce01623f4660fe6e8ce85ab97912e
---
 ssh.c | 64 +++++++++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 39 insertions(+), 25 deletions(-)

diff --git a/ssh.c b/ssh.c
index 64bd9de49..7dbe3e11e 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh.c,v 1.647 2026/11/02 06:49:42 dtucker Exp $ */
+/* $OpenBSD: ssh.c,v 1.648 2026/11/25 07:42:28 djm Exp $ */
 /*
  * Author: Tatu Ylonen <ylo at cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo at cs.hut.fi>, Espoo, Finland
@@ -622,6 +622,36 @@ set_addrinfo_port(struct addrinfo *addrs, int port)
 	}
 }
 
+/* Optionally set the SSH_AUTHSOCKET_ENV_NAME variable from IdentityAgent */
+static void
+set_identity_agent(void)
+{
+	const char *cp, *p;
+
+	if (options.identity_agent == NULL ||
+	    strcmp(options.identity_agent, SSH_AUTHSOCKET_ENV_NAME) == 0)
+		return;
+	if (strcmp(options.identity_agent, "none") == 0) {
+		unsetenv(SSH_AUTHSOCKET_ENV_NAME);
+		return;
+	}
+	cp = options.identity_agent;
+	/* legacy (limited) format */
+	if (cp[0] == '$' && cp[1] != '{') {
+		if (!valid_env_name(cp + 1)) {
+			fatal("Invalid IdentityAgent "
+			    "environment variable name %s", cp);
+		}
+		if ((p = getenv(cp + 1)) == NULL)
+			unsetenv(SSH_AUTHSOCKET_ENV_NAME);
+		else
+			setenv(SSH_AUTHSOCKET_ENV_NAME, p, 1);
+	} else {
+		/* identity_agent specifies a path directly */
+		setenv(SSH_AUTHSOCKET_ENV_NAME, cp, 1);
+	}
+}
+
 /*
  * Main program for the ssh client.
  */
@@ -1659,31 +1689,8 @@ main(int ac, char **av)
 	/* load options.identity_files */
 	load_public_identity_files(cinfo);
 
-	/* optionally set the SSH_AUTHSOCKET_ENV_NAME variable */
-	if (options.identity_agent &&
-	    strcmp(options.identity_agent, SSH_AUTHSOCKET_ENV_NAME) != 0) {
-		if (strcmp(options.identity_agent, "none") == 0) {
-			unsetenv(SSH_AUTHSOCKET_ENV_NAME);
-		} else {
-			cp = options.identity_agent;
-			/* legacy (limited) format */
-			if (cp[0] == '$' && cp[1] != '{') {
-				if (!valid_env_name(cp + 1)) {
-					fatal("Invalid IdentityAgent "
-					    "environment variable name %s", cp);
-				}
-				if ((p = getenv(cp + 1)) == NULL)
-					unsetenv(SSH_AUTHSOCKET_ENV_NAME);
-				else
-					setenv(SSH_AUTHSOCKET_ENV_NAME, p, 1);
-			} else {
-				/* identity_agent specifies a path directly */
-				setenv(SSH_AUTHSOCKET_ENV_NAME, cp, 1);
-			}
-		}
-	}
-
 	if (dump_pubkeys) {
+		set_identity_agent();
 		pubkey_dump(ssh);
 		exit(0);
 	}
@@ -1728,6 +1735,13 @@ main(int ac, char **av)
 	    &timeout_ms, options.tcp_keep_alive) != 0)
 		exit(255);
 
+	/*
+	 * IdentityAgent applies to this connection only, so don't touch the
+	 * environment until after any ProxyCommand/ProxyJump has been
+	 * started: the proxy (e.g. a ssh to a jump host) must not inherit
+	 * the destination's agent.
+	 */
+	set_identity_agent();
 
 	ssh_packet_set_timeout(ssh, options.server_alive_interval,
 	    options.server_alive_count_max);

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list