Skip to content

Commit a4e5c3d

Browse files
authored
Merge pull request BlogEngine#208 from irbishop/CVE-2019-10721
Restrict returnUrl to local pages
2 parents 3a293d6 + e841a60 commit a4e5c3d

File tree

1 file changed

+14
-4
lines changed
  • BlogEngine/BlogEngine.Core/Services/Security

1 file changed

+14
-4
lines changed

BlogEngine/BlogEngine.Core/Services/Security/Security.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,7 @@ public static bool AuthenticateUser(string username, string password, bool remem
185185
string returnUrl = context.Request.QueryString["returnUrl"];
186186

187187
// ignore Return URLs not beginning with a forward slash, such as remote sites.
188-
if (string.IsNullOrWhiteSpace(returnUrl) || !returnUrl.StartsWith("/"))
189-
returnUrl = null;
190-
191-
if (!string.IsNullOrWhiteSpace(returnUrl))
188+
if (Security.IsLocalUrl(returnUrl))
192189
{
193190
context.Response.Redirect(returnUrl);
194191
}
@@ -204,6 +201,19 @@ public static bool AuthenticateUser(string username, string password, bool remem
204201
return false;
205202
}
206203

204+
private static bool IsLocalUrl(string url)
205+
{
206+
if (string.IsNullOrWhiteSpace(url))
207+
{
208+
return false;
209+
}
210+
else
211+
{
212+
return ((url[0] == '/' && (url.Length == 1 || (url[1] != '/' && url[1] != '\\'))) || // "/" or "/foo" but not "//" or "/\"
213+
(url.Length > 1 && url[0] == '~' && url[1] == '/')); // "~/" or "~/foo"
214+
}
215+
}
216+
207217
private const string AUTH_TKT_USERDATA_DELIMITER = "-|-";
208218

209219
private static string SecurityValidationKey

0 commit comments

Comments
 (0)