Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make IsWhitelisted check more robust #38

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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