mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-15 19:22:19 +08:00
fix(core): filter webhook urls
This commit is contained in:
parent
b85988861e
commit
8c9c947d0f
|
@ -47,6 +47,12 @@ namespace BililiveRecorder.Core.SimpleWebhook
|
|||
|
||||
private async Task SendImplAsync(string url, byte[] data)
|
||||
{
|
||||
if (!BasicWebhookV2.IsUrlAllowed(url))
|
||||
{
|
||||
logger.Warning("不支持向 {Url} 发送 Webhook,已跳过", url);
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < 3; i++)
|
||||
try
|
||||
{
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
|
@ -67,6 +68,12 @@ namespace BililiveRecorder.Core.SimpleWebhook
|
|||
|
||||
private async Task SendImplAsync(string url, byte[] data)
|
||||
{
|
||||
if (!IsUrlAllowed(url))
|
||||
{
|
||||
logger.Warning("不支持向 {Url} 发送 Webhook,已跳过", url);
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < 3; i++)
|
||||
try
|
||||
{
|
||||
|
@ -85,5 +92,44 @@ namespace BililiveRecorder.Core.SimpleWebhook
|
|||
logger.Warning(ex, "发送 WebhookV2 到 {Url} 失败", url);
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly IReadOnlyList<string> DisallowedDomains = new[]
|
||||
{
|
||||
"test.example.com",
|
||||
"baidu" + ".com",
|
||||
"qq" + ".com",
|
||||
"google" + ".com",
|
||||
"b23" + ".tv",
|
||||
"bilibili" + ".com",
|
||||
"bilibili" + ".cn",
|
||||
"bilibili" + ".tv",
|
||||
"bilicomic" + ".com",
|
||||
"bilicomics" + ".com",
|
||||
"bilivideo" + ".com",
|
||||
"bilivideo" + ".cn",
|
||||
"biligame" + ".com",
|
||||
"biligame" + ".net",
|
||||
"biliapi" + ".com",
|
||||
"biliapi" + ".net",
|
||||
"hdslb" + ".com",
|
||||
};
|
||||
|
||||
internal static bool IsUrlAllowed(string url)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(url))
|
||||
return false;
|
||||
|
||||
if (!Uri.TryCreate(url, UriKind.Absolute, out var uri))
|
||||
return false;
|
||||
|
||||
if (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps)
|
||||
return false;
|
||||
|
||||
foreach (var domain in DisallowedDomains)
|
||||
if (uri.Host.EndsWith(domain, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user