diff --git a/Endpoint/Common/Attributes/LocalhostAttribute.cs b/Endpoint/Common/Attributes/LocalhostAttribute.cs index 734e0bf..7a483ca 100644 --- a/Endpoint/Common/Attributes/LocalhostAttribute.cs +++ b/Endpoint/Common/Attributes/LocalhostAttribute.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; +using System; using System.Net; namespace Mirea.Api.Endpoint.Common.Attributes; @@ -9,11 +10,21 @@ public class LocalhostAttribute : ActionFilterAttribute public override void OnActionExecuting(ActionExecutingContext context) { var ip = context.HttpContext.Connection.RemoteIpAddress; - if (ip == null || !IPAddress.IsLoopback(ip)) + + if (ip == null) { context.Result = new UnauthorizedResult(); return; } - base.OnActionExecuting(context); + + var isRunningInContainer = Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER")?.ToLower() == "true"; + + if (IPAddress.IsLoopback(ip) || (isRunningInContainer && ip.ToString().StartsWith("172."))) + { + base.OnActionExecuting(context); + return; + } + + context.Result = new UnauthorizedResult(); } } \ No newline at end of file