Skip to content

Commit

Permalink
Merge pull request #38 from bdukes/whitelist-port
Browse files Browse the repository at this point in the history
Make IsWhitelisted check more robust
  • Loading branch information
StevenFisherCantarus authored Sep 7, 2018
2 parents 85cc273 + 1a319eb commit 3f33ae5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions PolyDeploy/Components/IPSpecManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Cantarus.Modules.PolyDeploy.Components.DataAccess.Models;
using System;
using System.Collections.Generic;
using System.Net;

namespace Cantarus.Modules.PolyDeploy.Components
{
Expand Down Expand Up @@ -51,6 +52,20 @@ public static IPSpec GetById(int id)
*/
public static bool IsWhitelisted(string address)
{
if (!IPAddress.TryParse(address, out _))
{
// see if address is an IP plus port, e.g. "1.1.1.1:58290"
if (Uri.TryCreate(Uri.UriSchemeHttps + Uri.SchemeDelimiter + address, UriKind.Absolute, out Uri uri))
{
if (uri.HostNameType != UriHostNameType.IPv4 && uri.HostNameType != UriHostNameType.IPv6)
{
return false;
}

address = uri.Host;
}
}

IPSpec ipSpec = IPSpecDC.FindByAddress(address);

return ipSpec != null;
Expand Down

0 comments on commit 3f33ae5

Please sign in to comment.