Skip to content

Commit e841a60

Browse files
committed
Restrict returnUrl on Login to local pages
1 parent d152510 commit e841a60

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
stringreturnUrl=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
returnfalse;
205202
}
206203

204+
privatestaticboolIsLocalUrl(stringurl)
205+
{
206+
if(string.IsNullOrWhiteSpace(url))
207+
{
208+
returnfalse;
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
privateconststringAUTH_TKT_USERDATA_DELIMITER="-|-";
208218

209219
privatestaticstringSecurityValidationKey

0 commit comments

Comments
(0)