Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle unsupported browser warnings #43363

Merged
31 commits merged into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4d13214
Handle browser warnings
buyaa-n Oct 13, 2020
c94abbf
Merge branch 'master' of https://github.com/dotnet/runtime into add_b…
buyaa-n Oct 16, 2020
148bd59
Apply feedback, revert updates handled with different PRs
buyaa-n Oct 16, 2020
36984e3
Merge branch 'master' of https://github.com/dotnet/runtime into add_b…
buyaa-n Oct 16, 2020
256f290
Add misssing diagnotic id
buyaa-n Oct 20, 2020
99fb042
Merge branch 'master' of https://github.com/dotnet/runtime into add_b…
buyaa-n Oct 20, 2020
351e839
Merge branch 'master' of https://github.com/dotnet/runtime into add_b…
buyaa-n Oct 21, 2020
6267bec
Address multitargeted warnings
buyaa-n Oct 21, 2020
422be5b
Apply feedback
buyaa-n Oct 23, 2020
a523788
Small type/comment updates
buyaa-n Oct 23, 2020
3892c1c
Apply more feedback
buyaa-n Oct 23, 2020
ca6e0fa
Use project settings instead adding Directory.Build.props
buyaa-n Oct 24, 2020
8007c09
Annotate APIs injecting unsupported type through DI
buyaa-n Oct 29, 2020
443aa1f
Fix window support related warnings found with generic type parameter
buyaa-n Nov 2, 2020
f86de1f
Fix another browser warning found with generic type parameter bug fix
buyaa-n Nov 2, 2020
cb052c3
All public APIs of ConsoleLoggerExtensions are unsupported, so markin…
buyaa-n Nov 9, 2020
c70674c
Try handle mono warnings
buyaa-n Nov 10, 2020
2c25aaa
Merge conflicts
buyaa-n Nov 10, 2020
38320a5
Revert mono related changes, it was mistake
buyaa-n Nov 11, 2020
636e5d9
Try handle browser warninga in mono
buyaa-n Nov 11, 2020
7fef65c
Apply feedback and fix new warnings caused from corelib changes
buyaa-n Nov 12, 2020
e5c1673
Review update
buyaa-n Nov 12, 2020
5c9254a
Apply feedback
buyaa-n Nov 12, 2020
f74e50f
Move platform specific section from HttpTelemetry
buyaa-n Nov 13, 2020
ed2b844
Revering unwanted changes
buyaa-n Nov 13, 2020
8d7d39d
Remove redundant attributes
buyaa-n Nov 13, 2020
9a043fe
Exclude cross platform build with browser target
buyaa-n Nov 17, 2020
f6d9618
small updates
buyaa-n Nov 17, 2020
3ba103c
Annotate entire type DiagnosticCounter unsupported
buyaa-n Nov 18, 2020
a804980
Apply feedback, improve suppression comments
buyaa-n Nov 20, 2020
22bb8a2
Remove Unsupported browser from TypeDescriptor.CreateInstance, TypeDe…
buyaa-n Nov 25, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions eng/versioning.targets
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
</AssemblyAttribute>
</ItemGroup>

<ItemGroup Condition="'$(TargetsBrowser)' == 'true' and '$(IsTestProject)' != 'true'">
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
<SupportedPlatform Include="browser"/>
</ItemGroup>

