fix: replace broken private IP checker with IPNetwork library

This commit is contained in:
spiral 2021-12-01 11:48:14 -05:00
parent fc7a6357c0
commit 7c37726afb
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31
7 changed files with 7526 additions and 7495 deletions

View File

@ -222,6 +222,11 @@
"resolved": "2.8.26", "resolved": "2.8.26",
"contentHash": "OiKusGL20vby4uDEswj2IgkdchC1yQ6rwbIkZDVBPIR6al2b7n3pC91elBul9q33KaBgRKhbZH3+2Ur4fnWx2A==" "contentHash": "OiKusGL20vby4uDEswj2IgkdchC1yQ6rwbIkZDVBPIR6al2b7n3pC91elBul9q33KaBgRKhbZH3+2Ur4fnWx2A=="
}, },
"IPNetwork2": {
"type": "Transitive",
"resolved": "2.5.381",
"contentHash": "MUx9JEtZINtK8bqBAOdz8PpGMK5Rfw6NtQ6gzux95AK8EOJ2naQTRKLUOJfm9aPb0rCfZgSoVKBU4XSXUoKxRw=="
},
"Microsoft.AspNetCore.JsonPatch": { "Microsoft.AspNetCore.JsonPatch": {
"type": "Transitive", "type": "Transitive",
"resolved": "3.1.0", "resolved": "3.1.0",
@ -1600,7 +1605,8 @@
"Serilog.Sinks.File": "4.1.0", "Serilog.Sinks.File": "4.1.0",
"SqlKata": "2.3.7", "SqlKata": "2.3.7",
"SqlKata.Execution": "2.3.7", "SqlKata.Execution": "2.3.7",
"System.Interactive.Async": "5.0.0" "System.Interactive.Async": "5.0.0",
"ipnetwork2": "2.5.381"
} }
} }
} }

View File

@ -135,6 +135,11 @@
"System.Diagnostics.DiagnosticSource": "4.5.1" "System.Diagnostics.DiagnosticSource": "4.5.1"
} }
}, },
"IPNetwork2": {
"type": "Transitive",
"resolved": "2.5.381",
"contentHash": "MUx9JEtZINtK8bqBAOdz8PpGMK5Rfw6NtQ6gzux95AK8EOJ2naQTRKLUOJfm9aPb0rCfZgSoVKBU4XSXUoKxRw=="
},
"Microsoft.Bcl.AsyncInterfaces": { "Microsoft.Bcl.AsyncInterfaces": {
"type": "Transitive", "type": "Transitive",
"resolved": "1.0.0", "resolved": "1.0.0",
@ -1383,7 +1388,8 @@
"Serilog.Sinks.File": "4.1.0", "Serilog.Sinks.File": "4.1.0",
"SqlKata": "2.3.7", "SqlKata": "2.3.7",
"SqlKata.Execution": "2.3.7", "SqlKata.Execution": "2.3.7",
"System.Interactive.Async": "5.0.0" "System.Interactive.Async": "5.0.0",
"ipnetwork2": "2.5.381"
} }
} }
} }

View File

