Proxy Configuration Issue with Umbraco Backoffice Requests
All traffic from a customer’s website needs to go through a proxy (except SMTP).
The challenge is that everything is also behind a WAF, making it difficult to determine whether issues are caused by the WAF or by traffic that is not routed through the proxy.
Current Proxy Configuration
if (proxySettings.Enabled)
{
if (!proxySettings.UseSystemDefault && !string.IsNullOrWhiteSpace(proxySettings.ProxyAddress)) {
HttpClient.DefaultProxy = new WebProxy(proxySettings.ProxyAddress)
{
BypassProxyOnLocal = proxySettings.BypassOnLocal,
UseDefaultCredentials = proxySettings.UseDefaultCredentials
};
}
services.AddHttpClient(Options.DefaultName)
.ConfigurePrimaryHttpMessageHandler((sp) =>
{
var settings = sp.GetRequiredService<IOptions>().Value;
return settings.GetHttpMessageHandlerWithProxySettings();
});
services.AddHttpClient(“default”)
.ConfigurePrimaryHttpMessageHandler((sp) =>
{
var settings = sp.GetRequiredService<IOptions>().Value;
return settings.GetHttpMessageHandlerWithProxySettings();
});
services.AddHttpClient(“Umbraco:Forms:HttpClients:Recaptcha3”)
.ConfigurePrimaryHttpMessageHandler((sp) =>
{
var settings = sp.GetRequiredService<IOptions>().Value;
return settings.GetHttpMessageHandlerWithProxySettings();
});
services.AddHttpClient(“vimeoClient”)
.ConfigurePrimaryHttpMessageHandler((sp) =>
{
var settings = sp.GetRequiredService<IOptions>().Value;
return settings.GetHttpMessageHandlerWithProxySettings();
});
}
public static HttpMessageHandler GetHttpMessageHandlerWithProxySettings(this ProxySettings settings)
{
var handler = new HttpClientHandler() { UseProxy = false };
if (settings?.Enabled ?? false)
{
if (settings.UseSystemDefault)
{
// Use system default proxy settings
handler.UseProxy = true;
handler.Proxy = null; // null means use system default
handler.UseDefaultCredentials = settings.UseDefaultCredentials;
}
else if (!string.IsNullOrWhiteSpace(settings.ProxyAddress))
{
var proxy = new WebProxy(settings.ProxyAddress)
{
BypassProxyOnLocal = settings.BypassOnLocal,
UseDefaultCredentials = settings.UseDefaultCredentials
};
handler.UseProxy = true;
handler.Proxy = proxy;
handler.UseDefaultCredentials = settings.UseDefaultCredentials;
}
}
return handler;
}
Additionally, we set the environment variables ALL_PROXY and NO_PROXY (for localhost and smtp) in the web.config. This made no difference.
The setup works for many requests, but not for POST requests from the Umbraco backoffice, such as:
/umbraco/backoffice/umbracoapi/publishedsnapshotcachestatus/ReloadCache/umbraco/backoffice/umbracoapi/content/PostSave
These requests return a 500 error with the following message:
Possibly unhandled rejection: {"errorMsg":"Failed to trigger a cache reload","data":{"ExceptionMessage":"Recursive locks not allowed","ExceptionType":null,"StackTrace":null},"status":500,"xhrStatus":"complete"}
The open question is:
Is the proxy not being applied to the Umbraco backoffice with the above configuration, or is this issue caused by something else (e.g., Umbraco locking / WAF interference)?