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

Remove most CAS and Security transparency related attributes#15987

Closed
danmoseley wants to merge 12 commits into
dotnet:masterfrom
danmoseley:attrib
Closed

Remove most CAS and Security transparency related attributes#15987
danmoseley wants to merge 12 commits into
dotnet:masterfrom
danmoseley:attrib

Conversation

@danmoseley
Copy link
Copy Markdown
Member

Fixes https://github.com/dotnet/corefx/issues/12592

Remove CAS and Security Transparency attributes, and related message suppressions and pragma disable 618's with the exception of (1) no changes to Compression and Immutable and (2) no changes to SecurityCritical in refs (only removed some SecurityPermission's)

Are there any other OOBs that I should exclude? System.Net.Http was mentioned in #14383, should I reverse the couple changes there?

@jkotas @stephentoub @JeremyKuhne @davidsh

@jkotas
Copy link
Copy Markdown
Member

jkotas commented Feb 9, 2017

Rollback src/System.Diagnostics.Tracing/src/... as usual...

@danmoseley
Copy link
Copy Markdown
Member Author

Oh, that's frozen in corefx also? Sure...

@davidsh
Copy link
Copy Markdown
Contributor

davidsh commented Feb 9, 2017

Are there any other OOBs that I should exclude? System.Net.Http was mentioned in #14383, should I reverse the couple changes there?

You need to exclude System.Net.Http and all sources that it brings in from src/Common like tracing (DiagnosticSource, EventSource) and any other common files. Otherwise, we will break CAS on the 'net46' build of System.Net.Http.

And to verify your changes, you should run the 'secannotate' tool against the 'net46' binary of System.Net.Http. It needs to continue to show 0 errors. @morganbr can advise.

@davidsh
Copy link
Copy Markdown
Contributor

davidsh commented Feb 9, 2017

cc: @karelz

@danmoseley
Copy link
Copy Markdown
Member Author

I reverted all changes to files which are compiled into S.N.Http. That includes NetEventSource.Common.cs.

Is it acceptable to put #if NET46 around those? eg

#if NET46    
    [SecuritySafeCritical]
#endif

@davidsh
Copy link
Copy Markdown
Contributor

davidsh commented Feb 9, 2017

Is it acceptable to put #if NET46 around those? eg

Yes. The current source code already uses that convention in places.

@davidsh
Copy link
Copy Markdown
Contributor

davidsh commented Feb 9, 2017

Although for files like HttpClientHandler.Net46.cs, you shouldn't need any 'if NET46' because the whole file is only compiled if it is building NET46.

return _proxy;
}

#if NET46
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I think it is unnecessary to put any if-def wrappers in this file. This file is already only compiled for the NET46 build.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I decided to do it anyway so that if and when someone makes a similar pass again (as we paste in more reference source, more are brought in) it's quite clear they don't need to delete this one.

@danmoseley
Copy link
Copy Markdown
Member Author

danmoseley commented Feb 9, 2017

@morganbr can you advise about the security check tool mentioned above.

