Skip to content

Commit

Permalink
bug 65729
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelbannov committed Jan 10, 2024
1 parent 6d1341b commit 9d38560
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
30 changes: 29 additions & 1 deletion common/ASC.Webhooks.Core/DbWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode

using System.Net.NetworkInformation;
using System.Security;

using AutoMapper;

using Microsoft.Extensions.Configuration;

namespace ASC.Webhooks.Core;

[Scope]
Expand All @@ -42,6 +47,7 @@ public class DbWorker
private readonly TenantManager _tenantManager;
private readonly AuthContext _authContext;
private readonly IMapper _mapper;
private readonly IConfiguration _configuration;

private int Tenant
{
Expand All @@ -55,12 +61,14 @@ public DbWorker(
IDbContextFactory<WebhooksDbContext> dbContextFactory,
TenantManager tenantManager,
AuthContext authContext,
IMapper mapper)
IMapper mapper,
IConfiguration configuration)
{
_dbContextFactory = dbContextFactory;
_tenantManager = tenantManager;
_authContext = authContext;
_mapper = mapper;
_configuration = configuration;
}

public async Task<WebhooksConfig> AddWebhookConfig(string uri, string name, string secretKey, bool? enabled, bool? ssl)
Expand All @@ -74,6 +82,26 @@ public async Task<WebhooksConfig> AddWebhookConfig(string uri, string name, stri
return objForCreate;
}

try
{
if (Uri.TryCreate(uri, UriKind.Absolute, out var parsedUri) && NetworkInterface.GetIsNetworkAvailable())
{
foreach (var netInterface in NetworkInterface.GetAllNetworkInterfaces())
{
var ipProps = netInterface.GetIPProperties();

if (ipProps.UnicastAddresses.Any(addr => addr.Address.ToString() == parsedUri.Host))
{
throw new SecurityException();
}
}
}
}
catch (Exception)
{
// ignored
}

var toAdd = new WebhooksConfig
{
TenantId = Tenant,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode

using System.ComponentModel.DataAnnotations;

namespace ASC.Web.Api.ApiModels.RequestsDto;

/// <summary>
Expand All @@ -40,6 +42,7 @@ public class WebhooksConfigRequestsDto

/// <summary>URI</summary>
/// <type>System.String, System</type>
[Url]
public string Uri { get; set; }

/// <summary>Secret key</summary>
Expand Down

0 comments on commit 9d38560

Please sign in to comment.