-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Expose method for testing for a local URL consumable without depending on MVC #56770
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
Comments
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
Filing this for API review. I personally like the style of exposing a static method on the Parking in the Backlog for now until we review and figure out when it gets conclusion. |
[API Review]
namespace Microsoft.AspNetCore.Http;
public sealed partial class RedirectHttpResult
{
+ public static bool IsLocalUrl(string? url) => SharedUrlHelper.IsLocalUrl(url);
} API approved! |
Add `IsLocalUrl()` method to `RedirectHttpResult`, which is just a wrapper around `SharedUrlHelper.IsLocalUrl()`. Resolves dotnet#56770.
Uh oh!
There was an error while loading. Please reload this page.
Background and Motivation
I have an endpoint in an Minimal API application using Razor Slices so that native AoT could be supported whilst having a web UI that has an endpoint for handling rendering a sign in page similar to this:
This protects against open redirects via
?ReturnUrl={value}
usingResults.LocalRedirect()
, but in the case that a non-local URL is provided, this causes an HTTP 500 due to these lines of code:aspnetcore/src/Http/Http.Results/src/RedirectHttpResult.cs
Lines 99 to 102 in 90a622d
IUrlHelper.IsLocal()
isn't usable here because it's part of MVC which I don't have otherwise added to the application.To get the desired behaviour of "use
ReturnUrl
if local, otherwise just ignore it and go to the homepage" I'm left with a few options including:IUrlHelper.IsLocalUrl()
;SharedUrlHelper.IsLocalUrl()
;SharedUrlHelper.IsLocalUrl()
.This feels like a "missing piece" of functionality for general utility of lightweight Minimal APIs where MVC isn't a desired dependency of the application.
Proposed API
Usage Examples
Alternative Designs
namespace Microsoft.AspNetCore.Http; public sealed partial class RedirectHttpResult { + public static bool IsLocalUrl(string? url) => SharedUrlHelper.IsLocalUrl(url); }
Or, a new abstraction similar to
IUrlHelper
that is uncoupled from MVC, but then there's lots more open questions about what other functionality should or shouldn't be in it.Risks
Duplication of class name with
Microsoft.AspNetCore.Mvc.Routing.UrlHelper
.The text was updated successfully, but these errors were encountered: