fix(webhooks): don't allow Discord webhook URLs
This commit is contained in:
parent
75c35b7f85
commit
40dbf7dad6
@ -1,3 +1,4 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Myriad.Extensions;
|
using Myriad.Extensions;
|
||||||
@ -13,6 +14,7 @@ namespace PluralKit.Bot
|
|||||||
{
|
{
|
||||||
private readonly ModelRepository _repo;
|
private readonly ModelRepository _repo;
|
||||||
private readonly DispatchService _dispatch;
|
private readonly DispatchService _dispatch;
|
||||||
|
private static readonly Regex _webhookRegex = new(@"https://(?:\\w+.)?discord(?:app)?.com/api(?:/v.*)?/webhooks/(.*)");
|
||||||
public Api(ModelRepository repo, DispatchService dispatch)
|
public Api(ModelRepository repo, DispatchService dispatch)
|
||||||
{
|
{
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
@ -121,6 +123,9 @@ namespace PluralKit.Bot
|
|||||||
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?");
|
throw new PKError($"The URL {newUrl.AsCode()} is invalid or I cannot access it. Are you sure this is a valid, publicly accessible URL?");
|
||||||
|
|
||||||
|
if (_webhookRegex.IsMatch(newUrl))
|
||||||
|
throw new PKError("PluralKit does not currently support setting a Discord webhook URL as your system's webhook URL.");
|
||||||
|
|
||||||
var newToken = StringUtils.GenerateToken();
|
var newToken = StringUtils.GenerateToken();
|
||||||
|
|
||||||
await _repo.UpdateSystem(ctx.System.Id, new()
|
await _repo.UpdateSystem(ctx.System.Id, new()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user