public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Marek Blaha <mblaha@redhat.com>
To: git-commits@fedoraproject.org
Subject: [rpms/dnf5] f45: dnf5daemon-server: Authorize command line specs
Date: Fri, 13 Nov 2026 15:31:08 GMT	[thread overview]
Message-ID: <179458386821.1.17130253110987360218.rpms-dnf5-50eae302be49@fedoraproject.org> (raw)

A new commit has been pushed.

Repo   : rpms/dnf5
Branch : f45
Commit : 50eae302be4991c3ff4a67ef5996482bdac8014b
Author : Marek Blaha <mblaha@redhat.com>
Date   : 2026-11-12T09:36:59+01:00
Stats  : +399/-1 in 2 file(s)
URL    : https://src.fedoraproject.org/rpms/dnf5/c/50eae302be4991c3ff4a67ef5996482bdac8014b?branch=f45

Log:
dnf5daemon-server: Authorize command line specs

---
diff --git a/0001-dnfdaemon-authorize-command-line-specs.patch b/0001-dnfdaemon-authorize-command-line-specs.patch
new file mode 100644
index 0000000..11bae15
--- /dev/null
+++ b/0001-dnfdaemon-authorize-command-line-specs.patch
@@ -0,0 +1,394 @@
+From 9a9d73e248d2d9176c4a93a049310864555ad61a Mon Sep 17 00:00:00 2001
+From: Marek Blaha <mblaha@redhat.com>
+Date: Thu, 5 Nov 2026 07:59:41 +0000
+Subject: [PATCH 1/2] utils: add command-line package specification classifier
+
+Goal::Impl::add_spec() previously combined the internal URL helper with a
+local ".rpm" suffix check to decide whether a package specification refers
+to a command-line package. That classification needs to be reused by callers
+that must authorize external package inputs before libdnf5 opens or
+downloads them.
+
+Move the predicate to libdnf5::utils::is_cmdline_package_spec(), expose it
+through the public libdnf5 utility API, and use it from Goal and
+RepoSack. The function performs no filesystem or network I/O and
+recognizes supported URLs and non-URL paths ending in ".rpm". Add tests
+for scheme support, case insensitivity, query strings, and local paths.
+
+This centralizes the existing behavior without changing it.
+---
+ include/libdnf5/utils/patterns.hpp   |  9 +++++++++
+ libdnf5/base/goal.cpp                |  3 +--
+ libdnf5/repo/repo_sack.cpp           |  6 +++++-
+ libdnf5/utils/patterns.cpp           |  8 ++++++++
+ test/libdnf5/utils/test_patterns.cpp | 15 +++++++++++++++
+ test/libdnf5/utils/test_patterns.hpp |  2 ++
+ 6 files changed, 40 insertions(+), 3 deletions(-)
+
+diff --git a/include/libdnf5/utils/patterns.hpp b/include/libdnf5/utils/patterns.hpp
+index 72b639f1d..0c5a88e1d 100644
+--- a/include/libdnf5/utils/patterns.hpp
++++ b/include/libdnf5/utils/patterns.hpp
+@@ -38,6 +38,15 @@ LIBDNF_API bool is_glob_pattern(const char * pattern) noexcept;
+ /// @return True if a given pattern is a file path
+ LIBDNF_API bool is_file_pattern(const std::string & pattern) noexcept;
+ 
++/// @brief Check if a given package specification is a command-line package.
++///
++/// A command-line package specification is either a supported URL or a local path
++/// ending in ".rpm".
++///
++/// @param spec Text package specification to be tested
++/// @return True if a given specification is a command-line package
++LIBDNF_API bool is_cmdline_package_spec(const std::string & spec);
++
+ }  // namespace libdnf5::utils
+ 
+ #endif  // LIBDNF5_UTILS_PATTERNS_HPP
+diff --git a/libdnf5/base/goal.cpp b/libdnf5/base/goal.cpp
+index cee1aeaed..c042d17ae 100644
+--- a/libdnf5/base/goal.cpp
++++ b/libdnf5/base/goal.cpp
+@@ -485,8 +485,7 @@ void Goal::Impl::add_spec(GoalAction action, const std::string & spec, const Goa
+         group_specs.push_back(
+             std::make_tuple(action, libdnf5::transaction::TransactionItemReason::USER, group_spec, group_settings));
+     } else {
+-        const std::string_view ext(".rpm");
+-        if (libdnf5::utils::url::is_url(spec) || (spec.length() > ext.length() && spec.ends_with(ext))) {
++        if (libdnf5::utils::is_cmdline_package_spec(spec)) {
+             // spec is a remote rpm file or a local rpm file
+             if (action == GoalAction::REMOVE) {
+                 throw RuntimeError(M_("Unsupported argument for REMOVE action: {}"), spec);
+diff --git a/libdnf5/repo/repo_sack.cpp b/libdnf5/repo/repo_sack.cpp
+index e4ef426a9..6eef2f874 100644
+--- a/libdnf5/repo/repo_sack.cpp
++++ b/libdnf5/repo/repo_sack.cpp
+@@ -51,6 +51,7 @@
+ #include "libdnf5/utils/bgettext/bgettext-mark-domain.h"
+ #include "libdnf5/utils/fs/file.hpp"
+ #include "libdnf5/utils/fs/temp.hpp"
++#include "libdnf5/utils/patterns.hpp"
+ 
+ extern "C" {
+ #include <solv/testcase.h>
+@@ -233,9 +234,12 @@ std::map<std::string, libdnf5::rpm::Package> RepoSack::add_cmdline_packages(
+     std::vector<std::string> rpm_filepaths;
+     const std::string_view ext(".rpm");
+     for (const auto & spec : paths) {
++        if (!libdnf5::utils::is_cmdline_package_spec(spec)) {
++            continue;
++        }
+         if (libdnf5::utils::url::is_url(spec)) {
+             rpm_urls.emplace_back(spec);
+-        } else if (spec.length() > ext.length() && spec.ends_with(ext)) {
++        } else {
+             rpm_filepaths.emplace_back(spec);
+         }
+     }
+diff --git a/libdnf5/utils/patterns.cpp b/libdnf5/utils/patterns.cpp
+index f17e6ab51..5cae9d2fb 100644
+--- a/libdnf5/utils/patterns.cpp
++++ b/libdnf5/utils/patterns.cpp
+@@ -19,7 +19,10 @@
+ 
+ #include "libdnf5/utils/patterns.hpp"
+ 
++#include "utils/url.hpp"
++
+ #include <cstring>
++#include <string_view>
+ 
+ namespace libdnf5::utils {
+ 
+@@ -31,4 +34,9 @@ bool is_file_pattern(const std::string & pattern) noexcept {
+     return pattern[0] == '/' || (pattern[0] == '*' && pattern[1] == '/');
+ }
+ 
++bool is_cmdline_package_spec(const std::string & spec) {
++    constexpr std::string_view rpm_extension(".rpm");
++    return url::is_url(spec) || (spec.length() > rpm_extension.length() && spec.ends_with(rpm_extension));
++}
++
+ }  // namespace libdnf5::utils
+diff --git a/test/libdnf5/utils/test_patterns.cpp b/test/libdnf5/utils/test_patterns.cpp
+index a0abcabac..2fe52fbd5 100644
+--- a/test/libdnf5/utils/test_patterns.cpp
++++ b/test/libdnf5/utils/test_patterns.cpp
+@@ -42,3 +42,18 @@ void UtilsPatternsTest::test_is_glob_pattern() {
+     CPPUNIT_ASSERT(is_glob_pattern("glob[sdf]_pattern"));
+     CPPUNIT_ASSERT(is_glob_pattern("glob?_pattern"));
+ }
++
++
++void UtilsPatternsTest::test_is_cmdline_package_spec() {
++    CPPUNIT_ASSERT(!is_cmdline_package_spec(""));
++    CPPUNIT_ASSERT(!is_cmdline_package_spec("pkg"));
++    CPPUNIT_ASSERT(!is_cmdline_package_spec(".rpm"));
++    CPPUNIT_ASSERT(!is_cmdline_package_spec("gopher://example.com/pkg"));
++    CPPUNIT_ASSERT(is_cmdline_package_spec("gopher://example.com/pkg.rpm"));
++    CPPUNIT_ASSERT(is_cmdline_package_spec("/repository/pkg.rpm"));
++    CPPUNIT_ASSERT(is_cmdline_package_spec("file:///repository/pkg.rpm"));
++    CPPUNIT_ASSERT(is_cmdline_package_spec("FILE:///repository/pkg.rpm"));
++    CPPUNIT_ASSERT(is_cmdline_package_spec("http://example.com/pkg?marker.rpm"));
++    CPPUNIT_ASSERT(is_cmdline_package_spec("https://example.com/pkg"));
++    CPPUNIT_ASSERT(is_cmdline_package_spec("ftp://example.com/pkg"));
++}
+diff --git a/test/libdnf5/utils/test_patterns.hpp b/test/libdnf5/utils/test_patterns.hpp
+index 4e7ba2a0a..6160f169f 100644
+--- a/test/libdnf5/utils/test_patterns.hpp
++++ b/test/libdnf5/utils/test_patterns.hpp
+@@ -27,11 +27,13 @@ class UtilsPatternsTest : public CppUnit::TestCase {
+     CPPUNIT_TEST_SUITE(UtilsPatternsTest);
+     CPPUNIT_TEST(test_is_file_pattern);
+     CPPUNIT_TEST(test_is_glob_pattern);
++    CPPUNIT_TEST(test_is_cmdline_package_spec);
+     CPPUNIT_TEST_SUITE_END();
+ 
+ public:
+     void test_is_file_pattern();
+     void test_is_glob_pattern();
++    void test_is_cmdline_package_spec();
+ };
+ 
+ #endif  // LIBDNF5_TEST_UTILS_PATTERNS_HPP
+-- 
+2.56.0
+
+
+From 5c434b390801f5a29870fce24a1b524736e24d96 Mon Sep 17 00:00:00 2001
+From: Marek Blaha <mblaha@redhat.com>
+Date: Thu, 5 Nov 2026 17:06:41 +0000
+Subject: [PATCH 2/2] rpm: authorize command-line package specifications
+
+Rpm.list(), Rpm.list_fd(), install(), upgrade(), downgrade(), and
+reinstall() accepted URL and local .rpm specifications without an
+authorization check. Those specifications can reach libdnf5's
+command-line package loader during repository loading or Goal
+resolution, before the existing transaction-execution check.
+
+Classify the submitted specifications with the public libdnf5 predicate
+and check POLKIT_EXECUTE_RPM_TRANSACTION using the actual D-Bus sender
+before loading repository data or queueing any Goal request. Direct
+package actions default to interactive authorization so clients receive
+the Polkit prompt immediately; repository-only operations remain
+unchanged.
+---
+ .../interfaces/org.rpm.dnf.v0.rpm.Rpm.xml     | 20 ++++++++
+ .../polkit/org.rpm.dnf.v0.policy              |  2 +-
+ dnf5daemon-server/services/rpm/rpm.cpp        | 47 +++++++++++++++++++
+ dnf5daemon-server/services/rpm/rpm.hpp        |  2 +
+ 4 files changed, 70 insertions(+), 1 deletion(-)
+
+diff --git a/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.rpm.Rpm.xml b/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.rpm.Rpm.xml
+index 57641b1c3..dfa2c6027 100644
+--- a/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.rpm.Rpm.xml
++++ b/dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.rpm.Rpm.xml
+@@ -60,6 +60,8 @@ along with libdnf.  If not, see <https://www.gnu.org/licenses/>.
+ 
+             - patterns: list of strings
+                 any package matching to any of patterns is returned
++                Patterns that are URLs or local `.rpm` paths require authorization
++                before the daemon loads them.
+             - scope: string (default "all")
+                 limit packages to one of "all", "installed", "available", "upgrades", "upgradable"
+             - arch: list of strings
+@@ -120,6 +122,8 @@ along with libdnf.  If not, see <https://www.gnu.org/licenses/>.
+         @options: an array of key/value pairs to modify install behavior
+ 
+         Mark packages specified by @pkg_specs for installation.
++        URL or local `.rpm` specifications require authorization before they
++        are queued.
+ 
+         Following @options are supported:
+ 
+@@ -129,6 +133,8 @@ along with libdnf.  If not, see <https://www.gnu.org/licenses/>.
+                 Whether solver can skip packages with broken dependencies to resolve transaction
+             - skip_unavailable: boolean, default false
+                 Whether nonexisting packages can be skipped.
++            - interactive: boolean, default true
++                Set to "true", when the operation is done by a user, thus user interaction like password prompts can be done.
+ 
+         Unknown options are ignored.
+     -->
+@@ -143,11 +149,15 @@ along with libdnf.  If not, see <https://www.gnu.org/licenses/>.
+         @options: an array of key/value pairs to modify upgrade behavior
+ 
+         Mark packages specified by @pkg_specs for upgrade.
++        URL or local `.rpm` specifications require authorization before they
++        are queued.
+ 
+         Following @options are supported:
+ 
+             - repo_ids: list of strings
+                 Identifiers of the repos from which the packages could be upgraded.
++            - interactive: boolean, default true
++                Set to "true", when the operation is done by a user, thus user interaction like password prompts can be done.
+ 
+         Unknown options are ignored.
+     -->
+@@ -190,9 +200,14 @@ along with libdnf.  If not, see <https://www.gnu.org/licenses/>.
+         @options: an array of key/value pairs to modify downgrade behavior
+ 
+         Mark packages specified by @pkg_specs for downgrade.
++        URL or local `.rpm` specifications require authorization before they
++        are queued.
+ 
+         Following @options are supported:
+ 
++            - interactive: boolean, default true
++                Set to "true", when the operation is done by a user, thus user interaction like password prompts can be done.
++
+         Unknown options are ignored.
+     -->
+     <method name="downgrade">
+@@ -206,9 +221,14 @@ along with libdnf.  If not, see <https://www.gnu.org/licenses/>.
+         @options: an array of key/value pairs to modify reinstall behavior
+ 
+         Mark packages specified by @pkg_specs for reinstall.
++        URL or local `.rpm` specifications require authorization before they
++        are queued.
+ 
+         Following @options are supported:
+ 
++            - interactive: boolean, default true
++                Set to "true", when the operation is done by a user, thus user interaction like password prompts can be done.
++
+         Unknown options are ignored.
+     -->
+     <method name="reinstall">
+diff --git a/dnf5daemon-server/polkit/org.rpm.dnf.v0.policy b/dnf5daemon-server/polkit/org.rpm.dnf.v0.policy
+index 87c5fecf5..537aa9623 100644
+--- a/dnf5daemon-server/polkit/org.rpm.dnf.v0.policy
++++ b/dnf5daemon-server/polkit/org.rpm.dnf.v0.policy
+@@ -28,7 +28,7 @@
+ 
+   <action id="org.rpm.dnf.v0.rpm.execute_transaction">
+     <description>Execute untrusted rpm transaction</description>
+-    <message>Authentication is required to execute an rpm transaction with local or signature-unverified packages.</message>
++    <message>Authentication is required to execute an rpm transaction with untrusted packages or access package files from local paths or URLs.</message>
+     <defaults>
+         <allow_any>auth_admin</allow_any>
+         <allow_inactive>auth_admin</allow_inactive>
+diff --git a/dnf5daemon-server/services/rpm/rpm.cpp b/dnf5daemon-server/services/rpm/rpm.cpp
+index 0476cad7e..50a41157f 100644
+--- a/dnf5daemon-server/services/rpm/rpm.cpp
++++ b/dnf5daemon-server/services/rpm/rpm.cpp
+@@ -24,6 +24,7 @@
+ 
+ #include "libdnf5/comps/environment/query.hpp"
+ #include "libdnf5/comps/group/query.hpp"
++#include "libdnf5/utils/patterns.hpp"
+ 
+ #include <libdnf5/rpm/package_query.hpp>
+ #include <libdnf5/rpm/package_set.hpp>
+@@ -383,6 +384,17 @@ std::vector<std::string> get_filter_patterns(dnfdaemon::KeyValueMap options, con
+     return filter_patterns;
+ }
+ 
++bool Rpm::authorize_cmdline_package_specs(
++    const std::vector<std::string> & specs, const std::string & sender, bool interactive) {
++    for (const auto & spec : specs) {
++        if (libdnf5::utils::is_cmdline_package_spec(spec)) {
++            return session.check_authorization(dnfdaemon::POLKIT_EXECUTE_RPM_TRANSACTION, sender, interactive);
++        }
++    }
++
++    return true;
++}
++
+ libdnf5::rpm::PackageQuery resolve_nevras(
+     libdnf5::rpm::PackageQuery base_query, const std::vector<std::string> & nevras) {
+     libdnf5::rpm::PackageQuery result(base_query.get_base(), libdnf5::sack::ExcludeFlags::APPLY_EXCLUDES, true);
+@@ -593,6 +605,12 @@ sdbus::MethodReply Rpm::list(sdbus::MethodCall & call) {
+     call >> options;
+ 
+     bool interactive = dnfdaemon::key_value_map_get<bool>(options, "interactive", false);
++    const auto patterns =
++        dnfdaemon::key_value_map_get<std::vector<std::string>>(options, "patterns", std::vector<std::string>{});
++    if (!authorize_cmdline_package_specs(patterns, call.getSender(), interactive)) {
++        throw std::runtime_error("Not authorized");
++    }
++
+     session.fill_sack(interactive);
+ 
+     auto query = filter_packages(options);
+@@ -624,6 +642,12 @@ void Rpm::list_fd(sdbus::MethodCall & call, const std::string & transfer_id) {
+ 
+         int out_fd = dbus_unix_fd.get();
+         bool interactive = dnfdaemon::key_value_map_get<bool>(options, "interactive", false);
++        const auto patterns =
++            dnfdaemon::key_value_map_get<std::vector<std::string>>(options, "patterns", std::vector<std::string>{});
++        if (!authorize_cmdline_package_specs(patterns, call.getSender(), interactive)) {
++            throw std::runtime_error("Not authorized");
++        }
++
+         session.fill_sack(interactive);
+         auto query = filter_packages(options);
+         std::vector<std::string> package_attrs = dnfdaemon::key_value_map_get<std::vector<std::string>>(
+@@ -699,6 +723,12 @@ sdbus::MethodReply Rpm::downgrade(sdbus::MethodCall & call) {
+     // read options from dbus call
+     dnfdaemon::KeyValueMap options;
+     call >> options;
++
++    bool interactive = dnfdaemon::key_value_map_get<bool>(options, "interactive", true);
++    if (!authorize_cmdline_package_specs(specs, call.getSender(), interactive)) {
++        throw std::runtime_error("Not authorized");
++    }
++
+     std::vector<std::string> repo_ids = dnfdaemon::key_value_map_get<std::vector<std::string>>(options, "repo_ids", {});
+ 
+     // fill the goal
+@@ -721,6 +751,11 @@ sdbus::MethodReply Rpm::install(sdbus::MethodCall & call) {
+     dnfdaemon::KeyValueMap options;
+     call >> options;
+ 
++    bool interactive = dnfdaemon::key_value_map_get<bool>(options, "interactive", true);
++    if (!authorize_cmdline_package_specs(specs, call.getSender(), interactive)) {
++        throw std::runtime_error("Not authorized");
++    }
++
+     libdnf5::GoalSetting skip_broken;
+     if (options.find("skip_broken") != options.end()) {
+         skip_broken = dnfdaemon::key_value_map_get<bool>(options, "skip_broken") ? libdnf5::GoalSetting::SET_TRUE
+@@ -760,6 +795,12 @@ sdbus::MethodReply Rpm::upgrade(sdbus::MethodCall & call) {
+     // read options from dbus call
+     dnfdaemon::KeyValueMap options;
+     call >> options;
++
++    bool interactive = dnfdaemon::key_value_map_get<bool>(options, "interactive", true);
++    if (!authorize_cmdline_package_specs(specs, call.getSender(), interactive)) {
++        throw std::runtime_error("Not authorized");
++    }
++
+     std::vector<std::string> repo_ids = dnfdaemon::key_value_map_get<std::vector<std::string>>(options, "repo_ids", {});
+ 
+     // fill the goal
+@@ -785,6 +826,12 @@ sdbus::MethodReply Rpm::reinstall(sdbus::MethodCall & call) {
+     // read options from dbus call
+     dnfdaemon::KeyValueMap options;
+     call >> options;
++
++    bool interactive = dnfdaemon::key_value_map_get<bool>(options, "interactive", true);
++    if (!authorize_cmdline_package_specs(specs, call.getSender(), interactive)) {
++        throw std::runtime_error("Not authorized");
++    }
++
+     std::vector<std::string> repo_ids = dnfdaemon::key_value_map_get<std::vector<std::string>>(options, "repo_ids", {});
+ 
+     // fill the goal
+diff --git a/dnf5daemon-server/services/rpm/rpm.hpp b/dnf5daemon-server/services/rpm/rpm.hpp
+index 27563af48..6b3ee0fe4 100644
+--- a/dnf5daemon-server/services/rpm/rpm.hpp
++++ b/dnf5daemon-server/services/rpm/rpm.hpp
+@@ -35,6 +35,8 @@ public:
+ 
+ private:
+     libdnf5::rpm::PackageQuery filter_packages(const dnfdaemon::KeyValueMap & options);
++    bool authorize_cmdline_package_specs(
++        const std::vector<std::string> & specs, const std::string & sender, bool interactive);
+ 
+     sdbus::MethodReply list(sdbus::MethodCall & call);
+     sdbus::MethodReply install(sdbus::MethodCall & call);
+-- 
+2.56.0
+

diff --git a/dnf5.spec b/dnf5.spec
index 74fe13b..7181fd2 100644
--- a/dnf5.spec
+++ b/dnf5.spec
@@ -72,11 +72,12 @@
 
 Name:           dnf5
 Version:        %{project_version_prime}.%{project_version_major}.%{project_version_minor}.%{project_version_micro}
-Release:        1%{?dist}
+Release:        2%{?dist}
 Summary:        Command-line package manager
 License:        GPL-2.0-or-later AND LGPL-2.1-or-later AND LGPL-2.0-or-later
 URL:            https://github.com/rpm-software-management/dnf5
 Source0:        %{url}/archive/%{version}/dnf5-%{version}.tar.gz
+Patch1:         0001-dnfdaemon-authorize-command-line-specs.patch
 
 Requires:       libdnf5%{?_isa} = %{version}-%{release}
 Requires:       libdnf5-cli%{?_isa} = %{version}-%{release}
@@ -1235,6 +1236,9 @@ mkdir -p %{buildroot}%{_libdir}/libdnf5/plugins
 %ldconfig_scriptlets
 
 %changelog
+* Thu Nov 12 2026 Marek Blaha <mblaha@redhat.com> - 5.4.8.0-2
+- dnf5daemon-server: Authorize command line specs (CVE-2026-123177)
+
 * Wed Nov 11 2026 Packit <hello@packit.dev> - 5.4.8.0-1
 - Update to version 5.4.8.0
 

                 reply	other threads:[~2026-11-13 15:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179458386821.1.17130253110987360218.rpms-dnf5-50eae302be49@fedoraproject.org \
    --to=mblaha@redhat.com \
    --cc=git-commits@fedoraproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox