From b538de722a8c877478392def8178a117df63fa4d Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 27 Oct 2026 10:08:58 -0400 Subject: [PATCH] ansible-galaxy - Validate the role name (#87749) (#87759) * Validate the role name before creating or modifying the installation path Fixes CVE-2026-105929 Simplify by making any unsafe role name an error instead of guarding against modifying/installing it * handle possible diff error messages --------- (cherry picked from commit 9795c1b56a67138e807404d97b3e4b4d33098614) Co-authored-by: Sloane Hertel <19572925+s-hertel@users.noreply.github.com> Signed-off-by: Azure Linux Security Servicing Account Upstream-reference: https://github.com/ansible/ansible/commit/267a44d25c0f2b9f8a5b8b30b1a6b98c475324a6.patch --- .../fragments/ansible-galaxy-role-name-containment.yml | 3 +++ lib/ansible/cli/galaxy.py | 10 ++++++++++ 2 files changed, 13 insertions(+) create mode 100644 changelogs/fragments/ansible-galaxy-role-name-containment.yml diff --git a/changelogs/fragments/ansible-galaxy-role-name-containment.yml b/changelogs/fragments/ansible-galaxy-role-name-containment.yml new file mode 100644 index 0000000..72a364a --- /dev/null +++ b/changelogs/fragments/ansible-galaxy-role-name-containment.yml @@ -0,0 +1,3 @@ +security_fixes: +- >- + ``ansible-galaxy role install`` - fix validating the role name is contained to the configured role path. (CVE-2026-105929) diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index 5c506b0..fb4d378 100755 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -60,6 +60,7 @@ from ansible.playbook.role.requirement import RoleRequirement from ansible.template import Templar from ansible.utils.collection_loader import AnsibleCollectionConfig from ansible.utils.display import Display +from ansible.utils.path import is_subpath from ansible.utils.plugin_docs import get_versioned_doclink from ansible.utils.vars import load_extra_vars @@ -1510,6 +1511,15 @@ class GalaxyCLI(CLI): display.vvv('Processing role %s ' % role.name) + if not any( + is_subpath(os.path.join(path, role.name), path, real=True) + for path in context.CLIARGS['roles_path'] + ): + display.warning(f"The role name '{role.name}' resolves to a path outside of the configured role directory") + self.exit_without_ignore() + display.display(f'- skipping role {role.name}') + continue + # query the galaxy API for the role data if role.install_info is not None: -- 2.45.4