Skip to content

Commit 728d9e7

Browse files
authored
Update ssl check and bypass localhost (#27038)
1 parent 834c437 commit 728d9e7

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/OperationalInsights/OperationalInsights/Query/InvokeOperationalInsightsQuery.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
2323
using System.Threading;
2424
using Microsoft.WindowsAzure.Commands.Utilities.Common;
25+
using System.Net.Security;
2526

2627
namespace Microsoft.Azure.Commands.OperationalInsights.Query
2728
{
@@ -92,9 +93,19 @@ internal OperationalInsightsDataClient OperationalInsightsDataClient
9293

9394
this._operationalInsightsDataClient.BaseUri = targetUri;
9495

95-
if (targetUri.AbsoluteUri.Contains("localhost"))
96+
if (targetUri.Host.Equals("localhost", StringComparison.OrdinalIgnoreCase))
9697
{
97-
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
98+
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
99+
{
100+
if (sslPolicyErrors == SslPolicyErrors.None)
101+
return true;
102+
103+
// Bypass certificate validation for localhost
104+
if (sender is HttpWebRequest request)
105+
return request.RequestUri.IsLoopback;
106+
107+
return false;
108+
};
98109
}
99110
}
100111

0 commit comments

Comments
 (0)