Skip to content

Commit

Permalink
Merge pull request BlogEngine#208 from irbishop/CVE-2019-10721
Browse files Browse the repository at this point in the history
Restrict returnUrl to local pages
  • Loading branch information
rxtur authored Apr 23, 2019
2 parents 3a293d6 + e841a60 commit a4e5c3d
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions BlogEngine/BlogEngine.Core/Services/Security/Security.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,7 @@ public static bool AuthenticateUser(string username, string password, bool remem
string returnUrl = context.Request.QueryString["returnUrl"];

// ignore Return URLs not beginning with a forward slash, such as remote sites.
if (string.IsNullOrWhiteSpace(returnUrl) || !returnUrl.StartsWith("/"))
returnUrl = null;

if (!string.IsNullOrWhiteSpace(returnUrl))
if (Security.IsLocalUrl(returnUrl))
{
context.Response.Redirect(returnUrl);
}
Expand All @@ -204,6 +201,19 @@ public static bool AuthenticateUser(string username, string password, bool remem
return false;
}

private static bool IsLocalUrl(string url)
{
if (string.IsNullOrWhiteSpace(url))
{
return false;
}
else
{
return ((url[0] == '/' && (url.Length == 1 || (url[1] != '/' && url[1] != '\\'))) || // "/" or "/foo" but not "//" or "/\"
(url.Length > 1 && url[0] == '~' && url[1] == '/')); // "~/" or "~/foo"
}
}

private const string AUTH_TKT_USERDATA_DELIMITER = "-|-";

private static string SecurityValidationKey
Expand Down

0 comments on commit a4e5c3d

Please sign in to comment.