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.

Prevent for open redirection attack - last continue shopping page should be save a local path

KrzysztofPajakbdb0e109e3a4
diff --git a/src/Web/Grand.Web/Controllers/AccountController.cs b/src/Web/Grand.Web/Controllers/AccountController.cs
index b167d4737..dbcfabfd8 100644
--- a/src/Web/Grand.Web/Controllers/AccountController.cs
+++ b/src/Web/Grand.Web/Controllers/AccountController.cs
@@ -482,7 +482,7 @@ namespace Grand.Web.Controllers
await _messageProviderService.SendCustomerWelcomeMessage(_workContext.CurrentCustomer, _workContext.CurrentStore, _workContext.WorkingLanguage.Id);
var redirectUrl = Url.RouteUrl("RegisterResult", new { resultId = (int)UserRegistrationType.Standard }, HttpContext.Request.Scheme);
- if (!String.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
+ if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
{
redirectUrl = CommonExtensions.ModifyQueryString(redirectUrl, "returnurl", returnUrl);
}
diff --git a/src/Web/Grand.Web/Controllers/CatalogController.cs b/src/Web/Grand.Web/Controllers/CatalogController.cs
index bc7d7dc40..f023003e4 100644
--- a/src/Web/Grand.Web/Controllers/CatalogController.cs
+++ b/src/Web/Grand.Web/Controllers/CatalogController.cs
@@ -24,7 +24,6 @@ using Grand.Web.Features.Models.Vendors;
using Grand.Web.Models.Catalog;
using Grand.Web.Models.Vendors;
using MediatR;
-using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
@@ -93,14 +92,13 @@ namespace Grand.Web.Controllers
{
await _userFieldService.SaveField(customer,
SystemCustomerFieldNames.LastContinueShoppingPage,
- HttpContext?.Request?.GetDisplayUrl(),
+ HttpContext.Request.Path,
_workContext.CurrentStore.Id);
}
private VendorReviewOverviewModel PrepareVendorReviewOverviewModel(Vendor vendor)
{
- var model = new VendorReviewOverviewModel()
- {
+ var model = new VendorReviewOverviewModel() {
RatingSum = vendor.ApprovedRatingSum,
TotalReviews = vendor.ApprovedTotalReviews,
VendorId = vendor.Id,
@@ -148,8 +146,7 @@ namespace Grand.Web.Controllers
await _customerActionEventService.Viewed(customer, HttpContext.Request.Path.ToString(), Request.GetTypedHeaders().Referer?.ToString());
//model
- var model = await _mediator.Send(new GetCategory()
- {
+ var model = await _mediator.Send(new GetCategory() {
Category = category,
Command = command,
Currency = _workContext.WorkingCurrency,
@@ -203,8 +200,7 @@ namespace Grand.Web.Controllers
await _customerActionEventService.Viewed(customer, HttpContext.Request.Path.ToString(), Request.GetTypedHeaders().Referer?.ToString());
//model
- var model = await _mediator.Send(new GetBrand()
- {
+ var model = await _mediator.Send(new GetBrand() {
Command = command,
Currency = _workContext.WorkingCurrency,
Customer = _workContext.CurrentCustomer,
@@ -221,8 +217,7 @@ namespace Grand.Web.Controllers
public virtual async Task<IActionResult> BrandAll()
{
- var model = await _mediator.Send(new GetBrandAll()
- {
+ var model = await _mediator.Send(new GetBrandAll() {
Customer = _workContext.CurrentCustomer,
Language = _workContext.WorkingLanguage,
Store = _workContext.CurrentStore
@@ -269,8 +264,7 @@ namespace Grand.Web.Controllers
await _customerActionEventService.Viewed(customer, HttpContext.Request.Path.ToString(), Request.GetTypedHeaders().Referer?.ToString());
//model
- var model = await _mediator.Send(new GetCollection()
- {
+ var model = await _mediator.Send(new GetCollection() {
Command = command,
Currency = _workContext.WorkingCurrency,
Customer = _workContext.CurrentCustomer,
@@ -287,8 +281,7 @@ namespace Grand.Web.Controllers
public virtual async Task<IActionResult> CollectionAll()
{
- var model = await _mediator.Send(new GetCollectionAll()
- {
+ var model = await _mediator.Send(new GetCollectionAll() {
Customer = _workContext.CurrentCustomer,
Language = _workContext.WorkingLanguage,
Store = _workContext.CurrentStore
@@ -319,8 +312,7 @@ namespace Grand.Web.Controllers
if (await _permissionService.Authorize(StandardPermission.AccessAdminPanel, customer) && await _permissionService.Authorize(StandardPermission.ManageCollections, customer))
DisplayEditLink(Url.Action("Edit", "Vendor", new { id = vendor.Id, area = "Admin" }));
- var model = await _mediator.Send(new GetVendor()
- {
+ var model = await _mediator.Send(new GetVendor() {
Command = command,
Vendor = vendor,
Language = _workContext.WorkingLanguage,
@@ -372,8 +364,7 @@ namespace Grand.Web.Controllers
//allow reviews only by customer that bought something from this vendor
if (_vendorSettings.VendorReviewPossibleOnlyAfterPurchasing &&
- !(await _mediator.Send(new GetOrderQuery()
- {
+ !(await _mediator.Send(new GetOrderQuery() {
CustomerId = _workContext.CurrentCustomer.Id,
VendorId = vendor.Id,
Os = (int)OrderStatusSystem.Complete,
@@ -381,9 +372,9 @@ namespace Grand.Web.Controllers
})).Any())
ModelState.AddModelError(string.Empty, _translationService.GetResource("VendorReviews.VendorReviewPossibleOnlyAfterPurchasing"));
- if(ModelState.IsValid && _vendorSettings.VendorReviewPossibleOnlyOnce)
+ if (ModelState.IsValid && _vendorSettings.VendorReviewPossibleOnlyOnce)
{
- if((await _vendorService.GetAllVendorReviews(
+ if ((await _vendorService.GetAllVendorReviews(
customerId: _workContext.CurrentCustomer.Id,
approved: null,
vendorId: vendor.Id,
@@ -411,7 +402,7 @@ namespace Grand.Web.Controllers
if (!vendorReview.IsApproved)
model.AddVendorReview.Result = _translationService.GetResource("VendorReviews.SeeAfterApproving");
else
- {
+ {
model.AddVendorReview.Result = _translationService.GetResource("VendorReviews.SuccessfullyAdded");
model.VendorReviewOverview = PrepareVendorReviewOverviewModel(vendor);
}
@@ -459,8 +450,7 @@ namespace Grand.Web.Controllers
});
}
- vendorReview = await _mediator.Send(new SetVendorReviewHelpfulnessCommand()
- {
+ vendorReview = await _mediator.Send(new SetVendorReviewHelpfulnessCommand() {
Customer = _workContext.CurrentCustomer,
Vendor = vendor,
Review = vendorReview,
@@ -485,8 +475,7 @@ namespace Grand.Web.Controllers
if (productTag == null)
return InvokeHttp404();
- var model = await _mediator.Send(new GetProductsByTag()
- {
+ var model = await _mediator.Send(new GetProductsByTag() {
Command = command,
Language = _workContext.WorkingLanguage,
ProductTag = productTag,
@@ -501,8 +490,7 @@ namespace Grand.Web.Controllers
if (productTag == null)
return InvokeHttp404();
- var model = await _mediator.Send(new GetProductsByTag()
- {
+ var model = await _mediator.Send(new GetProductsByTag() {
Command = command,
Language = _workContext.WorkingLanguage,
ProductTag = productTag,
@@ -514,8 +502,7 @@ namespace Grand.Web.Controllers
public virtual async Task<IActionResult> ProductTagsAll()
{
- var model = await _mediator.Send(new GetProductTagsAll()
- {
+ var model = await _mediator.Send(new GetProductTagsAll() {
Language = _workContext.WorkingLanguage,
Store = _workContext.CurrentStore
});
@@ -537,8 +524,7 @@ namespace Grand.Web.Controllers
}
//Prepare model
var isSearchTermSpecified = HttpContext?.Request?.Query.ContainsKey("q");
- var searchmodel = await _mediator.Send(new GetSearch()
- {
+ var searchmodel = await _mediator.Send(new GetSearch() {
Command = command,
Currency = _workContext.WorkingCurrency,
Customer = _workContext.CurrentCustomer,
@@ -555,8 +541,7 @@ namespace Grand.Web.Controllers
if (String.IsNullOrWhiteSpace(term) || term.Length < catalogSettings.ProductSearchTermMinimumLength)
return Content("");
- var result = await _mediator.Send(new GetSearchAutoComplete()
- {
+ var result = await _mediator.Send(new GetSearchAutoComplete() {
CategoryId = categoryId,
Term = term.Trim(),
Customer = _workContext.CurrentCustomer,
diff --git a/src/Web/Grand.Web/Controllers/CommonController.cs b/src/Web/Grand.Web/Controllers/CommonController.cs
index d08c45688..f4016878c 100644
--- a/src/Web/Grand.Web/Controllers/CommonController.cs
+++ b/src/Web/Grand.Web/Controllers/CommonController.cs
@@ -326,8 +326,6 @@ namespace Grand.Web.Controllers
return Redirect(returnUrl);
}
-
-
//contact us page
//available even when a store is closed
[ClosedStore(true)]
diff --git a/src/Web/Grand.Web/Controllers/CourseController.cs b/src/Web/Grand.Web/Controllers/CourseController.cs
index 8252d9942..b96c0e597 100644
--- a/src/Web/Grand.Web/Controllers/CourseController.cs
+++ b/src/Web/Grand.Web/Controllers/CourseController.cs
@@ -104,9 +104,6 @@ namespace Grand.Web.Controllers
if (!await CheckPermission(course, customer))
return InvokeHttp404();
- //'Continue shopping' URL
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.LastContinueShoppingPage, HttpContext?.Request?.GetDisplayUrl(), _workContext.CurrentStore.Id);
-
//display "edit" (manage) link
if (await _permissionService.Authorize(StandardPermission.AccessAdminPanel, customer) && await _permissionService.Authorize(StandardPermission.ManageCourses, customer))
DisplayEditLink(Url.Action("Edit", "Course", new { id = course.Id, area = "Admin" }));
@@ -141,9 +138,6 @@ namespace Grand.Web.Controllers
if (!await CheckPermission(course, customer))
return InvokeHttp404();
- //'Continue shopping' URL
- await _userFieldService.SaveField(customer, SystemCustomerFieldNames.LastContinueShoppingPage, HttpContext?.Request?.GetDisplayUrl(), _workContext.CurrentStore.Id);
-
//display "edit" (manage) link
if (await _permissionService.Authorize(StandardPermission.AccessAdminPanel, customer) && await _permissionService.Authorize(StandardPermission.ManageCourses, customer))
DisplayEditLink(Url.Action("EditLesson", "Course", new { id = lesson.Id, area = "Admin" }));
@@ -152,7 +146,7 @@ namespace Grand.Web.Controllers
_ = _customerActivityService.InsertActivity("PublicStore.ViewLesson", lesson.Id,
_workContext.CurrentCustomer, HttpContext.Connection?.RemoteIpAddress?.ToString(),
_translationService.GetResource("ActivityLog.PublicStore.ViewLesson"), lesson.Name);
- await _customerActionEventService.Viewed(customer, HttpContext.Request.Path.ToString(), Request.GetTypedHeaders().Referer?.ToString());
+ await _customerActionEventService.Viewed(customer, HttpContext.Request.Path, Request.GetTypedHeaders().Referer?.ToString());
//model
var model = await _mediator.Send(new GetLesson() {
diff --git a/src/Web/Grand.Web/Controllers/ShoppingCartController.cs b/src/Web/Grand.Web/Controllers/ShoppingCartController.cs
index f70e18f39..cb50b0eab 100644
--- a/src/Web/Grand.Web/Controllers/ShoppingCartController.cs
+++ b/src/Web/Grand.Web/Controllers/ShoppingCartController.cs
@@ -123,8 +123,7 @@ namespace Grand.Web.Controllers
{
var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
- var checkoutAttributes = await _mediator.Send(new SaveCheckoutAttributesCommand()
- {
+ var checkoutAttributes = await _mediator.Send(new SaveCheckoutAttributesCommand() {
Customer = _workContext.CurrentCustomer,
Store = _workContext.CurrentStore,
Cart = cart,
@@ -145,8 +144,7 @@ namespace Grand.Web.Controllers
disabledAttributeIds.Add(attribute.Id);
}
}
- var model = await _mediator.Send(new GetOrderTotals()
- {
+ var model = await _mediator.Send(new GetOrderTotals() {
Cart = cart,
IsEditable = true,
Store = _workContext.CurrentStore,
@@ -239,8 +237,7 @@ namespace Grand.Web.Controllers
}
}
- var download = new Download
- {
+ var download = new Download {
DownloadGuid = Guid.NewGuid(),
UseDownloadUrl = false,
DownloadUrl = "",
@@ -270,8 +267,7 @@ namespace Grand.Web.Controllers
return RedirectToRoute("HomePage");
var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
- var model = await _mediator.Send(new GetShoppingCart()
- {
+ var model = await _mediator.Send(new GetShoppingCart() {
Cart = cart,
ValidateCheckoutAttributes = checkoutAttributes,
Customer = _workContext.CurrentCustomer,
@@ -411,8 +407,7 @@ namespace Grand.Web.Controllers
await _shoppingCartService.DeleteShoppingCartItem(_workContext.CurrentCustomer, item, ensureOnlyActiveCheckoutAttributes: true);
}
- var miniShoppingCartmodel = await _mediator.Send(new GetMiniShoppingCart()
- {
+ var miniShoppingCartmodel = await _mediator.Send(new GetMiniShoppingCart() {
Customer = _workContext.CurrentCustomer,
Currency = _workContext.WorkingCurrency,
Language = _workContext.WorkingLanguage,
@@ -430,8 +425,7 @@ namespace Grand.Web.Controllers
else
{
var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
- var shoppingcartmodel = await _mediator.Send(new GetShoppingCart()
- {
+ var shoppingcartmodel = await _mediator.Send(new GetShoppingCart() {
Cart = cart,
Customer = _workContext.CurrentCustomer,
Currency = _workContext.WorkingCurrency,
@@ -473,8 +467,7 @@ namespace Grand.Web.Controllers
await _customerService.UpdateShoppingCartItem(_workContext.CurrentCustomer.Id, item);
}
- var miniShoppingCart = await _mediator.Send(new GetMiniShoppingCart()
- {
+ var miniShoppingCart = await _mediator.Send(new GetMiniShoppingCart() {
Customer = _workContext.CurrentCustomer,
Currency = _workContext.WorkingCurrency,
Language = _workContext.WorkingLanguage,
@@ -483,8 +476,7 @@ namespace Grand.Web.Controllers
});
var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
- var shoppingcartmodel = await _mediator.Send(new GetShoppingCart()
- {
+ var shoppingcartmodel = await _mediator.Send(new GetShoppingCart() {
Cart = cart,
Customer = _workContext.CurrentCustomer,
Currency = _workContext.WorkingCurrency,
@@ -504,14 +496,10 @@ namespace Grand.Web.Controllers
public virtual IActionResult ContinueShopping()
{
var returnUrl = _workContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.LastContinueShoppingPage, _workContext.CurrentStore.Id);
- if (!string.IsNullOrEmpty(returnUrl))
- {
+ if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
return Redirect(returnUrl);
- }
- else
- {
- return RedirectToRoute("HomePage");
- }
+
+ return RedirectToRoute("HomePage");
}
[DenySystemAccount]
@@ -522,8 +510,7 @@ namespace Grand.Web.Controllers
//parse and save checkout attributes
if (form != null && form.Count > 0)
{
- checkoutAttributes = (await _mediator.Send(new SaveCheckoutAttributesCommand()
- {
+ checkoutAttributes = (await _mediator.Send(new SaveCheckoutAttributesCommand() {
Customer = _workContext.CurrentCustomer,
Store = _workContext.CurrentStore,
Cart = cart,
@@ -634,8 +621,7 @@ namespace Grand.Web.Controllers
isApplied = false;
}
- var model = await _mediator.Send(new GetShoppingCart()
- {
+ var model = await _mediator.Send(new GetShoppingCart() {
Cart = cart,
Customer = _workContext.CurrentCustomer,
Currency = _workContext.WorkingCurrency,
@@ -670,7 +656,7 @@ namespace Grand.Web.Controllers
if (!string.IsNullOrWhiteSpace(giftvouchercouponcode))
{
var giftVoucher = (await _mediator.Send(new GetGiftVoucherQuery() { Code = giftvouchercouponcode, IsGiftVoucherActivated = true })).FirstOrDefault();
- var isGiftVoucherValid = giftVoucher != null
+ var isGiftVoucherValid = giftVoucher != null
&& giftVoucher.IsGiftVoucherValid(_workContext.WorkingCurrency, _workContext.CurrentStore);
if (isGiftVoucherValid)
@@ -694,8 +680,7 @@ namespace Grand.Web.Controllers
isApplied = false;
}
- var model = await _mediator.Send(new GetShoppingCart()
- {
+ var model = await _mediator.Send(new GetShoppingCart() {
Cart = cart,
Customer = _workContext.CurrentCustomer,
Currency = _workContext.WorkingCurrency,
@@ -719,8 +704,7 @@ namespace Grand.Web.Controllers
{
var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.ShoppingCart, ShoppingCartType.Auctions);
- var model = await _mediator.Send(new GetEstimateShippingResult()
- {
+ var model = await _mediator.Send(new GetEstimateShippingResult() {
Cart = cart,
Currency = _workContext.WorkingCurrency,
Customer = _workContext.CurrentCustomer,
@@ -755,8 +739,7 @@ namespace Grand.Web.Controllers
}
var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
- var model = await _mediator.Send(new GetShoppingCart()
- {
+ var model = await _mediator.Send(new GetShoppingCart() {
Cart = cart,
Customer = _workContext.CurrentCustomer,
Currency = _workContext.WorkingCurrency,
@@ -788,8 +771,7 @@ namespace Grand.Web.Controllers
}
var cart = await _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, PrepareCartTypes());
- var model = await _mediator.Send(new GetShoppingCart()
- {
+ var model = await _mediator.Send(new GetShoppingCart() {
Cart = cart,
Customer = _workContext.CurrentCustomer,
Currency = _workContext.WorkingCurrency,