Repository navigation
Description
Background and Motivation
Pushed Authorization Requests (PAR) is a relatively new OAuth standard that improves the security of OAuth and OIDC flows by moving authorization parameters from the front channel to the back channel (that is, from redirect URLs in the browser to direct machine to machine http calls on the back end).
This prevents an attacker in the browser from
- seeing authorization parameters (which could leak PII) and from
- tampering with those parameters (e.g., the attacker could change the scope of access being requested).
Pushing the authorization parameters also keeps request URLs short. Authorize parameters might get very long when using more complex OAuth and OIDC features such as Rich Authorization Requests, and URLs that are long cause issues in many browsers and networking infrastructure.
The use of PAR is encouraged by the FAPI working group within the OpenID Foundation. For example, the FAPI2.0 Security Profile requires the use of PAR. This security profile is used by many of the groups working on open banking (primarily in Europe), in health care, and in other industries with high security requirements.
PAR is supported by a number of identity providers, including
- Duende IdentityServer
- Curity
- Keycloak
- Authlete
This proposal aims to add support for PAR to the OidcHandler.
Proposed API
We need a new flag to enable the behavior:
namespace Microsoft.AspNetCore.Authentication.OpenIdConnect;
public class OpenIdConnectOptions
{
+ /// <summary>
+ /// Flag to set whether the handler should push authorization parameters on the backchannel before
+ /// redirecting to the identity provider.
+ /// The default is 'false'.
+ /// </summary>
+ public bool UsePushedAuthorization { get; set; }
}And we need new properties on the OpenIdConnectConfiguration to describe the PAR-specific information we get from discovery (and use for manual configuration).
namespace Microsoft.IdentityModel.Protocols.OpenIdConnect;
public class OpenIdConnectConfiguration
{
+ //
+ // Summary:
+ // Gets or sets the 'pushed_authorization_request_endpoint'.
+ [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = "pushed_authorization_request_endpoint", Required = Required.Default)]
+ public string PushedAuthorizationRequestEndpoint { get; set; }
+
+ //
+ // Summary:
+ // Boolean parameter indicating whether the authorization server accepts authorization request
+ // data only via PAR. Dafault Value is false.
+ [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, PropertyName = "require_pushed_authorization_requests", Required = Required.Default)]
+ public bool RequirePushedAuthorizationRequests { get; set; }
}When the UsePushedAuthorization flag is enabled in configuration or the require_pushed_authorization_requests flag is enabled in the discovery document or the explicit configuration, the parameters that the handler would normally set in the URL when it redirects to the authorize endpoint will instead be sent on a backchannel call to the PAR endpoint, and the resulting request_uri will instead be attached to the redirect, along with the client_id, as per the specification.
It is an error to attempt to enable UsePushedAuthorization with an identity provider that publishes a discovery document without a pushed_authorization_request_endpoint (which indicates that the server does not support PAR) or with explicit configuration that does not set the PushedAuthorizationRequestEndpoint.
It is also an error to attempt to disable UsePushedAuthorization with an identity provider that publishes a discovery document that enables require_pushed_authorization_requests or with explicit configuration that enables the RequirePushedAuthorizationRequests flag.
Usage Examples
services.AddAuthentication(options =>
{
options.DefaultScheme = "cookie";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("cookie")
.AddOpenIdConnect("oidc", options =>
{
options.Authority = "https://localhost:5001";
options.ClientId = "par";
options.ClientSecret = "secret";
options.ResponseType = "code";
options.UsePkce = true;
options.UsePushedAuthorization = true; // <------ New flag on
})Alternative Designs
Instead of adding support for PAR directly to the handler, we could instead allow users of the handler to implement PAR themselves within events. The challenge with the events is that the best currently existing event to use for that purpose is the OnRedirectToIdentityProvider event, and it is raised before the state parameter is computed. There are a couple of ways that I see to work around this:
- Users could make an event that does the following:
- Copy the state parameter computation from the handler
- Push the authorization parameters (including state)
- Change the redirect url to use the client id and request uri
- Copy the rest of the logic of the event handler (without the state parameter computation)
- Another alternative is to add a new event that fires later in the process - immediately after the state parameter is computed. Naming this event is a little tricky, since we already have
OnRedirectToIdentityProvider, and this would also happen when redirecting to the identity provider, just later in the process. If such an even existed, then users of the handler could add use that event to push the authorization parameters and change the redirect url, without needing to copy large amounts of code from the handler into their event.
These two approaches are demonstrated here.
Risks
This is a low risk change. Users would have to opt in to get the new behavior. Existing Oidc scheme configurations are unaffected.
We are making a new outgoing HTTP request to implement this specification, but we're making the request to a url that was supplied by the OIDC authority through the discovery document or directly by the developer using the explicit configuration in the handler.
Activity
Tratcher commentedon Oct 26, 2023
That implies
UsePushedAuthorizationmust bebool?and default to null to distinguish between the unset state and the disabled state. Alternatively require_pushed_authorization_requests would just override UsePushedAuthorization.josephdecock commentedon Oct 27, 2023
I like this alternative, because it keeps the configuration simpler for the consumer of the API - it avoids the complexity of nullable booleans/ternary logic, and if you're working with a provider that declares its requirement for PAR in the metadata document, the handler just does the right thing.
Tratcher commentedon Oct 27, 2023
As part of the infrastructure we'll want some additional fields for this on OpenIdConnectMessage to indicate Pushed auth is being used (or a variant of CreateAuthenticationRequestUrl), as well as something like BuildFormPost for generating the push request.
aspnetcore/src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs
Lines 483 to 496 in 73e0b53
6 remaining items
josephdecock commentedon Apr 11, 2024
I went ahead and did a bit of a proof-of-concept implementation, which I'll share in a moment as a draft PR. The things I've come across so far:
We don't absolutely need to make changes to System.IdentityModel. The main benefit to adding PAR support there would be that when we do discovery, we would get nice properties for the PAR metadata. However, the OIDC Configuration model gives us a dictionary of AdditionalData that contains everything not explicitly modeled in the configuration type, so it's easy enough to get at PAR metadata within the handler. So my thinking is that at least initially, we could implement PAR entirely within this repo. Then if/when wilson adds PAR support, we could potentially take advantage of that later on.
I think we want to add an event that occurs before we make the pushed authorization request, to give users the ability to customize that request. You might want to run your own logic to decide if you were going to push the authentication or do the whole push yourself, and you might also want to use a different form of client authentication (e.g., a private key jwt client assertion). So in my event, I'm proposing that we add two flags - one to indicate that the event handled client authentication, and another to indicate that the event handled the actual push.
Speaking of client authentication, for the pushed authorization request, I am authenticating using client id and secret in the basic auth header. Other requests that we make in this handler use the post body for client secrets, so this is a new behavior. However, all the specs advise against using the post body. E.g., RFC 6749:
My understanding is that auth headers are generally considered safer than a request body, e.g., it would be more obviously wrong to log an auth header. I think we might want to consider using basic auth headers by default in general (separately from this work).
josephdecock commentedon Apr 11, 2024
@halter73 can you help guide me towards next steps please?
josephdecock commentedon Apr 23, 2024
@halter73, just pinging this issue again to see what the next step is.
josephdecock commentedon Apr 30, 2024
I really don't want to be annoying about this issue, I just want to make sure that it isn't waiting on anything from me.
Would it be helpful to consolidate the original API proposal and subsequent discussion into a single doc for API review?
Alternatively, the draft PR (#55069) represents my thinking pretty well, and I created it as a draft because I have not written automated tests. I held off on that thinking that there might be more discussion on this thread, but I can write tests and get the PR ready for review if that is a better way forward.
halter73 commentedon May 31, 2024
Sorry for the delay. I really do want to get this in for .NET 9, and the PR looks good! Feel free to start on the tests. I think those will be easy to update even if we adjust the API.
Yes please. Make sure to include details about the
OnPushAuthorizationevent andPushedAuthorizationContextwhich I think are good additions.I think it might be a good idea to give a way for developers to say use pushed authorization if it's supported by the OIDC provider. Arguably, that should be the default behavior, so it'd be nice if the updated API proposal accounted for that.
Please continue using the API proposal template you used in the initial proposal but copy it into a new comment on this thread. Don't worry about repeating stuff. It's nice to see the progress of the API design. If you could include a super simple example of someone using
OnPushAuthorizationto customize the PAR auth header via theHttpRequestMessageunder the "Usage Examples" section, that'd be great.I see you already submitted AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet#2499 to make the proposed
OpenIdConnectConfigurationchanges. You can leave those out of the updated API proposal in this issue. I'll give a nudge and see if we can't get that merged so we can depend on the new API rather than rely onAdditionalDatain .NET 9.We plan to review this next Thursday if that works for you. Thanks again!
josephdecock commentedon Jun 7, 2024
Updated API Proposal:
Background and Motivation
Pushed Authorization Requests (PAR) is a relatively new OAuth standard that improves the security of OAuth and OIDC flows by moving authorization parameters from the front channel to the back channel (that is, from redirect URLs in the browser to direct machine to machine http calls on the back end).
This prevents an attacker in the browser from
Pushing the authorization parameters also keeps request URLs short. Authorize parameters might get very long when using more complex OAuth and OIDC features such as Rich Authorization Requests, and URLs that are long cause issues in many browsers and networking infrastructure.
The use of PAR is encouraged by the FAPI working group within the OpenID Foundation. For example, the FAPI2.0 Security Profile requires the use of PAR. This security profile is used by many of the groups working on open banking (primarily in Europe), in health care, and in other industries with high security requirements.
PAR is supported by a number of identity providers, including
This proposal aims to add support for PAR to the OidcHandler.
Proposed API
Config Flag
Add a flag to the options to enable the behavior:
namespace Microsoft.AspNetCore.Authentication.OpenIdConnect; public class OpenIdConnectOptions { + /// <summary> + /// Flag to set whether the handler should push authorization parameters on the backchannel before + /// redirecting to the identity provider. + /// The default is 'true'. + /// </summary> + public bool UsePushedAuthorization { get; set; } = true; }When enabled, the parameters that the handler would normally set in the URL when it redirects to the authorize endpoint will instead be sent on a backchannel call to the PAR endpoint, and the resulting request_uri will instead be attached to the redirect, along with the client_id, as per the specification.
Note that there is ongoing discussion about exactly how we ought to go about enabling this feature, especially given the way that this interacts with what discovery tells us.
My current proposal is to enable the config flag by default, and then enable the feature if either of these conditions holds:
UsePushedAuthorizationflag is enabled AND thepushed_authorization_endpointis available in discoveryrequire_pushed_authorization_requestsflag is enabledEvent For Extensibility
Add an event that will be invoked before authorization parameters are pushed to facilitate extensibility. Event implementors can
namespace Microsoft.AspNetCore.Authentication.OpenIdConnect; public class OpenIdConnectEvents { + /// <summary> + /// Invoked before authorization parameters are pushed using PAR. + /// </summary> + public Func<PushedAuthorizationContext, Task> OnPushAuthorization { get; set; } = context => Task.CompletedTask; + /// <summary> + /// Invoked before authorization parameters are pushed during PAR. + /// </summary> + /// <param name="context"></param> + /// <returns></returns> + public virtual Task PushAuthorization(PushedAuthorizationContext context) => OnPushAuthorization(context); }The
PushedAuthorizationContextpassed to the event is similar to the existing context classes used in the other OIDC events. TheOpenIdConnectMessagethat it contains represents the request that the handler will send to the PAR endpoint. The event can manipulate this message to change the pushed parameters.If the event wants to control the behavior of the handler more, there are methods on the context to indicate this intent, similar to many of the other contexts (e.g.,
AuthorizationCodeReceivedContext.HandleCodeRedemption).To control client authentication, there is
HandleClientAuthentication. This causes the handler to not set the client secret.To skip PAR entirely, there is
SkipPush. This indicates that no backchannel call was made in the event, and that the handler should not push either. Instead, the handler will send authorization parameters in the front channel (as if PAR was disabled).To control pushing to the PAR endpoint, there is
HandlePush(string requestUri). This indicates that the event made the backchannel call and received the request_uri as the result. The handler will then use that request_uri when it makes the authorize request.Usage Examples
Basic Usage
Customized Authentication
Alternative Designs
Instead of adding support for PAR directly to the handler, we could instead allow users of the handler to implement PAR themselves within events. The challenge with the events is that the best currently existing event to use for that purpose is the
OnRedirectToIdentityProviderevent, and it is raised before the state parameter is computed. There are a couple of ways that I see to work around this:OnRedirectToIdentityProvider, and this would also happen when redirecting to the identity provider, just later in the process. If such an even existed, then users of the handler could add use that event to push the authorization parameters and change the redirect url, without needing to copy large amounts of code from the handler into their event.These two approaches are demonstrated here.
Risks
This is a low risk change. Users would have to be using an AS that supports PAR to get the new behavior, and they have a flag to opt out. There are some authorization servers that support PAR, but not for all clients. We might want to consider falling back to passing over the front channel if PAR fails.
We are making a new outgoing HTTP request to implement this specification, but we're making the request to a url that was supplied by the OIDC authority through the discovery document or directly by the developer using the explicit configuration in the handler.
amcasey commentedon Jun 10, 2024
[API Review]
<value>elementsProposed enum:
amcasey commentedon Jun 10, 2024
namespace Microsoft.AspNetCore.Authentication.OpenIdConnect; public class OpenIdConnectEvents { + /// <summary> + /// Invoked before authorization parameters are pushed using PAR. + /// </summary> + public Func<PushedAuthorizationContext, Task> OnPushAuthorization { get; set; } = context => Task.CompletedTask; + /// <summary> + /// Invoked before authorization parameters are pushed during PAR. + /// </summary> + /// <param name="context"></param> + /// <returns></returns> + public virtual Task PushAuthorization(PushedAuthorizationContext context) => OnPushAuthorization(context); }amcasey commentedon Jun 10, 2024
API approved!