@ -55,6 +55,14 @@ public static class DispatchExt
return new StringContent(JsonConvert.SerializeObject(o), Encoding.UTF8, "application/json"); return new StringContent(JsonConvert.SerializeObject(o), Encoding.UTF8, "application/json");
} }
private static List<IPNetwork> _privateNetworks = new()
{
IPNetwork.IANA_ABLK_RESERVED1, // 10/8
IPNetwork.IANA_CBLK_RESERVED1, // 192.168/16
IPNetwork.Parse("127.0.0.0/8"),
IPNetwork.Parse("169.254.0.0/16"),
};
public static async Task<bool> ValidateUri(string url) public static async Task<bool> ValidateUri(string url)
{ {
IPHostEntry host = null; IPHostEntry host = null;
@ -77,15 +85,7 @@ public static class DispatchExt
foreach (var address in host.AddressList.Where(address => foreach (var address in host.AddressList.Where(address =>
address.AddressFamily is AddressFamily.InterNetwork)) address.AddressFamily is AddressFamily.InterNetwork))
{ {
if ((address.Address & 0x7f000000) == 0x7f000000) // 127.0/8 if (_privateNetworks.Any(net => net.Contains(address)))
return false;
if ((address.Address & 0xa000000) == 0xa000000) // 10.0/8
return false;
if ((address.Address & 0xa9fe0000) == 0xa9fe0000) // 169.254/16
return false;
if ((address.Address & 0xac100000) == 0xac100000) // 172.16/12
return false;
if ((address.Address & 0xc0a80000) == 0xc0a80000) // 192.168/16
return false; return false;
} }

View File

@ -22,6 +22,7 @@
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.1.0" /> <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.1.0" />
<PackageReference Include="Dapper" Version="2.0.35" /> <PackageReference Include="Dapper" Version="2.0.35" />
<PackageReference Include="Dapper.Contrib" Version="2.0.35" /> <PackageReference Include="Dapper.Contrib" Version="2.0.35" />
<PackageReference Include="ipnetwork2" Version="2.5.381" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.1.10" /> <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.1.10" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.10" /> <PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.10" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.10" /> <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.10" />
@ -53,7 +54,7 @@
</ItemGroup> </ItemGroup>
<Target Name="SetSourceRevisionId" BeforeTargets="InitializeSourceControlInformation"> <Target Name="SetSourceRevisionId" BeforeTargets="InitializeSourceControlInformation">
<Exec Command="git log -1 --format='%H' > ../.version" IgnoreExitCode="False"> <Exec Command="git log -1 --format='%H' &gt; ../.version" IgnoreExitCode="False">
</Exec> </Exec>
</Target> </Target>

View File

@ -61,6 +61,12 @@
"System.Reflection.Emit": "4.7.0" "System.Reflection.Emit": "4.7.0"
} }
}, },
"IPNetwork2": {
"type": "Direct",
"requested": "[2.5.381, )",
"resolved": "2.5.381",
"contentHash": "MUx9JEtZINtK8bqBAOdz8PpGMK5Rfw6NtQ6gzux95AK8EOJ2naQTRKLUOJfm9aPb0rCfZgSoVKBU4XSXUoKxRw=="
},
"Microsoft.Extensions.Caching.Memory": { "Microsoft.Extensions.Caching.Memory": {
"type": "Direct", "type": "Direct",
"requested": "[3.1.10, )", "requested": "[3.1.10, )",

View File

@ -122,6 +122,11 @@
"resolved": "2.8.26", "resolved": "2.8.26",
"contentHash": "OiKusGL20vby4uDEswj2IgkdchC1yQ6rwbIkZDVBPIR6al2b7n3pC91elBul9q33KaBgRKhbZH3+2Ur4fnWx2A==" "contentHash": "OiKusGL20vby4uDEswj2IgkdchC1yQ6rwbIkZDVBPIR6al2b7n3pC91elBul9q33KaBgRKhbZH3+2Ur4fnWx2A=="
}, },
"IPNetwork2": {
"type": "Transitive",
"resolved": "2.5.381",
"contentHash": "MUx9JEtZINtK8bqBAOdz8PpGMK5Rfw6NtQ6gzux95AK8EOJ2naQTRKLUOJfm9aPb0rCfZgSoVKBU4XSXUoKxRw=="
},
"Microsoft.Bcl.AsyncInterfaces": { "Microsoft.Bcl.AsyncInterfaces": {
"type": "Transitive", "type": "Transitive",
"resolved": "1.0.0", "resolved": "1.0.0",
@ -1351,7 +1356,8 @@
"Serilog.Sinks.File": "4.1.0", "Serilog.Sinks.File": "4.1.0",
"SqlKata": "2.3.7", "SqlKata": "2.3.7",
"SqlKata.Execution": "2.3.7", "SqlKata.Execution": "2.3.7",
"System.Interactive.Async": "5.0.0" "System.Interactive.Async": "5.0.0",
"ipnetwork2": "2.5.381"
} }
} }
} }

View File

@ -158,6 +158,11 @@
"resolved": "2.8.26", "resolved": "2.8.26",
"contentHash": "OiKusGL20vby4uDEswj2IgkdchC1yQ6rwbIkZDVBPIR6al2b7n3pC91elBul9q33KaBgRKhbZH3+2Ur4fnWx2A==" "contentHash": "OiKusGL20vby4uDEswj2IgkdchC1yQ6rwbIkZDVBPIR6al2b7n3pC91elBul9q33KaBgRKhbZH3+2Ur4fnWx2A=="
}, },
"IPNetwork2": {
"type": "Transitive",
"resolved": "2.5.381",
"contentHash": "MUx9JEtZINtK8bqBAOdz8PpGMK5Rfw6NtQ6gzux95AK8EOJ2naQTRKLUOJfm9aPb0rCfZgSoVKBU4XSXUoKxRw=="
},
"Microsoft.AspNetCore.JsonPatch": { "Microsoft.AspNetCore.JsonPatch": {
"type": "Transitive", "type": "Transitive",
"resolved": "3.1.0", "resolved": "3.1.0",
@ -1753,7 +1758,8 @@
"Serilog.Sinks.File": "4.1.0", "Serilog.Sinks.File": "4.1.0",
"SqlKata": "2.3.7", "SqlKata": "2.3.7",
"SqlKata.Execution": "2.3.7", "SqlKata.Execution": "2.3.7",
"System.Interactive.Async": "5.0.0" "System.Interactive.Async": "5.0.0",
"ipnetwork2": "2.5.381"
} }
} }
} }