<ItemGroup>
<_unsupportedOSPlatforms Include="$(UnsupportedOSPlatforms)" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal static class SslClientAuthenticationOptionsExtensions
{
public static SslClientAuthenticationOptions ShallowClone(this SslClientAuthenticationOptions options)
{
#pragma warning disable CA1416 // Validate platform compatibility
var clone = new SslClientAuthenticationOptions()
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
{
AllowRenegotiation = options.AllowRenegotiation,
Expand All @@ -27,7 +28,7 @@ public static SslClientAuthenticationOptions ShallowClone(this SslClientAuthenti
RemoteCertificateValidationCallback = options.RemoteCertificateValidationCallback,
TargetHost = options.TargetHost
};

#pragma warning restore CA1416
#if DEBUG
// Try to detect if a property gets added that we're not copying correctly.
foreach (PropertyInfo pi in options.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,9 @@ private async ValueTask<HttpResponseMessage> SendAsyncCore(
// Wait for the send request to complete, getting back the response.
response = async ?
await base.SendAsync(request, cts.Token).ConfigureAwait(false) :
#pragma warning disable // Validate platform compatibility
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
base.Send(request, cts.Token);
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
#pragma warning restore
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
ThrowForNullResponse(response);

// Buffer the response content if we've been asked to.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public sealed partial class HttpListener : System.IDisposable
public HttpListener() { }
public System.Net.AuthenticationSchemes AuthenticationSchemes { get { throw null; } set { } }
public System.Net.AuthenticationSchemeSelector? AuthenticationSchemeSelectorDelegate { get { throw null; } set { } }
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
public System.Security.Authentication.ExtendedProtection.ServiceNameCollection DefaultServiceNames { get { throw null; } }
public System.Security.Authentication.ExtendedProtection.ExtendedProtectionPolicy ExtendedProtectionPolicy { get { throw null; } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] set { } }
[System.Diagnostics.CodeAnalysis.DisallowNullAttribute]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public HttpListener()

// default: no CBT checks on any platform (appcompat reasons); applies also to PolicyEnforcement
// config element
#pragma warning disable CA1416 // Validate platform compatibility
_extendedProtectionPolicy = new ExtendedProtectionPolicy(PolicyEnforcement.Never);
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
#pragma warning restore CA1416
}

public AuthenticationSchemeSelector? AuthenticationSchemeSelectorDelegate
Expand Down Expand Up @@ -99,6 +101,7 @@ public ExtendedProtectionPolicy ExtendedProtectionPolicy
}
}

[UnsupportedOSPlatform("browser")]
public ServiceNameCollection DefaultServiceNames => _defaultServiceNames.ServiceNames;

public HttpListenerPrefixCollection Prefixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ internal EntitySendFormat EntitySendFormat
CheckSentHeaders();
if (value == EntitySendFormat.Chunked && HttpListenerRequest.ProtocolVersion.Minor == 0)
{
#pragma warning disable CA1416 // Validate platform compatibility
throw new ProtocolViolationException(SR.net_nochunkuploadonhttp10);
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
#pragma warning restore CA1416
}
_boundaryType = (BoundaryType)value;
if (value != EntitySendFormat.ContentLength)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ private State ReadTrailer(byte[] buffer, ref int offset, int size)

private static void ThrowProtocolViolation(string message)
{
#pragma warning disable CA1416 // Validate platform compatibility
WebException we = new WebException(message, null, WebExceptionStatus.ServerProtocolViolation, null);
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
#pragma warning restore CA1416
throw we;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Net.Security;
using System.Net.Sockets;
using System.Runtime.Versioning;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Text;
Expand Down Expand Up @@ -79,18 +81,22 @@ public HttpConnection(Socket sock, HttpEndPointListener epl, bool secure, X509Ce
_cert = cert;
if (secure == false)
{
#pragma warning disable CA1416 // Validate platform compatibility
_stream = new NetworkStream(sock, false);
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
#pragma warning restore CA1416
}
else
{
#pragma warning disable CA5359
Debug.Assert(!OperatingSystem.IsBrowser());
_sslStream = epl.Listener.CreateSslStream(new NetworkStream(sock, false), false, (t, c, ch, e) =>
{
if (c == null)
{
return true;
}

Debug.Assert(!OperatingSystem.IsBrowser());
var c2 = c as X509Certificate2;
if (c2 == null)
{
Expand All @@ -108,7 +114,9 @@ public HttpConnection(Socket sock, HttpEndPointListener epl, bool secure, X509Ce

_timer = new Timer(OnTimeout, null, Timeout.Infinite, Timeout.Infinite);
if (_sslStream != null) {
#pragma warning disable CA1416 // Validate platform compatibility
_sslStream.AuthenticateAsServer (_cert, true, (SslProtocols)ServicePointManager.SecurityProtocol, false);
#pragma warning restore CA1416
}
Init();
}
Expand Down Expand Up @@ -156,6 +164,7 @@ public int Reuses
get { return _reuses; }
}

[UnsupportedOSPlatform("browser")]
public IPEndPoint? LocalEndPoint
{
get
Expand All @@ -168,6 +177,7 @@ public IPEndPoint? LocalEndPoint
}
}

[UnsupportedOSPlatform("browser")]
public IPEndPoint? RemoteEndPoint
{
get { return (IPEndPoint?)_socket!.RemoteEndPoint; }
Expand Down Expand Up @@ -458,7 +468,9 @@ public void SendError(string? msg, int status)
str = string.Format("<h1>{0}</h1>", description);

byte[] error = Encoding.Default.GetBytes(str);
#pragma warning disable CA1416 // Validate platform compatibility
response.Close(error, false);
#pragma warning restore CA1416
}
catch
{
Expand Down Expand Up @@ -492,7 +504,9 @@ private void CloseSocket()

try
{
#pragma warning disable CA1416 // Validate platform compatibility
_socket.Close();
#pragma warning restore CA1416
}
catch { }
finally
Expand Down Expand Up @@ -541,6 +555,7 @@ internal void Close(bool force)

Socket s = _socket;
_socket = null;
#pragma warning disable CA1416 // Validate platform compatibility
try
{
if (s != null)
Expand All @@ -554,6 +569,7 @@ internal void Close(bool force)
if (s != null)
s.Close();
}
#pragma warning restore CA1416
Unbind();
RemoveConnection();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@

using System.Collections.Generic;
using System.Net.Sockets;
using System.Runtime.Versioning;
using System.Security.Cryptography.X509Certificates;
using System.Threading;

#pragma warning disable CA1416 // Validate platform compatibility
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
namespace System.Net
{
internal sealed class HttpEndPointListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Sockets;

namespace System.Net
Expand Down Expand Up @@ -119,6 +120,7 @@ private static HttpEndPointListener GetEPListener(string host, int port, HttpLis
const int NotSupportedErrorCode = 50;
try
{
Debug.Assert(!OperatingSystem.IsBrowser());
addr = Dns.GetHostAddresses(host)[0];
}
catch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
using System.Collections.Generic;
using System.IO;
using System.Net.Security;
using System.Runtime.Versioning;
using System.Security.Cryptography.X509Certificates;

namespace System.Net
{
public partial class HttpListener
{
[UnsupportedOSPlatform("browser")]
internal SslStream CreateSslStream(Stream innerStream, bool ownsStream, RemoteCertificateValidationCallback callback)
{
return new SslStream(innerStream, ownsStream, callback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ internal void FinishInitialization()
else
path = _rawUrl;

Debug.Assert(!OperatingSystem.IsBrowser());
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
if ((host == null || host.Length == 0))
host = UserHostAddress;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ public int StatusCode
{
CheckDisposed();

#pragma warning disable CA1416 // Validate platform compatibility
if (value < 100 || value > 999)
throw new ProtocolViolationException(SR.net_invalidstatus);
#pragma warning restore CA1416

_statusCode = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Runtime.Versioning;

namespace System.Net
{
Expand Down Expand Up @@ -86,7 +87,9 @@ private void DisposeCore()
// Ignore error due to connection reset by peer
}
}
#pragma warning disable CA1416 // Validate platform compatibility
_response.Close();
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
#pragma warning restore CA1416
}

internal async Task WriteWebSocketHandshakeHeadersAsync()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Threading.Tasks;

namespace System.Net.WebSockets
Expand Down Expand Up @@ -59,6 +60,7 @@ internal static async Task<HttpListenerWebSocketContext> AcceptWebSocketAsyncCor

WebSocket webSocket = WebSocket.CreateFromStream(context.Connection.ConnectedStream, isServer:true, subProtocol, keepAliveInterval);

Debug.Assert(!OperatingSystem.IsBrowser());
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
HttpListenerWebSocketContext webSocketContext = new HttpListenerWebSocketContext(
request.Url!,
request.Headers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Security.Authentication.ExtendedProtection;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.Versioning;

namespace System.Net
{
Expand All @@ -14,6 +15,7 @@ internal class ServiceNameStore
private readonly List<string> _serviceNames;
private ServiceNameCollection? _serviceNameCollection;

[UnsupportedOSPlatform("browser")]
public ServiceNameCollection ServiceNames
{
get
Expand Down Expand Up @@ -291,6 +293,7 @@ public string[] BuildServiceNames(string uriPrefix)
// or the query fails for some reason, don't add an SPN.
try
{
Debug.Assert(!OperatingSystem.IsBrowser());
string machineName = Dns.GetHostEntry(string.Empty).HostName;
return new string[] { "HTTP/" + machineName };
}
Expand All @@ -309,6 +312,7 @@ public string[] BuildServiceNames(string uriPrefix)
// or the query fails for some reason, add only the dotless name.
try
{
Debug.Assert(!OperatingSystem.IsBrowser());
string fqdn = Dns.GetHostEntry(hostname).HostName;
return new string[] { "HTTP/" + hostname, "HTTP/" + fqdn };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>$(DefineConstants);INTERNAL_ASYMMETRIC_IMPLEMENTATIONS</DefineConstants>
<NoWarn>$(NoWarn);CA5350;CA5351;CA5379;CA5384</NoWarn>
<NoWarn>$(NoWarn);CA5350;CA5351;CA5379;CA5384;CA1416</NoWarn>
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
<TargetFrameworks>$(NetCoreAppCurrent)-Windows_NT;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Android;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down