From 630204827e377e77eadb50497a93470b8f5a4530 Mon Sep 17 00:00:00 2001
From: Jonathan Kang <jonathankang@gnome.org>
Date: Wed, 22 Jul 2026 15:42:40 +0800
Subject: [PATCH] daemon: Do not accept symlinks as frontend socket

If a debconf frontend socket is passed, we now ensure that it isn't a
symlink and is a socket, instead of following it and revealing that the
symlinked file exists.

Resolves: #969
---
 src/pk-transaction.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/pk-transaction.c b/src/pk-transaction.c
index 5c24462c7..569bbe066 100644
--- a/src/pk-transaction.c
+++ b/src/pk-transaction.c
@@ -4796,6 +4796,7 @@ pk_transaction_set_hint (PkTransaction *transaction,
 
 	/* frontend_socket=/tmp/socket.3456 */
 	if (g_strcmp0 (key, "frontend-socket") == 0) {
+		GStatBuf st;
 
 		/* nothing provided */
 		if (value == NULL || value[0] == '\0') {
@@ -4815,14 +4816,24 @@ pk_transaction_set_hint (PkTransaction *transaction,
 			return FALSE;
 		}
 
-		/* socket does not exist */
-		if (!g_file_test (value, G_FILE_TEST_EXISTS)) {
-			g_set_error_literal (error,
-					     PK_TRANSACTION_ERROR,
-					     PK_TRANSACTION_ERROR_NOT_SUPPORTED,
-					     "frontend-socket does not exist");
-			return FALSE;
-		}
+		/* must be an actual socket and must not be a symlink:
+		 * lstat() doesn't follow symlinks (which would let callers
+		 * probe arbitrary paths as root), and allows us to reject
+		 * anything that is not a Unix socket */
+	        if (g_lstat (value, &st) != 0) {
+	            g_set_error_literal (error,
+	                         PK_TRANSACTION_ERROR,
+	                         PK_TRANSACTION_ERROR_NOT_SUPPORTED,
+	                         "frontend-socket does not exist");
+	            return FALSE;
+	        }
+	        if (!S_ISSOCK (st.st_mode)) {
+	            g_set_error_literal (error,
+	                         PK_TRANSACTION_ERROR,
+	                         PK_TRANSACTION_ERROR_NOT_SUPPORTED,
+	                         "frontend-socket is not a socket");
+	            return FALSE;
+	        }
 
 		/* success */
 		pk_backend_job_set_frontend_socket (priv->job, value);
-- 
2.55.0

