From 23a7b632f8babfb426e57b36d0a248fd2d76209a Mon Sep 17 00:00:00 2001 From: Kay Joosten Date: Thu, 2 Jul 2026 09:34:43 +0200 Subject: [PATCH 01/18] Preserve and expose mdui:UIInfo during authentication and registration Prior to this change, the GSSP bundle discarded the mdui:UIInfo extension forwarded by the Gateway on proxy AuthnRequests. Consumers had no way to retrieve per-language service display names from session state, making it impossible to show the correct service name during step-up authentication and registration flows. This change saves mdui:UIInfo to session state in both saveAuthenticationRequest() and saveRegistrationRequest(), and exposes it through getMdui(): ?MduiChunk and hasMdui(): bool on StateHandler and StateHandlerInterface. Behat scenarios cover the present and absent cases for both flows. SSOController is corrected to read the relay state from the query string only, matching the HTTP-Redirect binding specification. Links: - https://github.com/OpenConext/Stepup-gssp-bundle/issues/48 - https://github.com/OpenConext/Stepup-saml-bundle/pull/137 --- ci/qa/phpstan-baseline.neon | 8 ++++ src/Controller/SSOController.php | 4 +- src/Features/Context/GsspContext.php | 65 ++++++++++++++++++++++++++- src/Features/authentication.feature | 30 +++++++++++++ src/Features/registration.feature | 18 ++++++++ src/Service/StateHandler.php | 54 +++++++++++++++++----- src/Service/StateHandlerInterface.php | 5 +++ tests/Service/StateHandlerTest.php | 61 +++++++++++++++++++++++++ 8 files changed, 230 insertions(+), 15 deletions(-) diff --git a/ci/qa/phpstan-baseline.neon b/ci/qa/phpstan-baseline.neon index 7c51709..be89ad5 100644 --- a/ci/qa/phpstan-baseline.neon +++ b/ci/qa/phpstan-baseline.neon @@ -1,5 +1,13 @@ parameters: ignoreErrors: + - + # phpstan cannot parse the dot in PHPMD annotation names (PHPMD.ExcessiveClassComplexity). + # This is a tool-compatibility issue, not a type error. + message: '#ExcessiveClassComplexity#' + identifier: phpDoc.parseError + count: 1 + path: ../../src/Service/StateHandler.php + - message: '#^Method Surfnet\\GsspBundle\\Saml\\ResponseContext\:\:getErrorStatus\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue diff --git a/src/Controller/SSOController.php b/src/Controller/SSOController.php index ee875da..ebc478e 100644 --- a/src/Controller/SSOController.php +++ b/src/Controller/SSOController.php @@ -147,9 +147,9 @@ private function registrationAction(Request $request, ReceivedAuthnRequest $orig */ private function getRelayStateFromRequest(Request $request): string { - if (!is_string($request->get(AuthnRequest::PARAMETER_RELAY_STATE))) { + if (!is_string($request->query->get(AuthnRequest::PARAMETER_RELAY_STATE))) { return ''; } - return $request->get(AuthnRequest::PARAMETER_RELAY_STATE); + return $request->query->get(AuthnRequest::PARAMETER_RELAY_STATE); } } diff --git a/src/Features/Context/GsspContext.php b/src/Features/Context/GsspContext.php index 31ea92b..38926ed 100644 --- a/src/Features/Context/GsspContext.php +++ b/src/Features/Context/GsspContext.php @@ -47,6 +47,10 @@ use SAML2\XML\saml\NameID; use Surfnet\GsspBundle\Controller\SSOController; use Surfnet\GsspBundle\Controller\SSOReturnController; +use Surfnet\SamlBundle\SAML2\Extensions\Extensions; +use Surfnet\SamlBundle\SAML2\Extensions\GsspUserAttributesChunk; +use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; +use SAML2\XML\Chunk as SAML2Chunk; use Surfnet\GsspBundle\Logger\StepupRequestIdSariLogger; use Surfnet\GsspBundle\Saml\AssertionSigningService; use Surfnet\GsspBundle\Saml\ResponseContext; @@ -113,6 +117,8 @@ final class GsspContext implements Context private ?Exception $lastException = null; + private ?StateHandler $stateHandler = null; + /** * Every scenario we start with a clean slate. * @@ -129,7 +135,7 @@ public function bootstrapDependencies(): void $this->twigTemplate = null; // Create required dependencies. - $stateHandler = new StateHandler(new InMemoryValueStore()); + $this->stateHandler = $stateHandler = new StateHandler(new InMemoryValueStore()); $this->logger = new BufferingLogger(); $logger = new StepupRequestIdSariLogger( $this->logger, @@ -625,6 +631,30 @@ public function theIdentityProviderSetsAnError($message): void $this->registrationService->replyToServiceProvider(); } + #[Given('the AuthnRequest contains service name :serviceName')] + public function setServiceNameOnAuthnRequest(string $serviceName): void + { + $chunk = new GsspUserAttributesChunk(); + $chunk->addAttribute( + 'urn:mace:surf.nl:stepup:service-name', + 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri', + $serviceName + ); + $this->authnRequest->setExtensions([new SAML2Chunk($chunk->getValue())]); + } + + #[Then('the service name :serviceName should be stored in state')] + public function assertServiceNameStoredInState(string $serviceName): void + { + $attributes = $this->stateHandler->getGsspUserAttributes(); + Assertion::notNull($attributes, 'Expected GsspUserAttributesChunk to be present in state'); + Assertion::eq( + $serviceName, + $attributes->getAttributeValue('urn:mace:surf.nl:stepup:service-name'), + sprintf('Expected service name "%s" in state', $serviceName) + ); + } + #[Given('set the subject nameId to :nameId')] public function setTheSubjectNameIdTo(string $nameId): void { @@ -645,4 +675,37 @@ public function theReturnEndpointShouldRaiseAnException($message): void { Assertion::eq($message, $this->lastException->getMessage()); } + + #[Given('the AuthnRequest contains mdui display name :firstName for language :firstLang and :secondName for language :secondLang')] + public function setMduiDisplayNamesOnAuthnRequest(string $firstName, string $firstLang, string $secondName, string $secondLang): void + { + $chunk = new MduiChunk(); + $doc = $chunk->getValue()->ownerDocument; + $ns = 'urn:oasis:names:tc:SAML:metadata:ui'; + + foreach ([[$firstLang, $firstName], [$secondLang, $secondName]] as [$lang, $name]) { + $el = $doc->createElementNS($ns, 'mdui:DisplayName'); + $el->setAttribute('xml:lang', $lang); + $el->textContent = $name; + $chunk->getValue()->appendChild($el); + } + + $this->authnRequest->setExtensions([new SAML2Chunk($chunk->getValue())]); + } + + #[Then('the mdui display name for language :lang should be :expected in state')] + public function assertMduiDisplayNameInState(string $lang, string $expected): void + { + $mdui = $this->stateHandler->getMdui(); + Assertion::notNull($mdui, 'Expected MduiChunk to be present in state'); + $names = $mdui->getDisplayNames(); + Assertion::keyExists($names, $lang, sprintf('Expected lang "%s" in mdui display names', $lang)); + Assertion::eq($expected, $names[$lang], sprintf('Expected display name "%s" for lang "%s"', $expected, $lang)); + } + + #[Then('no mdui data should be stored in state')] + public function assertNoMduiInState(): void + { + Assertion::false($this->stateHandler->hasMdui(), 'Expected no mdui data in state'); + } } diff --git a/src/Features/authentication.feature b/src/Features/authentication.feature index 7f74ee7..a39ce00 100644 --- a/src/Features/authentication.feature +++ b/src/Features/authentication.feature @@ -72,3 +72,33 @@ Feature: When an user needs to be authenticated When the user is redirected to the identity provider sso return endpoint Then the return endpoint should raise an exception with "There is no request state present" + + Scenario: Service name from SAML extension is preserved in state during authentication + Given a normal SAML 2.0 AuthnRequest + And the AuthnRequest contains service name 'My University Portal' + And AuthnRequest is signed with sha256 + And set the subject nameId to 'unique-identifier-token' + + When the service provider sends the AuthnRequest with HTTP-Redirect binding + + Then the service name 'My University Portal' should be stored in state + + Scenario: mdui:UIInfo display names are preserved in state during authentication + Given a normal SAML 2.0 AuthnRequest + And the AuthnRequest contains mdui display name "Online learning" for language "en" and "Leeromgeving" for language "nl" + And AuthnRequest is signed with sha256 + And set the subject nameId to 'unique-identifier-token' + + When the service provider sends the AuthnRequest with HTTP-Redirect binding + + Then the mdui display name for language "en" should be "Online learning" in state + And the mdui display name for language "nl" should be "Leeromgeving" in state + + Scenario: Authentication without mdui:UIInfo does not cause an error + Given a normal SAML 2.0 AuthnRequest + And AuthnRequest is signed with sha256 + And set the subject nameId to 'unique-identifier-token' + + When the service provider sends the AuthnRequest with HTTP-Redirect binding + + Then no mdui data should be stored in state diff --git a/src/Features/registration.feature b/src/Features/registration.feature index 5311797..4534108 100644 --- a/src/Features/registration.feature +++ b/src/Features/registration.feature @@ -40,6 +40,24 @@ Feature: When an user needs to enroll for a new token | notice | /Saml response created with id ".+", request ID: ".+"/ | present | | notice | Invalidate current state and redirect user to service provider assertion consumer url "https://service_provider/saml/acu" | present | + Scenario: mdui:UIInfo display names are preserved in state during registration + Given a normal SAML 2.0 AuthnRequest + And the AuthnRequest contains mdui display name "Online learning" for language "en" and "Leeromgeving" for language "nl" + And AuthnRequest is signed with sha256 + + When the service provider sends the AuthnRequest with HTTP-Redirect binding + + Then the mdui display name for language "en" should be "Online learning" in state + And the mdui display name for language "nl" should be "Leeromgeving" in state + + Scenario: Registration without mdui:UIInfo does not cause an error + Given a normal SAML 2.0 AuthnRequest + And AuthnRequest is signed with sha256 + + When the service provider sends the AuthnRequest with HTTP-Redirect binding + + Then no mdui data should be stored in state + Scenario: When an user request the sso return endpoint without being registered the user should be redirected to the application registration endpoint Given a normal SAML 2.0 AuthnRequest And AuthnRequest is signed with sha256 diff --git a/src/Service/StateHandler.php b/src/Service/StateHandler.php index e382d19..b500a92 100644 --- a/src/Service/StateHandler.php +++ b/src/Service/StateHandler.php @@ -23,11 +23,14 @@ use SAML2\Constants; use Surfnet\GsspBundle\Exception\RuntimeException; use Surfnet\SamlBundle\SAML2\Extensions\GsspUserAttributesChunk; +use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; use Surfnet\SamlBundle\SAML2\ReceivedAuthnRequest; use TypeError; /** * Knows and preserves the integrity of the GSSP application state. + * + * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) */ final readonly class StateHandler implements StateHandlerInterface { @@ -56,6 +59,8 @@ public const GSSP_USERATTRIBUTES = 'gssp_userattributes'; + public const GSSP_MDUI = 'gssp_mdui'; + public function __construct(private ValueStore $store) { } @@ -71,10 +76,7 @@ public function saveRegistrationRequest(ReceivedAuthnRequest $authnRequest, stri ->set(self::REQUEST_TYPE, self::REQUEST_TYPE_REGISTRATION) ; - $chunk = $authnRequest->getExtensions()->getGsspUserAttributesChunk(); - if ($chunk instanceof GsspUserAttributesChunk) { - $this->setGsspUserAttributes($chunk); - } + $this->saveRequestExtensions($authnRequest); } public function saveAuthenticationRequest(ReceivedAuthnRequest $authnRequest, string $relayState): void @@ -89,6 +91,8 @@ public function saveAuthenticationRequest(ReceivedAuthnRequest $authnRequest, st ->set(self::SCOPING_REQUESTER_IDS, $authnRequest->getScopingRequesterIds()) ->set(self::REQUEST_TYPE, self::REQUEST_TYPE_AUTHENTICATION) ; + + $this->saveRequestExtensions($authnRequest); } public function saveSubjectNameId(string $nameId): StateHandlerInterface @@ -156,13 +160,31 @@ public function getSubjectNameId(): string public function getGsspUserAttributes(): ?GsspUserAttributesChunk { - if (!is_string($this->store->get(self::GSSP_USERATTRIBUTES))) { + if (!$this->store->has(self::GSSP_USERATTRIBUTES)) { + return null; + } + $xml = $this->store->get(self::GSSP_USERATTRIBUTES); + if (!is_string($xml)) { throw new TypeError(sprintf('The "%s" must be of type string', self::GSSP_USERATTRIBUTES)); } - if ($this->store->has(self::GSSP_USERATTRIBUTES)) { - return GsspUserAttributesChunk::fromXML($this->store->get(self::GSSP_USERATTRIBUTES)); + return GsspUserAttributesChunk::fromXML($xml); + } + + public function getMdui(): ?MduiChunk + { + if (!$this->store->has(self::GSSP_MDUI)) { + return null; + } + $xml = $this->store->get(self::GSSP_MDUI); + if (!is_string($xml)) { + throw new TypeError(sprintf('The "%s" must be of type string', self::GSSP_MDUI)); } - return null; + return MduiChunk::fromXML($xml); + } + + public function hasMdui(): bool + { + return $this->store->has(self::GSSP_MDUI); } public function hasSubjectNameId(): bool @@ -237,9 +259,19 @@ private function setRequestId(string $originalRequestId): self return $this->set(self::REQUEST_ID, $originalRequestId); } - private function setGsspUserAttributes(GsspUserAttributesChunk $chunk): self + private function saveRequestExtensions(ReceivedAuthnRequest $authnRequest): void { - return $this->set(self::GSSP_USERATTRIBUTES, $chunk->toXML()); + $extensions = $authnRequest->getExtensions(); + + $chunk = $extensions->getGsspUserAttributesChunk(); + if ($chunk instanceof GsspUserAttributesChunk) { + $this->set(self::GSSP_USERATTRIBUTES, $chunk->toXML()); + } + + $mduiChunk = $extensions->getMduiChunk(); + if ($mduiChunk instanceof MduiChunk) { + $this->set(self::GSSP_MDUI, $mduiChunk->toXML()); + } } private function set(string $key, mixed $value): self @@ -250,9 +282,7 @@ private function set(string $key, mixed $value): self private function assertRequestTypeNotSet(): void { - // Request_type may not be set if ($this->store->has(self::REQUEST_TYPE)) { - // If it is set, it must be of type string. if (!is_string($this->store->get(self::REQUEST_TYPE))) { throw new TypeError(sprintf('The "%s" must be of type string', self::REQUEST_TYPE)); } diff --git a/src/Service/StateHandlerInterface.php b/src/Service/StateHandlerInterface.php index 9576631..0085792 100644 --- a/src/Service/StateHandlerInterface.php +++ b/src/Service/StateHandlerInterface.php @@ -21,6 +21,7 @@ namespace Surfnet\GsspBundle\Service; use Surfnet\SamlBundle\SAML2\Extensions\GsspUserAttributesChunk; +use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; use Surfnet\SamlBundle\SAML2\ReceivedAuthnRequest; /** @@ -56,6 +57,10 @@ public function getScopingRequesterIds(): array; public function getGsspUserAttributes(): ?GsspUserAttributesChunk; + public function getMdui(): ?MduiChunk; + + public function hasMdui(): bool; + /* * Is the current request type registration flow? */ diff --git a/tests/Service/StateHandlerTest.php b/tests/Service/StateHandlerTest.php index 27f72b0..488b0f4 100644 --- a/tests/Service/StateHandlerTest.php +++ b/tests/Service/StateHandlerTest.php @@ -20,8 +20,10 @@ namespace Surfnet\GsspBundle\Service; +use DOMDocument; use Mockery as m; use PHPUnit\Framework\TestCase; +use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; class StateHandlerTest extends TestCase { @@ -67,4 +69,63 @@ public function test_can_get_scoping_requester_ids() ->andReturn(['a', 'b', 'c']); $this->assertEquals(['a', 'b', 'c'], $this->handler->getScopingRequesterIds()); } + + public function test_has_mdui_returns_false_when_absent(): void + { + $this->valueStore + ->shouldReceive('has') + ->with('gssp_mdui') + ->andReturnFalse(); + $this->assertFalse($this->handler->hasMdui()); + } + + public function test_has_mdui_returns_true_when_present(): void + { + $this->valueStore + ->shouldReceive('has') + ->with('gssp_mdui') + ->andReturnTrue(); + $this->assertTrue($this->handler->hasMdui()); + } + + public function test_get_mdui_returns_null_when_absent(): void + { + $this->valueStore + ->shouldReceive('has') + ->with('gssp_mdui') + ->andReturnFalse(); + $this->assertNull($this->handler->getMdui()); + } + + public function test_get_mdui_returns_chunk_with_display_names(): void + { + $chunk = $this->buildMduiChunk(['en' => 'My Service', 'nl' => 'Mijn Dienst']); + + $this->valueStore + ->shouldReceive('has') + ->with('gssp_mdui') + ->andReturnTrue(); + $this->valueStore + ->shouldReceive('get') + ->with('gssp_mdui') + ->andReturn($chunk->toXML()); + + $result = $this->handler->getMdui(); + $this->assertInstanceOf(MduiChunk::class, $result); + $this->assertEquals(['en' => 'My Service', 'nl' => 'Mijn Dienst'], $result->getDisplayNames()); + } + + private function buildMduiChunk(array $displayNames): MduiChunk + { + $chunk = new MduiChunk(); + $doc = $chunk->getValue()->ownerDocument; + $ns = 'urn:oasis:names:tc:SAML:metadata:ui'; + foreach ($displayNames as $lang => $name) { + $el = $doc->createElementNS($ns, 'mdui:DisplayName'); + $el->setAttribute('xml:lang', $lang); + $el->textContent = $name; + $chunk->getValue()->appendChild($el); + } + return $chunk; + } } From 604d096583e0778d569584193605c216bb2d14d7 Mon Sep 17 00:00:00 2001 From: Kay Joosten Date: Thu, 2 Jul 2026 09:34:55 +0200 Subject: [PATCH 02/18] Point surfnet/stepup-saml-bundle to feature branch for integration testing Prior to this change, composer.json required surfnet/stepup-saml-bundle ^7.0 from packagist, which does not yet contain MduiChunk. This caused phpstan to fail with class-not-found errors for all mdui-related symbols, blocking CI. This change adds a VCS repository pointing to the GitHub source and pins the requirement to the feature branch that implements MduiChunk. This is temporary and must be reverted to a packagist version constraint once the saml-bundle pull request is merged and a new release is tagged. Links: - https://github.com/OpenConext/Stepup-saml-bundle/pull/137 --- composer.json | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 5ad3b82..dab21aa 100644 --- a/composer.json +++ b/composer.json @@ -3,6 +3,14 @@ "license": "Apache-2.0", "description": "A Symfony 6 bundle to aid the creation of GSSP (Generic SAML Step-up Provider) device support.", "type": "symfony-bundle", + "minimum-stability": "dev", + "prefer-stable": true, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/OpenConext/Stepup-saml-bundle" + } + ], "autoload": { "psr-4": { "Surfnet\\GsspBundle\\": "src" @@ -17,7 +25,7 @@ "php": "^8.2", "ext-openssl": "*", "beberlei/assert": "^3", - "surfnet/stepup-saml-bundle": "^7.0", + "surfnet/stepup-saml-bundle": "dev-feature/issue-48-mdui-chunk as 7.0.99", "symfony/dependency-injection": "^7.4", "symfony/framework-bundle": "^7.4", "symfony/monolog-bundle": "^4.0" @@ -68,7 +76,8 @@ "config": { "sort-packages": true, "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true + "dealerdirect/phpcodesniffer-composer-installer": true, + "simplesamlphp/composer-xmlprovider-installer": false } } } From d9c1b2d1d1eaa32d7e74d20f543937eb293f4378 Mon Sep 17 00:00:00 2001 From: Kay Joosten Date: Thu, 2 Jul 2026 11:28:10 +0200 Subject: [PATCH 03/18] Expose mdui:UIInfo via AuthenticationService::getMdui() Add public getMdui(): ?MduiChunk method to the AuthenticationService interface and implement it in StateBasedAuthenticationService to expose the mdui:UIInfo extension data that is already preserved in the underlying StateHandler. --- src/Service/AuthenticationService.php | 3 +++ .../StateBasedAuthenticationService.php | 6 +++++ .../StateBasedAuthenticationServiceTest.php | 26 +++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/src/Service/AuthenticationService.php b/src/Service/AuthenticationService.php index f69f8f8..690d482 100644 --- a/src/Service/AuthenticationService.php +++ b/src/Service/AuthenticationService.php @@ -22,6 +22,7 @@ use SAML2\Constants; use Surfnet\SamlBundle\SAML2\Extensions\GsspUserAttributesChunk; +use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; use Symfony\Component\HttpFoundation\Response; /** @@ -89,4 +90,6 @@ public function getIssuer(): string; public function getScopingRequesterIds(): array; public function getGsspUserAttributes(): ?GsspUserAttributesChunk; + + public function getMdui(): ?MduiChunk; } diff --git a/src/Service/StateBasedAuthenticationService.php b/src/Service/StateBasedAuthenticationService.php index bb78b5b..a341bce 100644 --- a/src/Service/StateBasedAuthenticationService.php +++ b/src/Service/StateBasedAuthenticationService.php @@ -24,6 +24,7 @@ use SAML2\Constants; use Surfnet\GsspBundle\Exception\RuntimeException; use Surfnet\SamlBundle\SAML2\Extensions\GsspUserAttributesChunk; +use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\Routing\RouterInterface; @@ -111,4 +112,9 @@ public function getGsspUserAttributes(): ?GsspUserAttributesChunk { return $this->stateHandler->getGsspUserAttributes(); } + + public function getMdui(): ?MduiChunk + { + return $this->stateHandler->getMdui(); + } } diff --git a/tests/Service/StateBasedAuthenticationServiceTest.php b/tests/Service/StateBasedAuthenticationServiceTest.php index 7f56574..0527455 100644 --- a/tests/Service/StateBasedAuthenticationServiceTest.php +++ b/tests/Service/StateBasedAuthenticationServiceTest.php @@ -24,6 +24,7 @@ use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; use Surfnet\GsspBundle\Exception\RuntimeException; +use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; use Symfony\Component\Routing\RouterInterface; class StateBasedAuthenticationServiceTest extends TestCase @@ -97,4 +98,29 @@ public function test_can_request_scoping_requester_ids_when_present() ); $this->assertEquals(['a', 'b', 'c'], $authenticationService->getScopingRequesterIds()); } + + public function test_getMdui_returns_mdui_chunk_when_present() + { + $mduiChunk = m::mock(MduiChunk::class); + $stateHandler = m::mock(StateHandlerInterface::class); + $stateHandler->shouldReceive('getMdui')->andReturn($mduiChunk); + $authenticationService = new StateBasedAuthenticationService( + $stateHandler, + m::mock(RouterInterface::class), + m::mock(LoggerInterface::class) + ); + $this->assertSame($mduiChunk, $authenticationService->getMdui()); + } + + public function test_getMdui_returns_null_when_not_present() + { + $stateHandler = m::mock(StateHandlerInterface::class); + $stateHandler->shouldReceive('getMdui')->andReturnNull(); + $authenticationService = new StateBasedAuthenticationService( + $stateHandler, + m::mock(RouterInterface::class), + m::mock(LoggerInterface::class) + ); + $this->assertNull($authenticationService->getMdui()); + } } From bd8d55bf169095a9fbdf6e214ee4214da1d4922e Mon Sep 17 00:00:00 2001 From: Kay Joosten Date: Thu, 2 Jul 2026 11:31:26 +0200 Subject: [PATCH 04/18] Add getMdui() accessor to RegistrationService Mirror the prior AuthenticationService change to the registration side: - Add getMdui(): ?MduiChunk interface method to RegistrationService - Implement in StateBasedRegistrationService, delegating to stateHandler - Add two test cases for presence and absence of MduiChunk --- src/Service/RegistrationService.php | 3 +++ src/Service/StateBasedRegistrationService.php | 6 +++++ .../StateBasedRegistrationServiceTest.php | 27 +++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/src/Service/RegistrationService.php b/src/Service/RegistrationService.php index 43e9d33..9a54b58 100644 --- a/src/Service/RegistrationService.php +++ b/src/Service/RegistrationService.php @@ -21,6 +21,7 @@ namespace Surfnet\GsspBundle\Service; use SAML2\Constants; +use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; use Symfony\Component\HttpFoundation\Response; /** @@ -62,6 +63,8 @@ public function register(string $subjectNameId): void; */ public function isRegistered(): bool; + public function getMdui(): ?MduiChunk; + public function reject(string $message, string $subCode = Constants::STATUS_AUTHN_FAILED): void; /* diff --git a/src/Service/StateBasedRegistrationService.php b/src/Service/StateBasedRegistrationService.php index ad8337d..def307d 100644 --- a/src/Service/StateBasedRegistrationService.php +++ b/src/Service/StateBasedRegistrationService.php @@ -23,6 +23,7 @@ use Psr\Log\LoggerInterface; use SAML2\Constants; use Surfnet\GsspBundle\Exception\RuntimeException; +use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\Routing\RouterInterface; @@ -59,6 +60,11 @@ public function isRegistered(): bool return $this->stateHandler->hasSubjectNameId(); } + public function getMdui(): ?MduiChunk + { + return $this->stateHandler->getMdui(); + } + public function registrationRequired(): bool { return $this->stateHandler->isRequestTypeRegistration(); diff --git a/tests/Service/StateBasedRegistrationServiceTest.php b/tests/Service/StateBasedRegistrationServiceTest.php index 924ffdd..48bb035 100644 --- a/tests/Service/StateBasedRegistrationServiceTest.php +++ b/tests/Service/StateBasedRegistrationServiceTest.php @@ -20,9 +20,11 @@ namespace Surfnet\GsspBundle\Service; +use Mockery as m; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; use Surfnet\GsspBundle\Exception\RuntimeException; +use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; use Symfony\Component\Routing\RouterInterface; class StateBasedRegistrationServiceTest extends TestCase @@ -73,4 +75,29 @@ public function testIsRegisteredShouldReturnFalseWhenRegistered() ); $this->assertTrue($registrationService->isRegistered()); } + + public function test_getMdui_returns_mdui_chunk_when_present() + { + $mduiChunk = m::mock(MduiChunk::class); + $stateHandler = m::mock(StateHandlerInterface::class); + $stateHandler->shouldReceive('getMdui')->andReturn($mduiChunk); + $registrationService = new StateBasedRegistrationService( + $stateHandler, + m::mock(RouterInterface::class), + m::mock(LoggerInterface::class) + ); + $this->assertSame($mduiChunk, $registrationService->getMdui()); + } + + public function test_getMdui_returns_null_when_not_present() + { + $stateHandler = m::mock(StateHandlerInterface::class); + $stateHandler->shouldReceive('getMdui')->andReturnNull(); + $registrationService = new StateBasedRegistrationService( + $stateHandler, + m::mock(RouterInterface::class), + m::mock(LoggerInterface::class) + ); + $this->assertNull($registrationService->getMdui()); + } } From a6d0c38e4fec15afebd09ebb7f6f6b903504131d Mon Sep 17 00:00:00 2001 From: Kay Joosten Date: Fri, 3 Jul 2026 08:58:09 +0200 Subject: [PATCH 05/18] Clarify pre-existing service-name scenario is unrelated to mdui:UIInfo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Regression coverage for the saveRequestExtensions() refactor, not part of the mdui feature itself — noted per review to avoid future readers assuming otherwise. --- src/Features/authentication.feature | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Features/authentication.feature b/src/Features/authentication.feature index a39ce00..0ddf9b6 100644 --- a/src/Features/authentication.feature +++ b/src/Features/authentication.feature @@ -73,6 +73,9 @@ Feature: When an user needs to be authenticated When the user is redirected to the identity provider sso return endpoint Then the return endpoint should raise an exception with "There is no request state present" + # Pre-existing GsspUserAttributes service-name path (urn:mace:surf.nl:stepup:service-name), + # not the mdui:UIInfo mechanism added in this PR. Kept here as regression coverage for the + # saveRequestExtensions() refactor, which now handles both extension types from one call site. Scenario: Service name from SAML extension is preserved in state during authentication Given a normal SAML 2.0 AuthnRequest And the AuthnRequest contains service name 'My University Portal' From 478ec76e5badd1c569f8c8a4875660787da74f28 Mon Sep 17 00:00:00 2001 From: Kay Joosten Date: Fri, 3 Jul 2026 09:29:18 +0200 Subject: [PATCH 06/18] Document composer audit ignores for transitive simplesamlphp/saml2 advisories Mirrors the same audit-ignore config added in Stepup-saml-bundle PR #137, needed here too since composer's advisory-blocking applies per root package -- each repo that resolves simplesamlphp/saml2 as part of its own composer install needs its own ignore entries, even though the underlying package and its advisories are identical. --- composer.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/composer.json b/composer.json index dab21aa..daa3b13 100644 --- a/composer.json +++ b/composer.json @@ -78,6 +78,14 @@ "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true, "simplesamlphp/composer-xmlprovider-installer": false + }, + "audit": { + "ignore": { + "PKSA-1fc7-xrz7-vw78": "GHSA-5cjr-mxj5-wmrx: DoS via XPath Transform in ds:Signature processing (transitive via surfnet/stepup-saml-bundle -> simplesamlphp/saml2). No patched simplesamlphp/saml2 4.x release exists or is planned. Mitigated in surfnet/stepup-saml-bundle by Surfnet\\SamlBundle\\Signing\\SignatureTransformGuard, called from PostBinding::processResponse() before every signature verification. See Stepup-saml-bundle PR #137.", + "PKSA-yk3g-3g3t-ts6q": "GHSA-6929-8p9f-26jx: TLS validator confusion in HTTP-Artifact binding resolution (transitive via surfnet/stepup-saml-bundle -> simplesamlphp/saml2). Neither this bundle nor surfnet/stepup-saml-bundle implement HTTP-Artifact binding; the affected code path is unreachable.", + "PKSA-rxdv-j1j4-96fj": "GHSA-46r4-f8gj-xg56: HTTP-Redirect signature verification bypass, fixed in simplesamlphp/saml2 >=4.16.16. Resolved version is 4.19.2, already patched.", + "PKSA-1983-c8jn-trgm": "GHSA-pxm4-r5ph-q2m2: XXE in SAML message parsing, fixed in simplesamlphp/saml2 >=4.6.14. Resolved version is 4.19.2, already patched." + } } } } From c1c8afd518b0a2573456d538f1ee3812226d4262 Mon Sep 17 00:00:00 2001 From: Kay Joosten Date: Wed, 8 Jul 2026 11:25:45 +0200 Subject: [PATCH 07/18] Drop stale composer audit ignores for already-patched saml2 advisories PKSA-rxdv-j1j4-96fj and PKSA-1983-c8jn-trgm targeted simplesamlphp/saml2 versions below 4.16.16 and 4.6.14 respectively. The resolved version here is 4.19.x, well past both fixes, so composer audit no longer flags them and the ignore entries were dead weight - noise that wrongly implies the vulnerabilities are still present and mitigated by us. Kept the two entries that still apply (PKSA-1fc7, PKSA-yk3g), which have no upstream fix and are documented as mitigated/unreachable. --- composer.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/composer.json b/composer.json index daa3b13..91c539d 100644 --- a/composer.json +++ b/composer.json @@ -82,9 +82,7 @@ "audit": { "ignore": { "PKSA-1fc7-xrz7-vw78": "GHSA-5cjr-mxj5-wmrx: DoS via XPath Transform in ds:Signature processing (transitive via surfnet/stepup-saml-bundle -> simplesamlphp/saml2). No patched simplesamlphp/saml2 4.x release exists or is planned. Mitigated in surfnet/stepup-saml-bundle by Surfnet\\SamlBundle\\Signing\\SignatureTransformGuard, called from PostBinding::processResponse() before every signature verification. See Stepup-saml-bundle PR #137.", - "PKSA-yk3g-3g3t-ts6q": "GHSA-6929-8p9f-26jx: TLS validator confusion in HTTP-Artifact binding resolution (transitive via surfnet/stepup-saml-bundle -> simplesamlphp/saml2). Neither this bundle nor surfnet/stepup-saml-bundle implement HTTP-Artifact binding; the affected code path is unreachable.", - "PKSA-rxdv-j1j4-96fj": "GHSA-46r4-f8gj-xg56: HTTP-Redirect signature verification bypass, fixed in simplesamlphp/saml2 >=4.16.16. Resolved version is 4.19.2, already patched.", - "PKSA-1983-c8jn-trgm": "GHSA-pxm4-r5ph-q2m2: XXE in SAML message parsing, fixed in simplesamlphp/saml2 >=4.6.14. Resolved version is 4.19.2, already patched." + "PKSA-yk3g-3g3t-ts6q": "GHSA-6929-8p9f-26jx: TLS validator confusion in HTTP-Artifact binding resolution (transitive via surfnet/stepup-saml-bundle -> simplesamlphp/saml2). Neither this bundle nor surfnet/stepup-saml-bundle implement HTTP-Artifact binding; the affected code path is unreachable." } } } From ab0e7139197f1e304fd97624f44bcb69262a88ae Mon Sep 17 00:00:00 2001 From: Kay Joosten Date: Wed, 8 Jul 2026 13:49:57 +0200 Subject: [PATCH 08/18] Remove audit.ignore block entirely, advisories are already patched Both remaining ignored advisories (PKSA-1fc7 XPath DoS, PKSA-yk3g HTTP-Artifact TLS confusion) claimed no patched simplesamlphp/saml2 release existed. That's no longer true: comparing the v4.19.2..v4.19.3 tags shows both fixes were backported and released, and our resolved version is 4.19.3. The audit.ignore config key only affects a dev manually running composer audit locally - CI's daily-security-check.yml uses symfonycorp/security-checker-action, a separate tool that doesn't read this config at all, so removing it doesn't change CI behaviour. Composer's own advisory feed still reports a coarse affected-version range that hasn't caught up with the precise per-branch patch, so `composer audit` may show these two as findings again until that feed updates - that's noise in the advisory database, not a real gap. --- composer.json | 6 ------ 1 file changed, 6 deletions(-) diff --git a/composer.json b/composer.json index 91c539d..dab21aa 100644 --- a/composer.json +++ b/composer.json @@ -78,12 +78,6 @@ "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true, "simplesamlphp/composer-xmlprovider-installer": false - }, - "audit": { - "ignore": { - "PKSA-1fc7-xrz7-vw78": "GHSA-5cjr-mxj5-wmrx: DoS via XPath Transform in ds:Signature processing (transitive via surfnet/stepup-saml-bundle -> simplesamlphp/saml2). No patched simplesamlphp/saml2 4.x release exists or is planned. Mitigated in surfnet/stepup-saml-bundle by Surfnet\\SamlBundle\\Signing\\SignatureTransformGuard, called from PostBinding::processResponse() before every signature verification. See Stepup-saml-bundle PR #137.", - "PKSA-yk3g-3g3t-ts6q": "GHSA-6929-8p9f-26jx: TLS validator confusion in HTTP-Artifact binding resolution (transitive via surfnet/stepup-saml-bundle -> simplesamlphp/saml2). Neither this bundle nor surfnet/stepup-saml-bundle implement HTTP-Artifact binding; the affected code path is unreachable." - } } } } From efdd21ec034b8cbe98bbe277a8a04b1d23265875 Mon Sep 17 00:00:00 2001 From: Kay Joosten Date: Wed, 8 Jul 2026 13:55:43 +0200 Subject: [PATCH 09/18] Revert "Remove audit.ignore block entirely, advisories are already patched" This reverts commit ab0e7139197f1e304fd97624f44bcb69262a88ae. --- composer.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/composer.json b/composer.json index dab21aa..91c539d 100644 --- a/composer.json +++ b/composer.json @@ -78,6 +78,12 @@ "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true, "simplesamlphp/composer-xmlprovider-installer": false + }, + "audit": { + "ignore": { + "PKSA-1fc7-xrz7-vw78": "GHSA-5cjr-mxj5-wmrx: DoS via XPath Transform in ds:Signature processing (transitive via surfnet/stepup-saml-bundle -> simplesamlphp/saml2). No patched simplesamlphp/saml2 4.x release exists or is planned. Mitigated in surfnet/stepup-saml-bundle by Surfnet\\SamlBundle\\Signing\\SignatureTransformGuard, called from PostBinding::processResponse() before every signature verification. See Stepup-saml-bundle PR #137.", + "PKSA-yk3g-3g3t-ts6q": "GHSA-6929-8p9f-26jx: TLS validator confusion in HTTP-Artifact binding resolution (transitive via surfnet/stepup-saml-bundle -> simplesamlphp/saml2). Neither this bundle nor surfnet/stepup-saml-bundle implement HTTP-Artifact binding; the affected code path is unreachable." + } } } } From c6f1b2ac686a213c98e63982d9d704c496f8d50e Mon Sep 17 00:00:00 2001 From: Kay Joosten Date: Fri, 10 Jul 2026 13:09:18 +0200 Subject: [PATCH 10/18] Preserve and expose mdui:UIInfo GSSP apps could not read the mdui:UIInfo data that arrives with proxied AuthnRequests, so they had to fall back to less accurate service naming or duplicate request parsing outside the bundle. Persist the UIInfo chunk in session state for both authentication and registration, then expose it through the public service interfaces that consuming applications already depend on. - add coverage for present and absent UIInfo data in both flows - centralize service-name resolution and formatting for consumers - pin the unreleased stepup-saml-bundle branch needed for integration until the upstream change is released Resolves: #48 --- ci/qa/phpstan-baseline.neon | 8 ++ composer.json | 19 ++- src/Controller/SSOController.php | 4 +- src/Features/Context/GsspContext.php | 65 +++++++++- src/Features/authentication.feature | 33 ++++++ src/Features/registration.feature | 18 +++ src/Service/AuthenticationService.php | 3 + src/Service/RegistrationService.php | 3 + .../ServiceName/ServiceNameFormatter.php | 37 ++++++ .../ServiceName/ServiceNameResolver.php | 57 +++++++++ .../StateBasedAuthenticationService.php | 6 + src/Service/StateBasedRegistrationService.php | 6 + src/Service/StateHandler.php | 54 +++++++-- src/Service/StateHandlerInterface.php | 5 + .../ServiceName/ServiceNameFormatterTest.php | 63 ++++++++++ .../ServiceName/ServiceNameResolverTest.php | 112 ++++++++++++++++++ .../StateBasedAuthenticationServiceTest.php | 26 ++++ .../StateBasedRegistrationServiceTest.php | 27 +++++ tests/Service/StateHandlerTest.php | 61 ++++++++++ 19 files changed, 590 insertions(+), 17 deletions(-) create mode 100644 src/Service/ServiceName/ServiceNameFormatter.php create mode 100644 src/Service/ServiceName/ServiceNameResolver.php create mode 100644 tests/Service/ServiceName/ServiceNameFormatterTest.php create mode 100644 tests/Service/ServiceName/ServiceNameResolverTest.php diff --git a/ci/qa/phpstan-baseline.neon b/ci/qa/phpstan-baseline.neon index 7c51709..be89ad5 100644 --- a/ci/qa/phpstan-baseline.neon +++ b/ci/qa/phpstan-baseline.neon @@ -1,5 +1,13 @@ parameters: ignoreErrors: + - + # phpstan cannot parse the dot in PHPMD annotation names (PHPMD.ExcessiveClassComplexity). + # This is a tool-compatibility issue, not a type error. + message: '#ExcessiveClassComplexity#' + identifier: phpDoc.parseError + count: 1 + path: ../../src/Service/StateHandler.php + - message: '#^Method Surfnet\\GsspBundle\\Saml\\ResponseContext\:\:getErrorStatus\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue diff --git a/composer.json b/composer.json index 5ad3b82..91c539d 100644 --- a/composer.json +++ b/composer.json @@ -3,6 +3,14 @@ "license": "Apache-2.0", "description": "A Symfony 6 bundle to aid the creation of GSSP (Generic SAML Step-up Provider) device support.", "type": "symfony-bundle", + "minimum-stability": "dev", + "prefer-stable": true, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/OpenConext/Stepup-saml-bundle" + } + ], "autoload": { "psr-4": { "Surfnet\\GsspBundle\\": "src" @@ -17,7 +25,7 @@ "php": "^8.2", "ext-openssl": "*", "beberlei/assert": "^3", - "surfnet/stepup-saml-bundle": "^7.0", + "surfnet/stepup-saml-bundle": "dev-feature/issue-48-mdui-chunk as 7.0.99", "symfony/dependency-injection": "^7.4", "symfony/framework-bundle": "^7.4", "symfony/monolog-bundle": "^4.0" @@ -68,7 +76,14 @@ "config": { "sort-packages": true, "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true + "dealerdirect/phpcodesniffer-composer-installer": true, + "simplesamlphp/composer-xmlprovider-installer": false + }, + "audit": { + "ignore": { + "PKSA-1fc7-xrz7-vw78": "GHSA-5cjr-mxj5-wmrx: DoS via XPath Transform in ds:Signature processing (transitive via surfnet/stepup-saml-bundle -> simplesamlphp/saml2). No patched simplesamlphp/saml2 4.x release exists or is planned. Mitigated in surfnet/stepup-saml-bundle by Surfnet\\SamlBundle\\Signing\\SignatureTransformGuard, called from PostBinding::processResponse() before every signature verification. See Stepup-saml-bundle PR #137.", + "PKSA-yk3g-3g3t-ts6q": "GHSA-6929-8p9f-26jx: TLS validator confusion in HTTP-Artifact binding resolution (transitive via surfnet/stepup-saml-bundle -> simplesamlphp/saml2). Neither this bundle nor surfnet/stepup-saml-bundle implement HTTP-Artifact binding; the affected code path is unreachable." + } } } } diff --git a/src/Controller/SSOController.php b/src/Controller/SSOController.php index ee875da..ebc478e 100644 --- a/src/Controller/SSOController.php +++ b/src/Controller/SSOController.php @@ -147,9 +147,9 @@ private function registrationAction(Request $request, ReceivedAuthnRequest $orig */ private function getRelayStateFromRequest(Request $request): string { - if (!is_string($request->get(AuthnRequest::PARAMETER_RELAY_STATE))) { + if (!is_string($request->query->get(AuthnRequest::PARAMETER_RELAY_STATE))) { return ''; } - return $request->get(AuthnRequest::PARAMETER_RELAY_STATE); + return $request->query->get(AuthnRequest::PARAMETER_RELAY_STATE); } } diff --git a/src/Features/Context/GsspContext.php b/src/Features/Context/GsspContext.php index 31ea92b..38926ed 100644 --- a/src/Features/Context/GsspContext.php +++ b/src/Features/Context/GsspContext.php @@ -47,6 +47,10 @@ use SAML2\XML\saml\NameID; use Surfnet\GsspBundle\Controller\SSOController; use Surfnet\GsspBundle\Controller\SSOReturnController; +use Surfnet\SamlBundle\SAML2\Extensions\Extensions; +use Surfnet\SamlBundle\SAML2\Extensions\GsspUserAttributesChunk; +use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; +use SAML2\XML\Chunk as SAML2Chunk; use Surfnet\GsspBundle\Logger\StepupRequestIdSariLogger; use Surfnet\GsspBundle\Saml\AssertionSigningService; use Surfnet\GsspBundle\Saml\ResponseContext; @@ -113,6 +117,8 @@ final class GsspContext implements Context private ?Exception $lastException = null; + private ?StateHandler $stateHandler = null; + /** * Every scenario we start with a clean slate. * @@ -129,7 +135,7 @@ public function bootstrapDependencies(): void $this->twigTemplate = null; // Create required dependencies. - $stateHandler = new StateHandler(new InMemoryValueStore()); + $this->stateHandler = $stateHandler = new StateHandler(new InMemoryValueStore()); $this->logger = new BufferingLogger(); $logger = new StepupRequestIdSariLogger( $this->logger, @@ -625,6 +631,30 @@ public function theIdentityProviderSetsAnError($message): void $this->registrationService->replyToServiceProvider(); } + #[Given('the AuthnRequest contains service name :serviceName')] + public function setServiceNameOnAuthnRequest(string $serviceName): void + { + $chunk = new GsspUserAttributesChunk(); + $chunk->addAttribute( + 'urn:mace:surf.nl:stepup:service-name', + 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri', + $serviceName + ); + $this->authnRequest->setExtensions([new SAML2Chunk($chunk->getValue())]); + } + + #[Then('the service name :serviceName should be stored in state')] + public function assertServiceNameStoredInState(string $serviceName): void + { + $attributes = $this->stateHandler->getGsspUserAttributes(); + Assertion::notNull($attributes, 'Expected GsspUserAttributesChunk to be present in state'); + Assertion::eq( + $serviceName, + $attributes->getAttributeValue('urn:mace:surf.nl:stepup:service-name'), + sprintf('Expected service name "%s" in state', $serviceName) + ); + } + #[Given('set the subject nameId to :nameId')] public function setTheSubjectNameIdTo(string $nameId): void { @@ -645,4 +675,37 @@ public function theReturnEndpointShouldRaiseAnException($message): void { Assertion::eq($message, $this->lastException->getMessage()); } + + #[Given('the AuthnRequest contains mdui display name :firstName for language :firstLang and :secondName for language :secondLang')] + public function setMduiDisplayNamesOnAuthnRequest(string $firstName, string $firstLang, string $secondName, string $secondLang): void + { + $chunk = new MduiChunk(); + $doc = $chunk->getValue()->ownerDocument; + $ns = 'urn:oasis:names:tc:SAML:metadata:ui'; + + foreach ([[$firstLang, $firstName], [$secondLang, $secondName]] as [$lang, $name]) { + $el = $doc->createElementNS($ns, 'mdui:DisplayName'); + $el->setAttribute('xml:lang', $lang); + $el->textContent = $name; + $chunk->getValue()->appendChild($el); + } + + $this->authnRequest->setExtensions([new SAML2Chunk($chunk->getValue())]); + } + + #[Then('the mdui display name for language :lang should be :expected in state')] + public function assertMduiDisplayNameInState(string $lang, string $expected): void + { + $mdui = $this->stateHandler->getMdui(); + Assertion::notNull($mdui, 'Expected MduiChunk to be present in state'); + $names = $mdui->getDisplayNames(); + Assertion::keyExists($names, $lang, sprintf('Expected lang "%s" in mdui display names', $lang)); + Assertion::eq($expected, $names[$lang], sprintf('Expected display name "%s" for lang "%s"', $expected, $lang)); + } + + #[Then('no mdui data should be stored in state')] + public function assertNoMduiInState(): void + { + Assertion::false($this->stateHandler->hasMdui(), 'Expected no mdui data in state'); + } } diff --git a/src/Features/authentication.feature b/src/Features/authentication.feature index 7f74ee7..0ddf9b6 100644 --- a/src/Features/authentication.feature +++ b/src/Features/authentication.feature @@ -72,3 +72,36 @@ Feature: When an user needs to be authenticated When the user is redirected to the identity provider sso return endpoint Then the return endpoint should raise an exception with "There is no request state present" + + # Pre-existing GsspUserAttributes service-name path (urn:mace:surf.nl:stepup:service-name), + # not the mdui:UIInfo mechanism added in this PR. Kept here as regression coverage for the + # saveRequestExtensions() refactor, which now handles both extension types from one call site. + Scenario: Service name from SAML extension is preserved in state during authentication + Given a normal SAML 2.0 AuthnRequest + And the AuthnRequest contains service name 'My University Portal' + And AuthnRequest is signed with sha256 + And set the subject nameId to 'unique-identifier-token' + + When the service provider sends the AuthnRequest with HTTP-Redirect binding + + Then the service name 'My University Portal' should be stored in state + + Scenario: mdui:UIInfo display names are preserved in state during authentication + Given a normal SAML 2.0 AuthnRequest + And the AuthnRequest contains mdui display name "Online learning" for language "en" and "Leeromgeving" for language "nl" + And AuthnRequest is signed with sha256 + And set the subject nameId to 'unique-identifier-token' + + When the service provider sends the AuthnRequest with HTTP-Redirect binding + + Then the mdui display name for language "en" should be "Online learning" in state + And the mdui display name for language "nl" should be "Leeromgeving" in state + + Scenario: Authentication without mdui:UIInfo does not cause an error + Given a normal SAML 2.0 AuthnRequest + And AuthnRequest is signed with sha256 + And set the subject nameId to 'unique-identifier-token' + + When the service provider sends the AuthnRequest with HTTP-Redirect binding + + Then no mdui data should be stored in state diff --git a/src/Features/registration.feature b/src/Features/registration.feature index 5311797..4534108 100644 --- a/src/Features/registration.feature +++ b/src/Features/registration.feature @@ -40,6 +40,24 @@ Feature: When an user needs to enroll for a new token | notice | /Saml response created with id ".+", request ID: ".+"/ | present | | notice | Invalidate current state and redirect user to service provider assertion consumer url "https://service_provider/saml/acu" | present | + Scenario: mdui:UIInfo display names are preserved in state during registration + Given a normal SAML 2.0 AuthnRequest + And the AuthnRequest contains mdui display name "Online learning" for language "en" and "Leeromgeving" for language "nl" + And AuthnRequest is signed with sha256 + + When the service provider sends the AuthnRequest with HTTP-Redirect binding + + Then the mdui display name for language "en" should be "Online learning" in state + And the mdui display name for language "nl" should be "Leeromgeving" in state + + Scenario: Registration without mdui:UIInfo does not cause an error + Given a normal SAML 2.0 AuthnRequest + And AuthnRequest is signed with sha256 + + When the service provider sends the AuthnRequest with HTTP-Redirect binding + + Then no mdui data should be stored in state + Scenario: When an user request the sso return endpoint without being registered the user should be redirected to the application registration endpoint Given a normal SAML 2.0 AuthnRequest And AuthnRequest is signed with sha256 diff --git a/src/Service/AuthenticationService.php b/src/Service/AuthenticationService.php index f69f8f8..690d482 100644 --- a/src/Service/AuthenticationService.php +++ b/src/Service/AuthenticationService.php @@ -22,6 +22,7 @@ use SAML2\Constants; use Surfnet\SamlBundle\SAML2\Extensions\GsspUserAttributesChunk; +use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; use Symfony\Component\HttpFoundation\Response; /** @@ -89,4 +90,6 @@ public function getIssuer(): string; public function getScopingRequesterIds(): array; public function getGsspUserAttributes(): ?GsspUserAttributesChunk; + + public function getMdui(): ?MduiChunk; } diff --git a/src/Service/RegistrationService.php b/src/Service/RegistrationService.php index 43e9d33..9a54b58 100644 --- a/src/Service/RegistrationService.php +++ b/src/Service/RegistrationService.php @@ -21,6 +21,7 @@ namespace Surfnet\GsspBundle\Service; use SAML2\Constants; +use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; use Symfony\Component\HttpFoundation\Response; /** @@ -62,6 +63,8 @@ public function register(string $subjectNameId): void; */ public function isRegistered(): bool; + public function getMdui(): ?MduiChunk; + public function reject(string $message, string $subCode = Constants::STATUS_AUTHN_FAILED): void; /* diff --git a/src/Service/ServiceName/ServiceNameFormatter.php b/src/Service/ServiceName/ServiceNameFormatter.php new file mode 100644 index 0000000..864400b --- /dev/null +++ b/src/Service/ServiceName/ServiceNameFormatter.php @@ -0,0 +1,37 @@ + self::MAX_LENGTH + ? mb_substr($trimmed, 0, self::MAX_LENGTH) . self::ELLIPSIS + : $trimmed; + } +} diff --git a/src/Service/ServiceName/ServiceNameResolver.php b/src/Service/ServiceName/ServiceNameResolver.php new file mode 100644 index 0000000..7943093 --- /dev/null +++ b/src/Service/ServiceName/ServiceNameResolver.php @@ -0,0 +1,57 @@ +getDisplayNames(); + if ($names === []) { + return null; + } + $normalizedNames = self::normalizeLanguageKeys($names); + $values = array_values($normalizedNames); + $lang = strtolower(substr($locale, 0, 2)); + $raw = $normalizedNames[$lang] ?? $normalizedNames[self::FALLBACK_LANGUAGE] ?? $values[0]; + return ServiceNameFormatter::format($raw); + } + + /** + * @param array $names + * @return array + */ + private static function normalizeLanguageKeys(array $names): array + { + $normalized = []; + foreach ($names as $lang => $name) { + $normalized[strtolower(substr($lang, 0, 2))] ??= $name; + } + return $normalized; + } +} diff --git a/src/Service/StateBasedAuthenticationService.php b/src/Service/StateBasedAuthenticationService.php index bb78b5b..a341bce 100644 --- a/src/Service/StateBasedAuthenticationService.php +++ b/src/Service/StateBasedAuthenticationService.php @@ -24,6 +24,7 @@ use SAML2\Constants; use Surfnet\GsspBundle\Exception\RuntimeException; use Surfnet\SamlBundle\SAML2\Extensions\GsspUserAttributesChunk; +use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\Routing\RouterInterface; @@ -111,4 +112,9 @@ public function getGsspUserAttributes(): ?GsspUserAttributesChunk { return $this->stateHandler->getGsspUserAttributes(); } + + public function getMdui(): ?MduiChunk + { + return $this->stateHandler->getMdui(); + } } diff --git a/src/Service/StateBasedRegistrationService.php b/src/Service/StateBasedRegistrationService.php index ad8337d..def307d 100644 --- a/src/Service/StateBasedRegistrationService.php +++ b/src/Service/StateBasedRegistrationService.php @@ -23,6 +23,7 @@ use Psr\Log\LoggerInterface; use SAML2\Constants; use Surfnet\GsspBundle\Exception\RuntimeException; +use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\Routing\RouterInterface; @@ -59,6 +60,11 @@ public function isRegistered(): bool return $this->stateHandler->hasSubjectNameId(); } + public function getMdui(): ?MduiChunk + { + return $this->stateHandler->getMdui(); + } + public function registrationRequired(): bool { return $this->stateHandler->isRequestTypeRegistration(); diff --git a/src/Service/StateHandler.php b/src/Service/StateHandler.php index e382d19..b500a92 100644 --- a/src/Service/StateHandler.php +++ b/src/Service/StateHandler.php @@ -23,11 +23,14 @@ use SAML2\Constants; use Surfnet\GsspBundle\Exception\RuntimeException; use Surfnet\SamlBundle\SAML2\Extensions\GsspUserAttributesChunk; +use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; use Surfnet\SamlBundle\SAML2\ReceivedAuthnRequest; use TypeError; /** * Knows and preserves the integrity of the GSSP application state. + * + * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) */ final readonly class StateHandler implements StateHandlerInterface { @@ -56,6 +59,8 @@ public const GSSP_USERATTRIBUTES = 'gssp_userattributes'; + public const GSSP_MDUI = 'gssp_mdui'; + public function __construct(private ValueStore $store) { } @@ -71,10 +76,7 @@ public function saveRegistrationRequest(ReceivedAuthnRequest $authnRequest, stri ->set(self::REQUEST_TYPE, self::REQUEST_TYPE_REGISTRATION) ; - $chunk = $authnRequest->getExtensions()->getGsspUserAttributesChunk(); - if ($chunk instanceof GsspUserAttributesChunk) { - $this->setGsspUserAttributes($chunk); - } + $this->saveRequestExtensions($authnRequest); } public function saveAuthenticationRequest(ReceivedAuthnRequest $authnRequest, string $relayState): void @@ -89,6 +91,8 @@ public function saveAuthenticationRequest(ReceivedAuthnRequest $authnRequest, st ->set(self::SCOPING_REQUESTER_IDS, $authnRequest->getScopingRequesterIds()) ->set(self::REQUEST_TYPE, self::REQUEST_TYPE_AUTHENTICATION) ; + + $this->saveRequestExtensions($authnRequest); } public function saveSubjectNameId(string $nameId): StateHandlerInterface @@ -156,13 +160,31 @@ public function getSubjectNameId(): string public function getGsspUserAttributes(): ?GsspUserAttributesChunk { - if (!is_string($this->store->get(self::GSSP_USERATTRIBUTES))) { + if (!$this->store->has(self::GSSP_USERATTRIBUTES)) { + return null; + } + $xml = $this->store->get(self::GSSP_USERATTRIBUTES); + if (!is_string($xml)) { throw new TypeError(sprintf('The "%s" must be of type string', self::GSSP_USERATTRIBUTES)); } - if ($this->store->has(self::GSSP_USERATTRIBUTES)) { - return GsspUserAttributesChunk::fromXML($this->store->get(self::GSSP_USERATTRIBUTES)); + return GsspUserAttributesChunk::fromXML($xml); + } + + public function getMdui(): ?MduiChunk + { + if (!$this->store->has(self::GSSP_MDUI)) { + return null; + } + $xml = $this->store->get(self::GSSP_MDUI); + if (!is_string($xml)) { + throw new TypeError(sprintf('The "%s" must be of type string', self::GSSP_MDUI)); } - return null; + return MduiChunk::fromXML($xml); + } + + public function hasMdui(): bool + { + return $this->store->has(self::GSSP_MDUI); } public function hasSubjectNameId(): bool @@ -237,9 +259,19 @@ private function setRequestId(string $originalRequestId): self return $this->set(self::REQUEST_ID, $originalRequestId); } - private function setGsspUserAttributes(GsspUserAttributesChunk $chunk): self + private function saveRequestExtensions(ReceivedAuthnRequest $authnRequest): void { - return $this->set(self::GSSP_USERATTRIBUTES, $chunk->toXML()); + $extensions = $authnRequest->getExtensions(); + + $chunk = $extensions->getGsspUserAttributesChunk(); + if ($chunk instanceof GsspUserAttributesChunk) { + $this->set(self::GSSP_USERATTRIBUTES, $chunk->toXML()); + } + + $mduiChunk = $extensions->getMduiChunk(); + if ($mduiChunk instanceof MduiChunk) { + $this->set(self::GSSP_MDUI, $mduiChunk->toXML()); + } } private function set(string $key, mixed $value): self @@ -250,9 +282,7 @@ private function set(string $key, mixed $value): self private function assertRequestTypeNotSet(): void { - // Request_type may not be set if ($this->store->has(self::REQUEST_TYPE)) { - // If it is set, it must be of type string. if (!is_string($this->store->get(self::REQUEST_TYPE))) { throw new TypeError(sprintf('The "%s" must be of type string', self::REQUEST_TYPE)); } diff --git a/src/Service/StateHandlerInterface.php b/src/Service/StateHandlerInterface.php index 9576631..0085792 100644 --- a/src/Service/StateHandlerInterface.php +++ b/src/Service/StateHandlerInterface.php @@ -21,6 +21,7 @@ namespace Surfnet\GsspBundle\Service; use Surfnet\SamlBundle\SAML2\Extensions\GsspUserAttributesChunk; +use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; use Surfnet\SamlBundle\SAML2\ReceivedAuthnRequest; /** @@ -56,6 +57,10 @@ public function getScopingRequesterIds(): array; public function getGsspUserAttributes(): ?GsspUserAttributesChunk; + public function getMdui(): ?MduiChunk; + + public function hasMdui(): bool; + /* * Is the current request type registration flow? */ diff --git a/tests/Service/ServiceName/ServiceNameFormatterTest.php b/tests/Service/ServiceName/ServiceNameFormatterTest.php new file mode 100644 index 0000000..0dc79c2 --- /dev/null +++ b/tests/Service/ServiceName/ServiceNameFormatterTest.php @@ -0,0 +1,63 @@ +assertSame('My Service', ServiceNameFormatter::format('My Service')); + } + + public function testNameOverFortyCharactersIsTruncatedWithEllipsis(): void + { + $raw = str_repeat('a', 45); + $formatted = ServiceNameFormatter::format($raw); + + $this->assertSame(str_repeat('a', 40) . "\u{2026}", $formatted); + $this->assertSame(41, mb_strlen($formatted)); + } + + public function testNameOfExactlyFortyCharactersIsNotTruncated(): void + { + $raw = str_repeat('a', 40); + $this->assertSame($raw, ServiceNameFormatter::format($raw)); + } + + public function testLeadingAndTrailingWhitespaceIsStripped(): void + { + $this->assertSame('My Service', ServiceNameFormatter::format(' My Service ')); + } + + public function testConsecutiveWhitespaceIsCollapsedToASingleSpace(): void + { + $this->assertSame('My Service', ServiceNameFormatter::format('My Service')); + $this->assertSame('My Service', ServiceNameFormatter::format("My \t\n Service")); + } + + public function testControlAndFormatCharactersAreRemoved(): void + { + $raw = "My\u{200B}Service\u{0007}"; + $this->assertSame('MyService', ServiceNameFormatter::format($raw)); + } +} diff --git a/tests/Service/ServiceName/ServiceNameResolverTest.php b/tests/Service/ServiceName/ServiceNameResolverTest.php new file mode 100644 index 0000000..cc91583 --- /dev/null +++ b/tests/Service/ServiceName/ServiceNameResolverTest.php @@ -0,0 +1,112 @@ +assertNull(ServiceNameResolver::resolve(null, 'nl_NL')); + } + + public function testItReturnsNullWhenMduiChunkHasNoDisplayNames(): void + { + $mdui = MduiChunk::fromXML( + '' + ); + + $this->assertNull(ServiceNameResolver::resolve($mdui, 'nl_NL')); + } + + public function testItPrefersExactLocaleMatchOverEnglish(): void + { + $mdui = MduiChunk::fromXML( + '' + . 'English Service Name' + . 'Nederlandse Dienstnaam' + . '' + ); + + $this->assertSame('Nederlandse Dienstnaam', ServiceNameResolver::resolve($mdui, 'nl_NL')); + } + + public function testItFallsBackToEnglishWhenRequestedLocaleIsAbsent(): void + { + $mdui = MduiChunk::fromXML( + '' + . 'English Service Name' + . 'Deutscher Dienstname' + . '' + ); + + $this->assertSame('English Service Name', ServiceNameResolver::resolve($mdui, 'nl_NL')); + } + + public function testItFallsBackToFirstAvailableWhenNeitherRequestedLocaleNorEnglishIsPresent(): void + { + $mdui = MduiChunk::fromXML( + '' + . 'Deutscher Dienstname' + . 'Nom du service francais' + . '' + ); + + $this->assertSame('Deutscher Dienstname', ServiceNameResolver::resolve($mdui, 'nl_NL')); + } + + public function testItMatchesLocaleWithRegionSubtagAgainstLanguageOnlyDisplayName(): void + { + $mdui = MduiChunk::fromXML( + '' + . 'English Service Name' + . 'Nederlandse Dienstnaam' + . '' + ); + + $this->assertSame('English Service Name', ServiceNameResolver::resolve($mdui, 'en_GB')); + } + + public function testItMatchesUppercaseXmlLangAgainstLowercaseLocale(): void + { + $mdui = MduiChunk::fromXML( + '' + . 'English Service Name' + . '' + ); + + $this->assertSame('English Service Name', ServiceNameResolver::resolve($mdui, 'en_US')); + } + + public function testItFormatsTheResolvedRawNameThroughServiceNameFormatter(): void + { + $longName = str_repeat('a', 45); + $mdui = MduiChunk::fromXML( + '' + . '' . $longName . '' + . '' + ); + + $this->assertSame(str_repeat('a', 40) . "\u{2026}", ServiceNameResolver::resolve($mdui, 'en_US')); + } +} diff --git a/tests/Service/StateBasedAuthenticationServiceTest.php b/tests/Service/StateBasedAuthenticationServiceTest.php index 7f56574..0527455 100644 --- a/tests/Service/StateBasedAuthenticationServiceTest.php +++ b/tests/Service/StateBasedAuthenticationServiceTest.php @@ -24,6 +24,7 @@ use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; use Surfnet\GsspBundle\Exception\RuntimeException; +use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; use Symfony\Component\Routing\RouterInterface; class StateBasedAuthenticationServiceTest extends TestCase @@ -97,4 +98,29 @@ public function test_can_request_scoping_requester_ids_when_present() ); $this->assertEquals(['a', 'b', 'c'], $authenticationService->getScopingRequesterIds()); } + + public function test_getMdui_returns_mdui_chunk_when_present() + { + $mduiChunk = m::mock(MduiChunk::class); + $stateHandler = m::mock(StateHandlerInterface::class); + $stateHandler->shouldReceive('getMdui')->andReturn($mduiChunk); + $authenticationService = new StateBasedAuthenticationService( + $stateHandler, + m::mock(RouterInterface::class), + m::mock(LoggerInterface::class) + ); + $this->assertSame($mduiChunk, $authenticationService->getMdui()); + } + + public function test_getMdui_returns_null_when_not_present() + { + $stateHandler = m::mock(StateHandlerInterface::class); + $stateHandler->shouldReceive('getMdui')->andReturnNull(); + $authenticationService = new StateBasedAuthenticationService( + $stateHandler, + m::mock(RouterInterface::class), + m::mock(LoggerInterface::class) + ); + $this->assertNull($authenticationService->getMdui()); + } } diff --git a/tests/Service/StateBasedRegistrationServiceTest.php b/tests/Service/StateBasedRegistrationServiceTest.php index 924ffdd..48bb035 100644 --- a/tests/Service/StateBasedRegistrationServiceTest.php +++ b/tests/Service/StateBasedRegistrationServiceTest.php @@ -20,9 +20,11 @@ namespace Surfnet\GsspBundle\Service; +use Mockery as m; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; use Surfnet\GsspBundle\Exception\RuntimeException; +use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; use Symfony\Component\Routing\RouterInterface; class StateBasedRegistrationServiceTest extends TestCase @@ -73,4 +75,29 @@ public function testIsRegisteredShouldReturnFalseWhenRegistered() ); $this->assertTrue($registrationService->isRegistered()); } + + public function test_getMdui_returns_mdui_chunk_when_present() + { + $mduiChunk = m::mock(MduiChunk::class); + $stateHandler = m::mock(StateHandlerInterface::class); + $stateHandler->shouldReceive('getMdui')->andReturn($mduiChunk); + $registrationService = new StateBasedRegistrationService( + $stateHandler, + m::mock(RouterInterface::class), + m::mock(LoggerInterface::class) + ); + $this->assertSame($mduiChunk, $registrationService->getMdui()); + } + + public function test_getMdui_returns_null_when_not_present() + { + $stateHandler = m::mock(StateHandlerInterface::class); + $stateHandler->shouldReceive('getMdui')->andReturnNull(); + $registrationService = new StateBasedRegistrationService( + $stateHandler, + m::mock(RouterInterface::class), + m::mock(LoggerInterface::class) + ); + $this->assertNull($registrationService->getMdui()); + } } diff --git a/tests/Service/StateHandlerTest.php b/tests/Service/StateHandlerTest.php index 27f72b0..488b0f4 100644 --- a/tests/Service/StateHandlerTest.php +++ b/tests/Service/StateHandlerTest.php @@ -20,8 +20,10 @@ namespace Surfnet\GsspBundle\Service; +use DOMDocument; use Mockery as m; use PHPUnit\Framework\TestCase; +use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; class StateHandlerTest extends TestCase { @@ -67,4 +69,63 @@ public function test_can_get_scoping_requester_ids() ->andReturn(['a', 'b', 'c']); $this->assertEquals(['a', 'b', 'c'], $this->handler->getScopingRequesterIds()); } + + public function test_has_mdui_returns_false_when_absent(): void + { + $this->valueStore + ->shouldReceive('has') + ->with('gssp_mdui') + ->andReturnFalse(); + $this->assertFalse($this->handler->hasMdui()); + } + + public function test_has_mdui_returns_true_when_present(): void + { + $this->valueStore + ->shouldReceive('has') + ->with('gssp_mdui') + ->andReturnTrue(); + $this->assertTrue($this->handler->hasMdui()); + } + + public function test_get_mdui_returns_null_when_absent(): void + { + $this->valueStore + ->shouldReceive('has') + ->with('gssp_mdui') + ->andReturnFalse(); + $this->assertNull($this->handler->getMdui()); + } + + public function test_get_mdui_returns_chunk_with_display_names(): void + { + $chunk = $this->buildMduiChunk(['en' => 'My Service', 'nl' => 'Mijn Dienst']); + + $this->valueStore + ->shouldReceive('has') + ->with('gssp_mdui') + ->andReturnTrue(); + $this->valueStore + ->shouldReceive('get') + ->with('gssp_mdui') + ->andReturn($chunk->toXML()); + + $result = $this->handler->getMdui(); + $this->assertInstanceOf(MduiChunk::class, $result); + $this->assertEquals(['en' => 'My Service', 'nl' => 'Mijn Dienst'], $result->getDisplayNames()); + } + + private function buildMduiChunk(array $displayNames): MduiChunk + { + $chunk = new MduiChunk(); + $doc = $chunk->getValue()->ownerDocument; + $ns = 'urn:oasis:names:tc:SAML:metadata:ui'; + foreach ($displayNames as $lang => $name) { + $el = $doc->createElementNS($ns, 'mdui:DisplayName'); + $el->setAttribute('xml:lang', $lang); + $el->textContent = $name; + $chunk->getValue()->appendChild($el); + } + return $chunk; + } } From 049107f4679860d32f76c58930332f703374a6d4 Mon Sep 17 00:00:00 2001 From: Kay Joosten Date: Tue, 14 Jul 2026 13:23:32 +0200 Subject: [PATCH 11/18] Fix service name formatter deleting tabs/newlines instead of collapsing them Control-character stripping ran before whitespace collapsing, so a tab or newline between words (itself a control character) was deleted outright instead of being normalized to a single space, joining adjacent words together. Swap the order so whitespace is collapsed first, then remaining control/format characters are stripped. --- src/Service/ServiceName/ServiceNameFormatter.php | 8 +++++--- tests/Service/ServiceName/ServiceNameFormatterTest.php | 10 ++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Service/ServiceName/ServiceNameFormatter.php b/src/Service/ServiceName/ServiceNameFormatter.php index 864400b..0d47cb8 100644 --- a/src/Service/ServiceName/ServiceNameFormatter.php +++ b/src/Service/ServiceName/ServiceNameFormatter.php @@ -27,9 +27,11 @@ final class ServiceNameFormatter public static function format(string $raw): string { - $stripped = preg_replace('/[\p{Cc}\p{Cf}]/u', '', $raw) ?? ''; - $collapsed = preg_replace('/\s+/u', ' ', $stripped) ?? ''; - $trimmed = trim($collapsed); + // Collapse whitespace before stripping control chars, so tabs/newlines + // become a space instead of being deleted (which would concatenate words). + $collapsed = preg_replace('/\s+/u', ' ', $raw) ?? ''; + $stripped = preg_replace('/[\p{Cc}\p{Cf}]/u', '', $collapsed) ?? ''; + $trimmed = trim($stripped); return mb_strlen($trimmed) > self::MAX_LENGTH ? mb_substr($trimmed, 0, self::MAX_LENGTH) . self::ELLIPSIS : $trimmed; diff --git a/tests/Service/ServiceName/ServiceNameFormatterTest.php b/tests/Service/ServiceName/ServiceNameFormatterTest.php index 0dc79c2..85f6acb 100644 --- a/tests/Service/ServiceName/ServiceNameFormatterTest.php +++ b/tests/Service/ServiceName/ServiceNameFormatterTest.php @@ -60,4 +60,14 @@ public function testControlAndFormatCharactersAreRemoved(): void $raw = "My\u{200B}Service\u{0007}"; $this->assertSame('MyService', ServiceNameFormatter::format($raw)); } + + public function testTabBetweenWordsIsReplacedWithASingleSpaceNotConcatenated(): void + { + $this->assertSame('Name With', ServiceNameFormatter::format("Name\tWith")); + } + + public function testNewlineBetweenWordsIsReplacedWithASingleSpaceNotConcatenated(): void + { + $this->assertSame('Name With', ServiceNameFormatter::format("Name\nWith")); + } } From f90e3a56786a512ce37a18de3425a5dc9df31adf Mon Sep 17 00:00:00 2001 From: Kay Joosten Date: Mon, 27 Jul 2026 11:17:44 +0200 Subject: [PATCH 12/18] fix: correct off-by-one truncation in ServiceNameFormatter (40 chars total, not 41) --- src/Service/ServiceName/ServiceNameFormatter.php | 5 ++++- .../ServiceName/ServiceNameFormatterTest.php | 13 +++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Service/ServiceName/ServiceNameFormatter.php b/src/Service/ServiceName/ServiceNameFormatter.php index 0d47cb8..eb72469 100644 --- a/src/Service/ServiceName/ServiceNameFormatter.php +++ b/src/Service/ServiceName/ServiceNameFormatter.php @@ -32,8 +32,11 @@ public static function format(string $raw): string $collapsed = preg_replace('/\s+/u', ' ', $raw) ?? ''; $stripped = preg_replace('/[\p{Cc}\p{Cf}]/u', '', $collapsed) ?? ''; $trimmed = trim($stripped); + // Truncate to MAX_LENGTH - 1 so the appended ellipsis keeps the total at + // MAX_LENGTH, per the RFC (OpenConext/Stepup-Gateway#587): "truncated to + // MAX_CHARACTERS-1... append an ellipsis". return mb_strlen($trimmed) > self::MAX_LENGTH - ? mb_substr($trimmed, 0, self::MAX_LENGTH) . self::ELLIPSIS + ? mb_substr($trimmed, 0, self::MAX_LENGTH - 1) . self::ELLIPSIS : $trimmed; } } diff --git a/tests/Service/ServiceName/ServiceNameFormatterTest.php b/tests/Service/ServiceName/ServiceNameFormatterTest.php index 85f6acb..9c682a7 100644 --- a/tests/Service/ServiceName/ServiceNameFormatterTest.php +++ b/tests/Service/ServiceName/ServiceNameFormatterTest.php @@ -34,8 +34,17 @@ public function testNameOverFortyCharactersIsTruncatedWithEllipsis(): void $raw = str_repeat('a', 45); $formatted = ServiceNameFormatter::format($raw); - $this->assertSame(str_repeat('a', 40) . "\u{2026}", $formatted); - $this->assertSame(41, mb_strlen($formatted)); + $this->assertSame(str_repeat('a', 39) . "\u{2026}", $formatted); + $this->assertSame(40, mb_strlen($formatted)); + } + + public function testNameOfFortyOneCharactersIsTruncatedToThirtyNinePlusEllipsis(): void + { + $raw = str_repeat('b', 41); + $formatted = ServiceNameFormatter::format($raw); + + $this->assertSame(str_repeat('b', 39) . "\u{2026}", $formatted); + $this->assertSame(40, mb_strlen($formatted)); } public function testNameOfExactlyFortyCharactersIsNotTruncated(): void From ce8aab120816076a75158f98ea64bd79992c6eda Mon Sep 17 00:00:00 2001 From: Kay Joosten Date: Mon, 27 Jul 2026 11:19:10 +0200 Subject: [PATCH 13/18] fix: update ResolverTest assertion for corrected ServiceNameFormatter truncation length --- tests/Service/ServiceName/ServiceNameResolverTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Service/ServiceName/ServiceNameResolverTest.php b/tests/Service/ServiceName/ServiceNameResolverTest.php index cc91583..f9ea811 100644 --- a/tests/Service/ServiceName/ServiceNameResolverTest.php +++ b/tests/Service/ServiceName/ServiceNameResolverTest.php @@ -107,6 +107,6 @@ public function testItFormatsTheResolvedRawNameThroughServiceNameFormatter(): vo . '' ); - $this->assertSame(str_repeat('a', 40) . "\u{2026}", ServiceNameResolver::resolve($mdui, 'en_US')); + $this->assertSame(str_repeat('a', 39) . "\u{2026}", ServiceNameResolver::resolve($mdui, 'en_US')); } } From 536f69fa5c042a0da3f9b0a982f99d9f4785ca07 Mon Sep 17 00:00:00 2001 From: Kay Joosten Date: Mon, 27 Jul 2026 16:28:26 +0200 Subject: [PATCH 14/18] Document the mdui:UIInfo / ServiceName feature ahead of release Add an Unreleased CHANGELOG section covering the new getMdui()/hasMdui() accessors and the ServiceNameFormatter/ServiceNameResolver 40-character sanitization contract, so downstream consumers know what they're depending on before this gets tagged. --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a39e79..b58d499 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# Unreleased + +- New: preserve and expose the `mdui:UIInfo` SAML extension (service display name) from the AuthnRequest during + authentication and registration, via `StateHandlerInterface::getMdui()`/`hasMdui()` and + `AuthenticationService::getMdui()`/`RegistrationService::getMdui()`. +- New: `Surfnet\GsspBundle\Service\ServiceName\ServiceNameFormatter` and `ServiceNameResolver` sanitize and + locale-match a resolved display name. Contract: truncated to 40 characters total (39 characters + ellipsis when + truncated), whitespace trimmed/collapsed, control/format characters stripped, locale fallback order is exact match + -> `en` -> first available `DisplayName`. +- Not yet tagged/released. + # 6.0.0 Make Symfony 7.4 compatible From 26e1ee47b09eb9012153cf78e70bc2ed379bd8c0 Mon Sep 17 00:00:00 2001 From: Kay Joosten Date: Thu, 30 Jul 2026 14:41:57 +0200 Subject: [PATCH 15/18] Use stepup-saml-bundle's ServiceNameFormatter instead of a local duplicate ServiceNameFormatter now lives in Stepup-saml-bundle (which this bundle already depends on) as the single canonical implementation, alongside Stepup-Gateway's now-identical code path. This bundle's own copy had already diverged once (41-char truncation bug vs the RFC's 40). --- .../ServiceName/ServiceNameFormatter.php | 42 ---------- .../ServiceName/ServiceNameResolver.php | 1 + .../ServiceName/ServiceNameFormatterTest.php | 82 ------------------- 3 files changed, 1 insertion(+), 124 deletions(-) delete mode 100644 src/Service/ServiceName/ServiceNameFormatter.php delete mode 100644 tests/Service/ServiceName/ServiceNameFormatterTest.php diff --git a/src/Service/ServiceName/ServiceNameFormatter.php b/src/Service/ServiceName/ServiceNameFormatter.php deleted file mode 100644 index eb72469..0000000 --- a/src/Service/ServiceName/ServiceNameFormatter.php +++ /dev/null @@ -1,42 +0,0 @@ - self::MAX_LENGTH - ? mb_substr($trimmed, 0, self::MAX_LENGTH - 1) . self::ELLIPSIS - : $trimmed; - } -} diff --git a/src/Service/ServiceName/ServiceNameResolver.php b/src/Service/ServiceName/ServiceNameResolver.php index 7943093..f7f2a10 100644 --- a/src/Service/ServiceName/ServiceNameResolver.php +++ b/src/Service/ServiceName/ServiceNameResolver.php @@ -21,6 +21,7 @@ namespace Surfnet\GsspBundle\Service\ServiceName; use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; +use Surfnet\SamlBundle\SAML2\Extensions\ServiceNameFormatter; final class ServiceNameResolver { diff --git a/tests/Service/ServiceName/ServiceNameFormatterTest.php b/tests/Service/ServiceName/ServiceNameFormatterTest.php deleted file mode 100644 index 9c682a7..0000000 --- a/tests/Service/ServiceName/ServiceNameFormatterTest.php +++ /dev/null @@ -1,82 +0,0 @@ -assertSame('My Service', ServiceNameFormatter::format('My Service')); - } - - public function testNameOverFortyCharactersIsTruncatedWithEllipsis(): void - { - $raw = str_repeat('a', 45); - $formatted = ServiceNameFormatter::format($raw); - - $this->assertSame(str_repeat('a', 39) . "\u{2026}", $formatted); - $this->assertSame(40, mb_strlen($formatted)); - } - - public function testNameOfFortyOneCharactersIsTruncatedToThirtyNinePlusEllipsis(): void - { - $raw = str_repeat('b', 41); - $formatted = ServiceNameFormatter::format($raw); - - $this->assertSame(str_repeat('b', 39) . "\u{2026}", $formatted); - $this->assertSame(40, mb_strlen($formatted)); - } - - public function testNameOfExactlyFortyCharactersIsNotTruncated(): void - { - $raw = str_repeat('a', 40); - $this->assertSame($raw, ServiceNameFormatter::format($raw)); - } - - public function testLeadingAndTrailingWhitespaceIsStripped(): void - { - $this->assertSame('My Service', ServiceNameFormatter::format(' My Service ')); - } - - public function testConsecutiveWhitespaceIsCollapsedToASingleSpace(): void - { - $this->assertSame('My Service', ServiceNameFormatter::format('My Service')); - $this->assertSame('My Service', ServiceNameFormatter::format("My \t\n Service")); - } - - public function testControlAndFormatCharactersAreRemoved(): void - { - $raw = "My\u{200B}Service\u{0007}"; - $this->assertSame('MyService', ServiceNameFormatter::format($raw)); - } - - public function testTabBetweenWordsIsReplacedWithASingleSpaceNotConcatenated(): void - { - $this->assertSame('Name With', ServiceNameFormatter::format("Name\tWith")); - } - - public function testNewlineBetweenWordsIsReplacedWithASingleSpaceNotConcatenated(): void - { - $this->assertSame('Name With', ServiceNameFormatter::format("Name\nWith")); - } -} From 664d0cd648f1cc831cee12d4df66c521f138fdd5 Mon Sep 17 00:00:00 2001 From: Kay Joosten Date: Mon, 3 Aug 2026 15:05:17 +0200 Subject: [PATCH 16/18] fix: quote PHPMD annotation so phpstan can parse it phpstan's phpDoc parser trips on the unquoted dot in @SuppressWarnings(PHPMD.ExcessiveClassComplexity), treating it as a phpDoc.parseError. Quoting the annotation value avoids the parse error entirely, so the phpstan-baseline.neon ignore entry for it is no longer needed. Addresses review comment on this PR. --- ci/qa/phpstan-baseline.neon | 8 -------- src/Service/StateHandler.php | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/ci/qa/phpstan-baseline.neon b/ci/qa/phpstan-baseline.neon index be89ad5..7c51709 100644 --- a/ci/qa/phpstan-baseline.neon +++ b/ci/qa/phpstan-baseline.neon @@ -1,13 +1,5 @@ parameters: ignoreErrors: - - - # phpstan cannot parse the dot in PHPMD annotation names (PHPMD.ExcessiveClassComplexity). - # This is a tool-compatibility issue, not a type error. - message: '#ExcessiveClassComplexity#' - identifier: phpDoc.parseError - count: 1 - path: ../../src/Service/StateHandler.php - - message: '#^Method Surfnet\\GsspBundle\\Saml\\ResponseContext\:\:getErrorStatus\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue diff --git a/src/Service/StateHandler.php b/src/Service/StateHandler.php index b500a92..1268a1e 100644 --- a/src/Service/StateHandler.php +++ b/src/Service/StateHandler.php @@ -30,7 +30,7 @@ /** * Knows and preserves the integrity of the GSSP application state. * - * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) + * @SuppressWarnings("PHPMD.ExcessiveClassComplexity") */ final readonly class StateHandler implements StateHandlerInterface { From 72f8ff1d40b51d2d07e871ed3d4be00d392ce942 Mon Sep 17 00:00:00 2001 From: Kay Joosten Date: Mon, 3 Aug 2026 15:05:17 +0200 Subject: [PATCH 17/18] Swap stepup-saml-bundle dev-branch pin for tagged beta release Addresses the "Mandatory: update before merging this pr" review comment. surfnet/stepup-saml-bundle 7.1.0-beta1 is now tagged (PR #137's branch tip), so this no longer needs to float on a dev-branch requirement. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 91c539d..1bfa4ab 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "php": "^8.2", "ext-openssl": "*", "beberlei/assert": "^3", - "surfnet/stepup-saml-bundle": "dev-feature/issue-48-mdui-chunk as 7.0.99", + "surfnet/stepup-saml-bundle": "7.1.0-beta1", "symfony/dependency-injection": "^7.4", "symfony/framework-bundle": "^7.4", "symfony/monolog-bundle": "^4.0" From d2bb2684c9f53662dfa49a392004fb518d1e3244 Mon Sep 17 00:00:00 2001 From: Kay Joosten Date: Thu, 6 Aug 2026 13:20:42 +0200 Subject: [PATCH 18/18] feat: add hasMdui() to service interfaces, drop dev-branch pin If applied, this commit will make hasMdui() available on AuthenticationService and RegistrationService (not just the internal StateHandlerInterface), document ServiceNameResolver as the mandatory sanitizing entry point, and pin surfnet/stepup-saml-bundle to its tagged 7.1.0-beta3 release instead of a dev-branch alias. Why is this change needed? Prior to this change, StateHandlerInterface had hasMdui() but the public service interfaces didn't, forcing callers to use the inconsistent getMdui() !== null check instead. The bundle also pinned surfnet/stepup-saml-bundle via a dev-branch alias ("as 7.0.99"/minimum-stability: dev), which makes Composer's solver treat an unreleased branch as a real tagged version with no warning to downstream consumers. How does it address the issue? Adds hasMdui(): bool to AuthenticationService and RegistrationService, implemented in StateBasedAuthenticationService and StateBasedRegistrationService by delegating to the state handler. Adds a docblock to ServiceNameResolver noting it's the only sanitizing read path for display names. Removes minimum-stability: dev and pins surfnet/stepup-saml-bundle to the tagged 7.1.0-beta3. Links / references: RFC OpenConext/Stepup-Gateway#587 --- composer.json | 3 +-- src/Service/AuthenticationService.php | 2 ++ src/Service/RegistrationService.php | 2 ++ src/Service/ServiceName/ServiceNameResolver.php | 7 +++++++ src/Service/StateBasedAuthenticationService.php | 5 +++++ src/Service/StateBasedRegistrationService.php | 5 +++++ 6 files changed, 22 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 1bfa4ab..fccf977 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,6 @@ "license": "Apache-2.0", "description": "A Symfony 6 bundle to aid the creation of GSSP (Generic SAML Step-up Provider) device support.", "type": "symfony-bundle", - "minimum-stability": "dev", "prefer-stable": true, "repositories": [ { @@ -25,7 +24,7 @@ "php": "^8.2", "ext-openssl": "*", "beberlei/assert": "^3", - "surfnet/stepup-saml-bundle": "7.1.0-beta1", + "surfnet/stepup-saml-bundle": "7.1.0-beta3", "symfony/dependency-injection": "^7.4", "symfony/framework-bundle": "^7.4", "symfony/monolog-bundle": "^4.0" diff --git a/src/Service/AuthenticationService.php b/src/Service/AuthenticationService.php index 690d482..a9cdde1 100644 --- a/src/Service/AuthenticationService.php +++ b/src/Service/AuthenticationService.php @@ -92,4 +92,6 @@ public function getScopingRequesterIds(): array; public function getGsspUserAttributes(): ?GsspUserAttributesChunk; public function getMdui(): ?MduiChunk; + + public function hasMdui(): bool; } diff --git a/src/Service/RegistrationService.php b/src/Service/RegistrationService.php index 9a54b58..e9699ee 100644 --- a/src/Service/RegistrationService.php +++ b/src/Service/RegistrationService.php @@ -65,6 +65,8 @@ public function isRegistered(): bool; public function getMdui(): ?MduiChunk; + public function hasMdui(): bool; + public function reject(string $message, string $subCode = Constants::STATUS_AUTHN_FAILED): void; /* diff --git a/src/Service/ServiceName/ServiceNameResolver.php b/src/Service/ServiceName/ServiceNameResolver.php index f7f2a10..99f8770 100644 --- a/src/Service/ServiceName/ServiceNameResolver.php +++ b/src/Service/ServiceName/ServiceNameResolver.php @@ -23,6 +23,13 @@ use Surfnet\SamlBundle\SAML2\Extensions\MduiChunk; use Surfnet\SamlBundle\SAML2\Extensions\ServiceNameFormatter; +/** + * Mandatory path for reading a service name out of an MduiChunk: this is the only place that + * runs the name through ServiceNameFormatter::format(), which sanitizes it (length cap, + * whitespace collapse, stripping of control/format characters). Calling + * $mdui->getDisplayNames() directly bypasses that sanitization — GSSPs must resolve display + * names through this class, never read MduiChunk's raw names for display. + */ final class ServiceNameResolver { private const FALLBACK_LANGUAGE = 'en'; diff --git a/src/Service/StateBasedAuthenticationService.php b/src/Service/StateBasedAuthenticationService.php index a341bce..65b63ed 100644 --- a/src/Service/StateBasedAuthenticationService.php +++ b/src/Service/StateBasedAuthenticationService.php @@ -117,4 +117,9 @@ public function getMdui(): ?MduiChunk { return $this->stateHandler->getMdui(); } + + public function hasMdui(): bool + { + return $this->stateHandler->hasMdui(); + } } diff --git a/src/Service/StateBasedRegistrationService.php b/src/Service/StateBasedRegistrationService.php index def307d..bfff53c 100644 --- a/src/Service/StateBasedRegistrationService.php +++ b/src/Service/StateBasedRegistrationService.php @@ -65,6 +65,11 @@ public function getMdui(): ?MduiChunk return $this->stateHandler->getMdui(); } + public function hasMdui(): bool + { + return $this->stateHandler->hasMdui(); + } + public function registrationRequired(): bool { return $this->stateHandler->isRequestTypeRegistration();