Skip to content

Instantly share code, notes, and snippets.

@michaelhidalgo
Last active October 27, 2015 20:24
Show Gist options
  • Save michaelhidalgo/52be95e1c87ba20646b9 to your computer and use it in GitHub Desktop.
Save michaelhidalgo/52be95e1c87ba20646b9 to your computer and use it in GitHub Desktop.
OpenRedirects
static void Main(string[] args)
{
var url = "https://www.gogole.com";
var result = url.IsLocalUrl();
Console.WriteLine(result);
Console.ReadKey();
}
public static bool IsLocalUrl(this string url)
{
return !url.IsEmpty() &&
((url[0] == '/' && (url.Length == 1 ||
(url[1] != '/' && url[1] != '\\'))) || // "/" or "/foo" but not "//" or "/\"
(url.Length > 1 &&
url[0] == '~' && url[1] == '/')); // "~/" or "~/foo"
}
public static bool IsEmpty(this string value) {
return string.IsNullOrEmpty(value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment