Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Simplify returnUrl handling in controllers

KrzysztofPajak7c33dd22fabf
diff --git a/src/Web/Grand.Web.Admin/Controllers/HomeController.cs b/src/Web/Grand.Web.Admin/Controllers/HomeController.cs
index bb98e4823..d45e1528c 100644
--- a/src/Web/Grand.Web.Admin/Controllers/HomeController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/HomeController.cs
@@ -150,7 +150,7 @@ public class HomeController : BaseAdminController
SystemCustomerFieldNames.AdminAreaStoreScopeConfiguration, "");
//home page
- if (string.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl))
+ if (!Url.IsLocalUrl(returnUrl))
returnUrl = Url.Action("Index", "Home", new { area = Constants.AreaAdmin });
return Redirect(returnUrl);
diff --git a/src/Web/Grand.Web/Controllers/CommonController.cs b/src/Web/Grand.Web/Controllers/CommonController.cs
index 19c4a9d0c..c975bfd11 100644
--- a/src/Web/Grand.Web/Controllers/CommonController.cs
+++ b/src/Web/Grand.Web/Controllers/CommonController.cs
@@ -143,16 +143,12 @@ public class CommonController : BasePublicController
public virtual async Task<IActionResult> SetLanguage(
[FromServices] AppConfig config,
[FromServices] ICustomerService customerService,
- string langCode, string returnUrl = default)
+ string langCode, string returnUrl = "")
{
var language = await _languageService.GetLanguageByCode(langCode);
if (!language?.Published ?? false)
language = _workContext.WorkingLanguage;
- //home page
- if (string.IsNullOrEmpty(returnUrl))
- returnUrl = Url.RouteUrl("HomePage");
-
//prevent open redirection attack
if (!Url.IsLocalUrl(returnUrl))
returnUrl = Url.RouteUrl("HomePage");
@@ -227,10 +223,6 @@ public class CommonController : BasePublicController
//notification
await _mediator.Publish(new ChangeCurrencyEvent(_workContext.CurrentCustomer, currency));
- //home page
- if (string.IsNullOrEmpty(returnUrl))
- returnUrl = Url.RouteUrl("HomePage");
-
//prevent open redirection attack
if (!Url.IsLocalUrl(returnUrl))
returnUrl = Url.RouteUrl("HomePage");
@@ -266,10 +258,6 @@ public class CommonController : BasePublicController
}
}
- //home page
- if (string.IsNullOrEmpty(returnUrl))
- returnUrl = Url.RouteUrl("HomePage");
-
//prevent open redirection attack
if (!Url.IsLocalUrl(returnUrl))
returnUrl = Url.RouteUrl("HomePage");
@@ -284,14 +272,10 @@ public class CommonController : BasePublicController
public virtual async Task<IActionResult> SetTaxType(
[FromServices] TaxSettings taxSettings,
[FromServices] ICustomerService customerService,
- int customerTaxType, string returnUrl = default)
+ int customerTaxType, string returnUrl = "")
{
var taxDisplayType = (TaxDisplayType)Enum.ToObject(typeof(TaxDisplayType), customerTaxType);
- //home page
- if (string.IsNullOrEmpty(returnUrl))
- returnUrl = Url.RouteUrl("HomePage");
-
//prevent open redirection attack
if (!Url.IsLocalUrl(returnUrl))
returnUrl = Url.RouteUrl("HomePage");
@@ -324,10 +308,6 @@ public class CommonController : BasePublicController
//notification
await _mediator.Publish(new ChangeThemeEvent(_workContext.CurrentCustomer, themeName));
- //home page
- if (string.IsNullOrEmpty(returnUrl))
- returnUrl = Url.RouteUrl("HomePage");
-
//prevent open redirection attack
if (!Url.IsLocalUrl(returnUrl))
returnUrl = Url.RouteUrl("HomePage");