Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent infinite loop when max_age=0 #1544

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/IdentityServer/Constants.cs
Expand Up @@ -131,6 +131,12 @@ public static class SigningAlgorithms
/// </summary>
public const string ProcessedPrompt = "suppressed_" + OidcConstants.AuthorizeRequest.Prompt;

/// <summary>
/// The name of the parameter passed to the authorize callback to indicate
/// max age that have already been used.
/// </summary>
public const string ProcessedMaxAge = "suppressed_" + OidcConstants.AuthorizeRequest.MaxAge;

public static class KnownAcrValues
{
public const string HomeRealm = "idp:";
Expand Down
Expand Up @@ -10,6 +10,7 @@
using System.Security.Cryptography;
using System.Text;
using System.Collections.Specialized;
using System.Globalization;

#pragma warning disable 1591

Expand Down Expand Up @@ -49,6 +50,16 @@ public static void RemovePrompt(this ValidatedAuthorizeRequest request)
}).ToArray();
}

public static void RemoveMaxAge(this ValidatedAuthorizeRequest request)
{
request.Raw.Remove("max_age");

if (request.MaxAge.HasValue)
{
request.Raw.Add(Constants.ProcessedMaxAge, request.MaxAge.Value.ToString(CultureInfo.InvariantCulture));
}
}

public static string GetPrefixedAcrValue(this ValidatedAuthorizeRequest request, string prefix)
{
var value = request.AuthenticationContextReferenceClasses
Expand Down
Expand Up @@ -244,6 +244,12 @@ protected internal virtual async Task<InteractionResponse> ProcessLoginAsync(Val
var authTime = request.Subject.GetAuthenticationTime();
if (Clock.UtcNow.UtcDateTime > authTime.AddSeconds(request.MaxAge.Value))
{
// Remove the max_age=0 parameter to prevent (infinite) loop
if (request.MaxAge.Value == 0)
{
request.RemoveMaxAge();
}

Logger.LogInformation("Showing login: Requested MaxAge exceeded.");

return new InteractionResponse { IsLogin = true };
Expand Down