Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Log when an insecure Https -> Http redirect is blocked #27077

Merged
merged 7 commits into from Feb 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -888,6 +888,16 @@ private async void StartRequest(WinHttpRequestState state)

HttpResponseMessage responseMessage = WinHttpResponseParser.CreateResponseMessage(state, _doManualDecompressionCheck);
state.Tcs.TrySetResult(responseMessage);

// HttpStatusCode cast is needed for 308 Moved Permenantly, which we support but is not included in NetStandard status codes.
if (WinHttpTraceHelper.IsTraceEnabled() &&
((responseMessage.StatusCode >= HttpStatusCode.MultipleChoices && responseMessage.StatusCode <= HttpStatusCode.SeeOther) ||
(responseMessage.StatusCode >= HttpStatusCode.RedirectKeepVerb && responseMessage.StatusCode <= (HttpStatusCode)308)) &&
state.RequestMessage.RequestUri.Scheme == Uri.UriSchemeHttps && responseMessage.Headers.Location?.Scheme == Uri.UriSchemeHttp)
{
WinHttpTraceHelper.Trace("WinHttpHandler.SendAsync: Insecure https to http redirect from {0} to {1} blocked.",
state.RequestMessage.RequestUri.ToString(), responseMessage.Headers.Location.ToString());
}
}
catch (Exception ex)
{
Expand Down
Expand Up @@ -370,6 +370,11 @@ internal void SetPossibleRedirectForLocationHeader(string location)
{
SetCookieOption(newUri);
}

if (newUri.Scheme == Uri.UriSchemeHttp && _requestMessage.RequestUri.Scheme == Uri.UriSchemeHttps)
{
EventSourceTrace("Insecure https to http redirect: {0}", (_requestMessage.RequestUri, newUri));
}
}

// Set up the new credentials, either for the new Uri if we were able to get it,
Expand Down
Expand Up @@ -132,6 +132,10 @@ await AuthenticationHelper.TrySetDigestAuthToken(request, currentCredential, dig
(HttpUtilities.IsSupportedSecureScheme(request.RequestUri.Scheme) && HttpUtilities.IsSupportedSecureScheme(location.Scheme));
if (!allowed)
{
if (NetEventSource.IsEnabled)
{
NetEventSource.Info(this, $"Insecure https to http redirect from {request.RequestUri} to {location} blocked.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike the other two, this one is fine, as it's guarded by the NetEventSource.IsEnabled check. The costs will only be incurred when tracing is enabled.

}
break;
}

Expand Down