From b92d951c058dcb753d370bed2e22ff85f918edf1 Mon Sep 17 00:00:00 2001 From: Anders Abel Date: Mon, 11 Sep 2023 12:10:26 +0200 Subject: [PATCH] Validate response and assertion issuers are same --- Sustainsys.Saml2/SAML2P/Saml2Response.cs | 2 ++ .../Tests.Shared/Saml2P/Saml2ResponseTests.cs | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/Sustainsys.Saml2/SAML2P/Saml2Response.cs b/Sustainsys.Saml2/SAML2P/Saml2Response.cs index 2a3598a10..1d3fd1c9e 100644 --- a/Sustainsys.Saml2/SAML2P/Saml2Response.cs +++ b/Sustainsys.Saml2/SAML2P/Saml2Response.cs @@ -605,6 +605,8 @@ private IEnumerable CreateClaims(IOptions options, IdentityProvi validationParameters.ValidAudience = options.SPOptions.EntityId.Id; validationParameters.TokenReplayCache = options.SPOptions.TokenReplayCache; validationParameters.ValidateTokenReplay = true; + validationParameters.ValidIssuer = idp.EntityId.Id; + validationParameters.ValidateIssuer = true; options.Notifications.Unsafe.TokenValidationParametersCreated(validationParameters, idp, XmlElement); diff --git a/Tests/Tests.Shared/Saml2P/Saml2ResponseTests.cs b/Tests/Tests.Shared/Saml2P/Saml2ResponseTests.cs index 0b389c7a9..3d30ff120 100644 --- a/Tests/Tests.Shared/Saml2P/Saml2ResponseTests.cs +++ b/Tests/Tests.Shared/Saml2P/Saml2ResponseTests.cs @@ -24,6 +24,7 @@ using X509SecurityKey = Microsoft.IdentityModel.Tokens.X509SecurityKey; using System.Collections.Generic; using Microsoft.IdentityModel.Logging; +using Microsoft.IdentityModel.Tokens; namespace Sustainsys.Saml2.Tests.Saml2P { @@ -2506,5 +2507,35 @@ public void Saml2Response_SessionNotOnOrAfter_ThrowsIfCalledBeforeGetClaims() .Should().Throw() .WithMessage("*GetClaims*"); } + + [TestMethod] + public void Saml2Response_GetClaims_DifferentIssuers() + { + var response = + @" + + https://idp.example.com + + + + + https://other.example.com + + SomeUser + + + + + "; + + var signedResponse = SignedXmlHelper.SignXml(response); + + Saml2Response.Read(signedResponse).Invoking(r => r.GetClaims(Options.FromConfiguration)) + .Should().Throw(); + } } }