From 9c74c0b56e3791ec92a0ffefbb9065011d9b0b88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janier=20Rodr=C3=ADguez?= Date: Tue, 24 Nov 2026 15:38:17 +0100 Subject: [PATCH] Keep attribute names containing ':' when they exist verbatim The "prefix:attr" syntax split every attribute name on the first ':'. SAML and OAuth2 providers commonly use URIs or urn:oid names (e.g. urn:oid:1.3.6.1.4.1.5923.1.5.1.1), which were split into a bogus prefix and a missing attribute, so groups and usernames came out empty. Only apply the prefix syntax when the full name is not a received attribute. --- src/uds/core/util/auth.py | 2 +- tests/core/util/test_auth_regex.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/uds/core/util/auth.py b/src/uds/core/util/auth.py index cb086bd22..c5296b0dd 100644 --- a/src/uds/core/util/auth.py +++ b/src/uds/core/util/auth.py @@ -147,7 +147,7 @@ def _get_attr(attr_name: str) -> list[str]: # Prepend the value after ** to attribute value before ** attr, prependable = attr_name.split("**") val = [prependable + a for a in ensure.as_list(attributes.get(attr, []))] - elif ":" in attr_name: + elif ":" in attr_name and attr_name not in attributes: # "prefix:attr" — look up attr, prepend prefix to each value (e.g. alumno:alum + "S" -> "alumnoS") prefix, attr = attr_name.split(":", 1) val = [prefix + a for a in ensure.as_list(attributes.get(attr, []))] diff --git a/tests/core/util/test_auth_regex.py b/tests/core/util/test_auth_regex.py index a033f9c2a..459c92d96 100644 --- a/tests/core/util/test_auth_regex.py +++ b/tests/core/util/test_auth_regex.py @@ -57,3 +57,21 @@ def test_get_attributes_regex_field_colon(self) -> None: from uds.core.util.auth import get_attributes_regex_field self.assertEqual(get_attributes_regex_field("alumno:alumno\npas:pas"), {"alumno", "pas"}) + + def test_attribute_name_with_colon_is_used_verbatim(self) -> None: + from uds.core.util.auth import process_regex_field + + attributes = { + "urn:oid:1.3.6.1.4.1.5923.1.5.1.1": ["staff"], + "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress": ["user@example.com"], + } + self.assertEqual( + process_regex_field("urn:oid:1.3.6.1.4.1.5923.1.5.1.1", attributes), + ["staff"], + ) + self.assertEqual( + process_regex_field( + "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress=(.*)@", attributes + ), + ["user"], + )