OIDC: tests for key-material faults, scope-limited claims, userinfo refusal, client re-seeding; redirect URI must be http(s)

A rooted path parses as an absolute file URI on Linux, so RedirectUri now also requires an http or https scheme. The authorize challenge no longer re-checks the resume path length: OpenIddict's request_uri keeps it short and a test pins that. The token endpoint no longer re-checks the grant type OpenIddict already restricts.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-22 18:40:11 +02:00
commit 06ca8209da
4 changed files with 193 additions and 18 deletions

View file

@ -36,13 +36,11 @@ public static class OidcEndpoints
if (http.User.Identity?.IsAuthenticated != true)
{
// OpenIddict has already replaced the request with a short request_uri; sign-in resumes at this URL.
var resume = http.Request.PathBase + http.Request.Path + http.Request.QueryString;
return LocalReturnPath.Parse(resume).Value == resume
? Results.Challenge(
new AuthenticationProperties { RedirectUri = resume },
[CookieAuthenticationDefaults.AuthenticationScheme])
: Deny(Errors.InvalidRequest, "The authorization request is too long to resume after sign-in.");
// OpenIddict has already replaced the request with a short request_uri, so this URL fits a sign-in
// return path (LocalReturnPath.MaxLength); a test pins that, because Parse would otherwise fall back to /App.
return Results.Challenge(
new AuthenticationProperties { RedirectUri = http.Request.PathBase + http.Request.Path + http.Request.QueryString },
[CookieAuthenticationDefaults.AuthenticationScheme]);
}
var actor = await actors.GetAsync(http.RequestAborted);
@ -79,13 +77,7 @@ public static class OidcEndpoints
private static async Task<IResult> ExchangeAsync(HttpContext http)
{
var request = http.GetOpenIddictServerRequest()
?? throw new InvalidOperationException("The OpenIddict request could not be retrieved.");
if (!request.IsAuthorizationCodeGrantType())
{
return Deny(Errors.UnsupportedGrantType, "Only the authorization code grant is supported.");
}
// Only the authorization code grant is enabled, so OpenIddict has refused every other grant already.
// The code's own principal carries the claims chosen at authorize time.
var result = await http.AuthenticateAsync(OpenIddictScheme);
return Results.SignIn(result.Principal!, properties: null, OpenIddictScheme);

View file

@ -40,9 +40,11 @@ public sealed class OidcKeyMaterial : IDisposable
Require(mas.ClientId, "Bifrost:Oidc:Clients:Mas:ClientId");
Require(mas.ClientSecretPath, "Bifrost:Oidc:Clients:Mas:ClientSecretPath");
Require(mas.RedirectUri, "Bifrost:Oidc:Clients:Mas:RedirectUri");
if (!Uri.TryCreate(mas.RedirectUri, UriKind.Absolute, out _))
// A rooted path such as "/callback" parses as an absolute file URI on Linux, so the scheme is checked too.
if (!Uri.TryCreate(mas.RedirectUri, UriKind.Absolute, out var redirect) ||
redirect.Scheme is not ("https" or "http"))
{
throw new OidcConfigurationException("Bifrost:Oidc:Clients:Mas:RedirectUri must be an absolute URI.");
throw new OidcConfigurationException("Bifrost:Oidc:Clients:Mas:RedirectUri must be an absolute http(s) URI.");
}
var ecdsa = LoadSigningKey(options.SigningKeyPath);