Skip to content

Commit

Permalink
Fix code scanning alert no. 234: URL redirection from remote source
Browse files Browse the repository at this point in the history
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
  • Loading branch information
1 parent a03bef8 commit 16fc5c3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Web/Grand.Web/Controllers/CommonController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,11 @@ public virtual async Task<IActionResult> SetStore(
if (string.IsNullOrEmpty(returnUrl))
returnUrl = Url.RouteUrl("HomePage");

// List of valid URLs
var validUrls = new List<string> { Url.RouteUrl("HomePage"), Url.RouteUrl("AnotherSafePage") };

//prevent open redirection attack
if (!Url.IsLocalUrl(returnUrl))
if (!Url.IsLocalUrl(returnUrl) || !validUrls.Contains(returnUrl))
returnUrl = Url.RouteUrl("HomePage");

return Redirect(returnUrl);
Expand All @@ -292,8 +295,11 @@ public virtual async Task<IActionResult> SetTaxType(
if (string.IsNullOrEmpty(returnUrl))
returnUrl = Url.RouteUrl("HomePage");

// List of valid URLs
var validUrls = new List<string> { Url.RouteUrl("HomePage"), Url.RouteUrl("AnotherSafePage") };

//prevent open redirection attack
if (!Url.IsLocalUrl(returnUrl))
if (!Url.IsLocalUrl(returnUrl) || !validUrls.Contains(returnUrl))
returnUrl = Url.RouteUrl("HomePage");

//whether customers are allowed to select tax display type
Expand Down Expand Up @@ -328,8 +334,11 @@ public virtual async Task<IActionResult> SetStoreTheme(
if (string.IsNullOrEmpty(returnUrl))
returnUrl = Url.RouteUrl("HomePage");

// List of valid URLs
var validUrls = new List<string> { Url.RouteUrl("HomePage"), Url.RouteUrl("AnotherSafePage") };

//prevent open redirection attack
if (!Url.IsLocalUrl(returnUrl))
if (!Url.IsLocalUrl(returnUrl) || !validUrls.Contains(returnUrl))
returnUrl = Url.RouteUrl("HomePage");

return Redirect(returnUrl);
Expand Down

0 comments on commit 16fc5c3

Please sign in to comment.