From 9f7a723843afaedd8ea2ed78399b00ae6d074d4e Mon Sep 17 00:00:00 2001 From: Chris R Date: Thu, 3 Sep 2015 17:54:09 -0700 Subject: [PATCH] #390 Make the nonce cookie expire. --- .../OpenIdConnectAuthenticationHandler.cs | 3 ++- .../OpenIdConnectAuthenticationOptions.cs | 6 +++++- .../OpenIdConnect/OpenIdConnectMiddlewareTests.cs | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationHandler.cs index ae56928640..954f6e74ed 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationHandler.cs @@ -666,7 +666,8 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect new CookieOptions { HttpOnly = true, - Secure = Request.IsHttps + Secure = Request.IsHttps, + Expires = DateTime.UtcNow + Options.ProtocolValidator.NonceLifetime }); } diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs index 6809b571a7..f24cdec61c 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs @@ -169,7 +169,11 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect /// is valid per: http://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation /// /// if 'value' is null. - public OpenIdConnectProtocolValidator ProtocolValidator { get; set; } = new OpenIdConnectProtocolValidator { RequireState = false }; + public OpenIdConnectProtocolValidator ProtocolValidator { get; set; } = new OpenIdConnectProtocolValidator() + { + RequireState = false, + NonceLifetime = TimeSpan.FromMinutes(15) + }; /// /// Gets or sets the 'post_logout_redirect_uri' diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs index 971301c19b..693ff185d6 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs @@ -83,6 +83,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect }); var transaction = await SendAsync(server, DefaultHost + Challenge); transaction.SetCookie.Single().ShouldContain(OpenIdConnectAuthenticationDefaults.CookieNoncePrefix); + transaction.SetCookie.Single().ShouldContain("Expires"); } [Fact]