[edit - I found it -- I"ll run it]

internal static partial class WebSocket
{
[DllImport(Libraries.WebSocket)]
[SuppressUnmanagedCodeSecurity]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If this gets used in OOBs, it can affect correctness or performance.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We want to leave all attributes in all Common code? Or just those used in OOBs (which was my goal)?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't know which ones get used in OOBs. We only need attributes in files that get used in OOBs (and perhaps ones that would get used in the future).

public sealed partial class ProjectData
{
internal ProjectData() { }
[System.Security.SecuritySafeCriticalAttribute]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I believe SafeCritical is important in contracts as well

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is no difference between SafeCritical and transparent (ie no annotation) in the contract.

In other words, changing from SafeCritical to transparent or vice versa, is not a contract breaking change.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There are a couple differences related to inheritance documented at https://msdn.microsoft.com/en-us/library/dd233102(v=vs.110).aspx

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, but those only matter at runtime. They do not matter at compile time where the contracts are consumed.

using System.Reflection;
using System.Collections;

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2112:SecuredTypesShouldNotExposeFields", Scope = "type", Target = "System.ComponentModel.AttributeCollection")]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please don't remove FXCop suppressions -- those affect our ability to sign off on the code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I removed this because it relates to LinkDemands, which is CAS. Does it have another purpose?

A public or protected type contains public fields and is secured by a Link Demands.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The tooling we use for security signoffs doesn't know that we don't use CAS. Suppressions help us weed out the noise.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

But it's triggered by the presence of a link demand, right? Which we don't have. It doesn't just trigger on all public or protected type contains public fields

namespace System.Configuration
{
// obsolete
[ComVisible(false)]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ComVisible is used for interop, not security. Are these intended to be in this change?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@danmoseley
Copy link
Copy Markdown
Member Author

@ericstj , @joperezr pointed out there are more than these 3 oobs. In my naive grep, many apply to desktop:

C:\git\corefx\src>for /f %i in ('dir /s/b *pkgproj') do @(echo %i & @type %i > out & @\t\grep -i "supportedframework.*net4" out)
C:\git\corefx\src\Microsoft.CSharp\pkg\Microsoft.CSharp.pkgproj
      <SupportedFramework>net463;netcoreapp2.0;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\Microsoft.VisualBasic\pkg\Microsoft.VisualBasic.pkgproj
      <SupportedFramework>net45;netcore45;netcoreapp1.0;wpa81;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\Microsoft.Win32.Registry\pkg\Microsoft.Win32.Registry.pkgproj
      <SupportedFramework>net463;netcoreapp2.0</SupportedFramework>
C:\git\corefx\src\Microsoft.Win32.Registry.AccessControl\pkg\Microsoft.Win32.Registry.AccessControl.pkgproj
      <SupportedFramework>net46;netcoreapp1.0</SupportedFramework>
C:\git\corefx\src\Native\pkg\runtime.native.System.Data.SqlClient.sni\runtime.native.System.Data.SqlClient.sni.pkgproj
C:\git\corefx\src\Native\pkg\runtime.native.System.Data.SqlClient.sni\win\runtime.native.System.Data.SqlClient.sni.pkgproj
C:\git\corefx\src\System.Buffers\pkg\System.Buffers.pkgproj
      <SupportedFramework>net45;netcore45;netcoreapp1.0;wpa81;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.CodeDom\pkg\System.CodeDom.pkgproj
      <SupportedFramework>net461;netcoreapp2.0;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Collections.Immutable\pkg\System.Collections.Immutable.pkgproj
      <SupportedFramework>net45;netcore45;netcoreapp1.0;wp8;wpa81;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.ComponentModel.Annotations\pkg\System.ComponentModel.Annotations.pkgproj
      <SupportedFramework>net463;netcoreapp2.0;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Composition\pkg\System.Composition.pkgproj
C:\git\corefx\src\System.Composition.AttributedModel\pkg\System.Composition.AttributedModel.pkgproj
      <SupportedFramework>net45;netcore45;netcoreapp1.0;wp8;wpa81;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Composition.Convention\pkg\System.Composition.Convention.pkgproj
      <SupportedFramework>net45;netcore45;netcoreapp1.0;wp8;wpa81;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Composition.Hosting\pkg\System.Composition.Hosting.pkgproj
      <SupportedFramework>net45;netcore45;netcoreapp1.0;wp8;wpa81;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Composition.Runtime\pkg\System.Composition.Runtime.pkgproj
      <SupportedFramework>net45;netcore45;netcoreapp1.0;wp8;wpa81;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Composition.TypedParts\pkg\System.Composition.TypedParts.pkgproj
      <SupportedFramework>net45;netcore45;netcoreapp1.0;wp8;wpa81;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Configuration.ConfigurationManager\pkg\System.Configuration.ConfigurationManager.pkgproj
      <SupportedFramework>netcoreapp2.0;net461;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Data.SqlClient\pkg\System.Data.SqlClient.pkgproj
      <SupportedFramework>net463;netcoreapp2.0;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Diagnostics.DiagnosticSource\pkg\System.Diagnostics.DiagnosticSource.pkgproj
      <SupportedFramework>net46;net45;netcore45;netcoreapp1.0;wpa81;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.DirectoryServices\pkg\System.DirectoryServices.pkgproj
C:\git\corefx\src\System.DirectoryServices.AccountManagement\pkg\System.DirectoryServices.AccountManagement.pkgproj
C:\git\corefx\src\System.DirectoryServices.Protocols\pkg\System.DirectoryServices.Protocols.pkgproj
C:\git\corefx\src\System.IO.Compression\pkg\System.IO.Compression.pkgproj
      <SupportedFramework>netcoreapp2.0;net463;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.IO.FileSystem.AccessControl\pkg\System.IO.FileSystem.AccessControl.pkgproj
      <SupportedFramework>net46;netcoreapp1.0</SupportedFramework>
C:\git\corefx\src\System.IO.Packaging\pkg\System.IO.Packaging.pkgproj
      <SupportedFramework>net46;netcore50;netcoreapp1.0;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.IO.Pipes.AccessControl\pkg\System.IO.Pipes.AccessControl.pkgproj
      <SupportedFramework>net46;netcoreapp1.0</SupportedFramework>
C:\git\corefx\src\System.IO.Ports\pkg\System.IO.Ports.pkgproj
      <SupportedFramework>net463;netcoreapp2.0</SupportedFramework>
C:\git\corefx\src\System.Json\pkg\System.Json.pkgproj
      <SupportedFramework>net45;netcore45;netcoreapp1.0;wp8;wpa81;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Memory\pkg\System.Memory.pkgproj
      <SupportedFramework>net45;netcore45;wp8;wpa81;netcoreapp1.0;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Net.Http\pkg\System.Net.Http.pkgproj
      <SupportedFramework>net46</SupportedFramework>
C:\git\corefx\src\System.Net.Http.Rtc\pkg\System.Net.Http.Rtc.pkgproj
C:\git\corefx\src\System.Net.Http.WinHttpHandler\pkg\System.Net.Http.WinHttpHandler.pkgproj
      <SupportedFramework>net46;netcoreapp1.0</SupportedFramework>
C:\git\corefx\src\System.Numerics.Vectors.WindowsRuntime\pkg\System.Numerics.Vectors.WindowsRuntime.pkgproj
C:\git\corefx\src\System.Reflection.Context\pkg\System.Reflection.Context.pkgproj
      <SupportedFramework>net45;netcore45;wpa81;netcoreapp1.0;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Reflection.DispatchProxy\pkg\System.Reflection.DispatchProxy.pkgproj
      <SupportedFramework>net46;netcore50;netcoreapp1.0;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Reflection.Metadata\pkg\System.Reflection.Metadata.pkgproj
      <SupportedFramework>net45;netcore45;netcoreapp1.0;wpa81;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Runtime.CompilerServices.Unsafe\pkg\System.Runtime.CompilerServices.Unsafe.pkgproj
      <SupportedFramework>net45;netcore45;wp8;wpa81;netcoreapp1.0;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Runtime.InteropServices.RuntimeInformation\pkg\System.Runtime.InteropServices.RuntimeInformation.pkgproj
      <SupportedFramework>net45;netcore45;wpa81;netcoreapp1.0;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Runtime.WindowsRuntime\pkg\System.Runtime.WindowsRuntime.pkgproj
C:\git\corefx\src\System.Runtime.WindowsRuntime.UI.Xaml\pkg\System.Runtime.WindowsRuntime.UI.Xaml.pkgproj
C:\git\corefx\src\System.Security.AccessControl\pkg\System.Security.AccessControl.pkgproj
      <SupportedFramework>net463;netcoreapp2.0</SupportedFramework>
C:\git\corefx\src\System.Security.Cryptography.OpenSsl\pkg\System.Security.Cryptography.OpenSsl.pkgproj
      <SupportedFramework>net461;netcoreapp2.0;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Security.Cryptography.Pkcs\pkg\System.Security.Cryptography.Pkcs.pkgproj
      <SupportedFramework>net46;netcore50;netcoreapp1.0</SupportedFramework>
C:\git\corefx\src\System.Security.Cryptography.ProtectedData\pkg\System.Security.Cryptography.ProtectedData.pkgproj
      <SupportedFramework>net46;netcore50;netcoreapp1.0;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Security.Cryptography.Xml\pkg\System.Security.Cryptography.Xml.pkgproj
      <SupportedFramework>net462;netcoreapp2.0;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Security.Permissions\pkg\System.Security.Permissions.pkgproj
      <SupportedFramework>netcoreapp2.0;net461;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Security.Principal.Windows\pkg\System.Security.Principal.Windows.pkgproj
      <SupportedFramework>net463;netcoreapp2.0</SupportedFramework>
C:\git\corefx\src\System.ServiceProcess.ServiceController\pkg\System.ServiceProcess.ServiceController.pkgproj
      <SupportedFramework>net463;netcoreapp2.0</SupportedFramework>
C:\git\corefx\src\System.Text.Encoding.CodePages\pkg\System.Text.Encoding.CodePages.pkgproj
      <SupportedFramework>net461;netcoreapp2.0;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Text.Encodings.Web\pkg\System.Text.Encodings.Web.pkgproj
      <SupportedFramework>net45;netcore45;wp8;wpa81;netcoreapp1.0;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Threading.AccessControl\pkg\System.Threading.AccessControl.pkgproj
      <SupportedFramework>net46;netcoreapp1.0</SupportedFramework>
C:\git\corefx\src\System.Threading.Tasks.Dataflow\pkg\System.Threading.Tasks.Dataflow.pkgproj
      <SupportedFramework>net45;netcore45;wp8;wpa81;netcoreapp1.0;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Threading.Tasks.Extensions\pkg\System.Threading.Tasks.Extensions.pkgproj
      <SupportedFramework>net45;netcore45;netcoreapp1.0;wpa81;wp8;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.Transactions\pkg\System.Transactions.pkgproj
      <SupportedFramework>net461;netcoreapp2.0;$(AllXamarinFrameworks)</SupportedFramework>
C:\git\corefx\src\System.ValueTuple\pkg\System.ValueTuple.pkgproj
      <SupportedFramework>net45;netcore45;netcoreapp1.0;wp8;wpa81;$(AllXamarinFrameworks)</SupportedFramework>

Will we actually support these on desktop? If not, which? @karelz

@jkotas
Copy link
Copy Markdown
Member

jkotas commented Feb 9, 2017

In my naive grep, many apply to desktop:

These are OOB packages. Most of them do not actually have any actual corefx code in them for desktop - they just contain forwarders for desktop.

@danmoseley
Copy link
Copy Markdown
Member Author

@weshaggard for above question about OOB.s

@davidsh
Copy link
Copy Markdown
Contributor

davidsh commented Feb 9, 2017

@danmosemsft

This is what a successful (no errors) secannotate tool shows when there are no errors in CAS attributes for System.Net.Http for the 'net46' binary.

image

@danmoseley
Copy link
Copy Markdown
Member Author

OK, well neither the net46 nor netfx flavors (not sure if both are relevant) of S.N.Http have any errors when I do that on the latest commit.

@danmoseley
Copy link
Copy Markdown
Member Author

danmoseley commented Feb 9, 2017

OK so it seems what I need to do is examine anything that builds for net46/netfx to determine what is not a pure runtime facade (ie actually has types in) and #if NETFX the attributes in those.

Apparently @ericstj is cleaning out some of these desktop facades that CoreFX builds so I'll sit on this PR until that is done and then rebase and do the analysis above.

@danmoseley danmoseley added the * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) label Feb 9, 2017
@morganbr
Copy link
Copy Markdown

morganbr commented Feb 9, 2017

@danmosemsft that sounds pretty good. You can confirm by running secannotate over whatever does build for net46/netfx.

@danmoseley
Copy link
Copy Markdown
Member Author

@ericstj what is the issue # for the work you are doing that this depends on (to clear up the pkgprojs wedon't need)

@ericstj
Copy link
Copy Markdown
Member

ericstj commented Feb 16, 2017

@danmosemsft Anything we need for packaging is currently committed and builds with the AllConfigurations build. Also pkgprojs have been cleaned up for some time. All remaining ones we expect to ship. The PR that enables build of these pkgrpojs is currently pending: #16191

@danmoseley
Copy link
Copy Markdown
Member Author

OK, so I should avoid touching any security annotations on any contract with a pkgproj - right?

@jkotas
Copy link
Copy Markdown
Member

jkotas commented Feb 16, 2017

avoid touching any security annotations on any contract with a pkgproj - right?

You will leave most of the cruft in with this filter. For example, the security annotations can be deleted under \corefx\src\System.DirectoryServices.* - because of the implementation is ,NET Core specific - even though it has pkgproj files.

I believe https://github.com/dotnet/corefx/issues/12592#issuecomment-253971384 is still accurate way how to identify where it is fine to clean it up.

@danmoseley
Copy link
Copy Markdown
Member Author

I just won't have time to do this anytime soon unfortunately. Maybe I or someone else can reheat this in future.

@danmoseley danmoseley closed this Mar 2, 2017
@karelz karelz modified the milestone: 2.0.0 Mar 7, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Meta * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants