fix(webhooks): fix error when DNS entry has non-ipv4 addresses
This commit is contained in:
parent
00b7f76a5b
commit
e8beb245da
@ -110,7 +110,7 @@ namespace PluralKit.Bot
|
|||||||
await _repo.UpdateSystem(ctx.System.Id, new()
|
await _repo.UpdateSystem(ctx.System.Id, new()
|
||||||
{
|
{
|
||||||
WebhookUrl = null,
|
WebhookUrl = null,
|
||||||
Token = null,
|
WebhookToken = null,
|
||||||
});
|
});
|
||||||
|
|
||||||
await ctx.Reply($"{Emojis.Success} System webhook URL removed.");
|
await ctx.Reply($"{Emojis.Success} System webhook URL removed.");
|
||||||
@ -119,17 +119,14 @@ namespace PluralKit.Bot
|
|||||||
|
|
||||||
var newUrl = ctx.RemainderOrNull();
|
var newUrl = ctx.RemainderOrNull();
|
||||||
if (!await DispatchExt.ValidateUri(newUrl))
|
if (!await DispatchExt.ValidateUri(newUrl))
|
||||||
{
|
throw new PKError($"The URL {newUrl.AsCode()} is invalid or I cannot access it. Are you sure this is a valid, publicly accessible URL?");
|
||||||
await ctx.Reply($"New URL '{newUrl}' is invalid. Are you sure this is a valid, publicly accessible URL?");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var newToken = StringUtils.GenerateToken();
|
var newToken = StringUtils.GenerateToken();
|
||||||
|
|
||||||
await _repo.UpdateSystem(ctx.System.Id, new()
|
await _repo.UpdateSystem(ctx.System.Id, new()
|
||||||
{
|
{
|
||||||
WebhookUrl = newUrl,
|
WebhookUrl = newUrl,
|
||||||
Token = newToken,
|
WebhookToken = newToken,
|
||||||
});
|
});
|
||||||
|
|
||||||
await ctx.Reply($"{Emojis.Success} Successfully the new webhook URL for your system."
|
await ctx.Reply($"{Emojis.Success} Successfully the new webhook URL for your system."
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Net.Sockets;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@ -78,22 +80,24 @@ namespace PluralKit.Core
|
|||||||
|
|
||||||
public static async Task<bool> ValidateUri(string url)
|
public static async Task<bool> ValidateUri(string url)
|
||||||
{
|
{
|
||||||
var uri = new Uri(url);
|
|
||||||
|
|
||||||
IPHostEntry host = null;
|
IPHostEntry host = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var uri = new Uri(url);
|
||||||
host = await Dns.GetHostEntryAsync(uri.DnsSafeHost);
|
host = await Dns.GetHostEntryAsync(uri.DnsSafeHost);
|
||||||
}
|
}
|
||||||
catch (Exception) { }
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (host == null || host.AddressList.Length == 0)
|
if (host == null || host.AddressList.Length == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
#pragma warning disable CS0618
|
#pragma warning disable CS0618
|
||||||
|
|
||||||
foreach (var address in host.AddressList)
|
foreach (var address in host.AddressList.Where(address => address.AddressFamily is AddressFamily.InterNetwork))
|
||||||
{
|
{
|
||||||
if ((address.Address & 0x7f000000) == 0x7f000000) // 127.0/8
|
if ((address.Address & 0x7f000000) == 0x7f000000) // 127.0/8
|
||||||
return false;
|
return false;
|
||||||
@ -105,7 +109,11 @@ namespace PluralKit.Core
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
if (host.AddressList.Any(address => address.IsIPv6LinkLocal))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// we only support IPv4 in prod :(
|
||||||
|
return host.AddressList.Any(address => address.AddressFamily is AddressFamily.InterNetwork);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user