You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
.NET Core samples should not include CAS elements #837
Pri2Indicates issues/PRs that are medium priorityarea-System.SecurityIssues related to security practices for .NET developers.doc-bugProblem with the content; needs to be fixeddotnet-api/prod
In .NET Core, CAS types (like FileIOPermission, etc) and Security Transparency types are stubbed only. CAS is not supported. Therefore the samples in .NET Core topics should not include use of them.
Here [SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlAppDomain)] should be removed as it does nothing and implies that CAS is relevant.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
ID: 48667829-dc8d-680d-6fde-71a46dee4ce7
Version Independent ID: 15184777-1251-be89-27a7-7ca859082294
The only instances I've found where the CAS types are used for Core snippets are in API ref. There, the same snippet is shown regardless of whether Core or Framework is selected. To remove CAS from the snippet removes it from the Framework 4.x version too. Some options that come to mind:
Duplicate each snippet, remove CAS types from one copy, and include both copies in the doc with an appropriate heading for each.
Remove CAS types from each snippet, i.e., let the CAS types be missing even when Framework 4.x is selected.
Add a code comment at the top of each snippet noting that CAS doesn't apply to Core.
Given that > 1,000 snippet files are affected, all of these options will involve a significant time investment, # 3 seems least problematic, and # 1 seems questionable whether the benefit would outweigh the cost.
We haven't supported CAS in .NET Framework for years either. So I think generally (2) would make most sense.
I see the size of the task. If I search samples\snippets for ^\s*\[\w+Permission[^\]*\] I see 819 hits in .cs files. That ignores .vb, and attributes that cross lines. And any imperative use of these things. And of course any use of them in the docs for themselves needs to be preserved.
The good news is that it doesn't have to be perfect or complete. My suggestion is to look for something like the regex above (possbily improved to straddle lines) and just search and replace it away. Then do the same (using angle brackets) for VB. Then bulk revert anything the seems inappropriate. Then compile and either fix or just revert anything that breaks. I'd imagine you could spend a few hours and make a major dent, if you reverted anything that broke.
It does seem like a bunch of work, but after all these years, we should not be encouraging people to continue using these broken things. Thoughts?
Discussed this issue offline with @GrabYourPitchforks and @danmosemsft. Levi will identify specific categories of changes required, and for each category I'll make a PR that addresses all affected snippets.
Pri2Indicates issues/PRs that are medium priorityarea-System.SecurityIssues related to security practices for .NET developers.doc-bugProblem with the content; needs to be fixeddotnet-api/prod
Activity
mairaw commentedon Aug 16, 2018
Thanks @danmosemsft. I've added this issue to our security review project. We're hoping to get started on this soon.
danmoseley commentedon May 10, 2019
Here's another example, which reminded me.
https://docs.microsoft.com/en-us/dotnet/api/system.console.bufferheight?view=netcore-3.0
A bit confusing if you heard that CAS is dead.
rpetrusha commentedon May 10, 2019
This issue has languished, @danmosemsft, but I'll start addressing it in the next sprint.
danmoseley commentedon May 10, 2019
Thanks, @rpetrusha
8 remaining items
tdykstra commentedon Jun 11, 2020
@danmosemsft How can I get a list of the CAS types and Security Transparency types?
danmoseley commentedon Jun 11, 2020
https://github.com/dotnet/runtime/blob/master/src/libraries/System.Security.Permissions/ref/System.Security.Permissions.cs seems like a pretty good list
@GrabYourPitchforks does that map pretty well to what should not be in samples anymore?
GrabYourPitchforks commentedon Jun 12, 2020
That list, plus pretty much everything else in the System.Security.Permissions namespace, regardless of which reference assembly defines it.
Conveniently, Dan just provided a nice list of every API I want to slap
[Obsolete]on. ;)tdykstra commentedon Jun 12, 2020
The only instances I've found where the CAS types are used for Core snippets are in API ref. There, the same snippet is shown regardless of whether Core or Framework is selected. To remove CAS from the snippet removes it from the Framework 4.x version too. Some options that come to mind:
Given that > 1,000 snippet files are affected, all of these options will involve a significant time investment, # 3 seems least problematic, and # 1 seems questionable whether the benefit would outweigh the cost.
danmoseley commentedon Jun 13, 2020
We haven't supported CAS in .NET Framework for years either. So I think generally (2) would make most sense.
I see the size of the task. If I search samples\snippets for
^\s*\[\w+Permission[^\]*\]I see 819 hits in.csfiles. That ignores.vb, and attributes that cross lines. And any imperative use of these things. And of course any use of them in the docs for themselves needs to be preserved.The good news is that it doesn't have to be perfect or complete. My suggestion is to look for something like the regex above (possbily improved to straddle lines) and just search and replace it away. Then do the same (using angle brackets) for VB. Then bulk revert anything the seems inappropriate. Then compile and either fix or just revert anything that breaks. I'd imagine you could spend a few hours and make a major dent, if you reverted anything that broke.
It does seem like a bunch of work, but after all these years, we should not be encouraging people to continue using these broken things. Thoughts?
tdykstra commentedon Jun 13, 2020
That sounds like a good plan to me, I'll get started on it next week.
tdykstra commentedon Jul 21, 2020
Discussed this issue offline with @GrabYourPitchforks and @danmosemsft. Levi will identify specific categories of changes required, and for each category I'll make a PR that addresses all affected snippets.