Index: libqapt/src/worker/transaction.cpp
===================================================================
--- libqapt.orig/src/worker/transaction.cpp
+++ libqapt/src/worker/transaction.cpp
@@ -517,11 +517,27 @@ void Transaction::setErrorDetails(const
 
 QVariantMap Transaction::envVariable()
 {
+    QMutexLocker lock(&m_dataMutex);
     return m_envVariable;
 }
 
 void Transaction::setEnvVariable(const QString &envVariableName, const QString &envVariableValue)
 {
+    // 使用鉴权方式：所有用户都需要鉴权
+    QString service = m_service.isEmpty() ? message().service() : m_service;
+    if (service.isEmpty()) {
+        sendErrorReply(QDBusError::AccessDenied, 
+                      QLatin1String("Unable to determine service name for authorization"));
+        return;
+    }
+ 
+    if (!QApt::Auth::authorize(dbusActionUri("commitchanges"), service)) {
+        sendErrorReply(QDBusError::AccessDenied, 
+                      QLatin1String("Authorization required to set environment variables"));
+        return;
+    }
+
+    QMutexLocker lock(&m_dataMutex);
     m_envVariable.insert(envVariableName, envVariableValue);
     setenv(envVariableName.toLocal8Bit(), envVariableValue.toLocal8Bit(), 1);
     emit propertyChanged(QApt::EnvVariableProperty, QDBusVariant(m_envVariable));
