diff --git a/src/Agent/AutopilotMonitor.Agent/buildcounter.txt b/src/Agent/AutopilotMonitor.Agent/buildcounter.txt index 895152c2..cec64570 100644 --- a/src/Agent/AutopilotMonitor.Agent/buildcounter.txt +++ b/src/Agent/AutopilotMonitor.Agent/buildcounter.txt @@ -1 +1 @@ -748 +749 diff --git a/src/Backend/AutopilotMonitor.Functions/Functions/Config/TestWebhookNotificationFunction.cs b/src/Backend/AutopilotMonitor.Functions/Functions/Config/TestWebhookNotificationFunction.cs index ceb9c590..097c4f79 100644 --- a/src/Backend/AutopilotMonitor.Functions/Functions/Config/TestWebhookNotificationFunction.cs +++ b/src/Backend/AutopilotMonitor.Functions/Functions/Config/TestWebhookNotificationFunction.cs @@ -36,7 +36,22 @@ namespace AutopilotMonitor.Functions.Functions.Config try { // Authentication + TenantAdminOrGA authorization enforced by PolicyEnforcementMiddleware - string userIdentifier = TenantHelper.GetUserIdentifier(req); + var requestCtx = req.GetRequestContext(); + string userIdentifier = requestCtx.UserPrincipalName; + + // Validate tenant access: cross-tenant only for Global Admins + if (!requestCtx.IsGlobalAdmin && !string.Equals(requestCtx.TenantId, tenantId, StringComparison.OrdinalIgnoreCase)) + { + _logger.LogWarning("User {User} from tenant {AuthTenant} attempted to test notification for tenant {TargetTenant}", + userIdentifier, requestCtx.TenantId, tenantId); + var forbiddenResponse = req.CreateResponse(HttpStatusCode.Forbidden); + await forbiddenResponse.WriteAsJsonAsync(new + { + success = false, + message = "Access denied. You can only test notifications for your own tenant." + }); + return forbiddenResponse; + } _logger.LogInformation("Test webhook notification requested by {User} for tenant {TenantId}", userIdentifier, tenantId);