Remove most CAS and Security transparency related attributes#15987
Remove most CAS and Security transparency related attributes#15987danmoseley wants to merge 12 commits into
Conversation
…ion, PermissionSet, ReflectionPermission, SecurityPermission, HostProtection
|
Rollback src/System.Diagnostics.Tracing/src/... as usual... |
|
Oh, that's frozen in corefx also? Sure... |
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. |
|
cc: @karelz |
|
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 |
Yes. The current source code already uses that convention in places. |
|
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
@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] |
There was a problem hiding this comment.
If this gets used in OOBs, it can affect correctness or performance.
There was a problem hiding this comment.
We want to leave all attributes in all Common code? Or just those used in OOBs (which was my goal)?
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
I believe SafeCritical is important in contracts as well
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
There are a couple differences related to inheritance documented at https://msdn.microsoft.com/en-us/library/dd233102(v=vs.110).aspx
There was a problem hiding this comment.
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")] |
There was a problem hiding this comment.
Please don't remove FXCop suppressions -- those affect our ability to sign off on the code.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
The tooling we use for security signoffs doesn't know that we don't use CAS. Suppressions help us weed out the noise.
There was a problem hiding this comment.
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)] |
There was a problem hiding this comment.
ComVisible is used for interop, not security. Are these intended to be in this change?
There was a problem hiding this comment.
Yes, per Jan's comments in https://github.com/dotnet/corefx/issues/12592
|
@ericstj , @joperezr pointed out there are more than these 3 oobs. In my naive grep, many apply to desktop: Will we actually support these on desktop? If not, which? @karelz |
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. |
|
@weshaggard for above question about OOB.s |
|
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. |
|
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. |
|
@danmosemsft that sounds pretty good. You can confirm by running secannotate over whatever does build for net46/netfx. |
|
@ericstj what is the issue # for the work you are doing that this depends on (to clear up the pkgprojs wedon't need) |
|
@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 |
|
OK, so I should 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 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. |
|
I just won't have time to do this anytime soon unfortunately. Maybe I or someone else can reheat this in future. |

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