Skip to content

Commit 9187727

Browse files
committed
Validate AuthnResponse status
1 parent 8381c1a commit 9187727

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

test/TestWebApp/Controllers/AuthController.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Security.Claims;
99
using TestWebApp.Identity;
1010
using System.IdentityModel.Services;
11+
using System.Security.Authentication;
1112

1213
namespace TestWebApp.Controllers
1314
{
@@ -46,8 +47,12 @@ public ActionResult AssertionConsumerService()
4647
var binding = new Saml2PostBinding();
4748
var saml2AuthnResponse = new Saml2AuthnResponse(config);
4849

50+
binding.ReadSamlResponse(Request.ToGenericHttpRequest(), saml2AuthnResponse);
51+
if (saml2AuthnResponse.Status != Saml2StatusCodes.Success)
52+
{
53+
throw new AuthenticationException($"SAML Response status: {saml2AuthnResponse.Status}");
54+
}
4955
binding.Unbind(Request.ToGenericHttpRequest(), saml2AuthnResponse);
50-
5156
saml2AuthnResponse.CreateSession(claimsAuthenticationManager: new DefaultClaimsAuthenticationManager());
5257

5358
var relayStateQuery = binding.GetRelayStateQuery();

test/TestWebAppCore/Controllers/AuthController.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.AspNetCore.Mvc;
1010
using TestWebAppCore.Identity;
1111
using Microsoft.Extensions.Options;
12+
using System.Security.Authentication;
1213

1314
namespace TestWebAppCore.Controllers
1415
{
@@ -50,6 +51,11 @@ public async Task<IActionResult> AssertionConsumerService()
5051
var binding = new Saml2PostBinding();
5152
var saml2AuthnResponse = new Saml2AuthnResponse(config);
5253

54+
binding.ReadSamlResponse(Request.ToGenericHttpRequest(), saml2AuthnResponse);
55+
if (saml2AuthnResponse.Status != Saml2StatusCodes.Success)
56+
{
57+
throw new AuthenticationException($"SAML Response status: {saml2AuthnResponse.Status}");
58+
}
5359
binding.Unbind(Request.ToGenericHttpRequest(), saml2AuthnResponse);
5460
await saml2AuthnResponse.CreateSession(HttpContext, claimsTransform: (claimsPrincipal) => ClaimsTransform.Transform(claimsPrincipal));
5561

0 commit comments

Comments
 (0)