-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Proposed code fixer for obsoleted CAS APIs #39235
Comments
To clarify the above "fixer shouldn't do anything" examples a bit... // fixer should NOT recommend removal
// dev needs to take a closer look at what they were trying to accomplish
[SecurityPermission(SecurityAction.Deny, ...)]
public void SomeMethod() { /* ... */ }
// note: this is already obsolete *as error*
// fixer should NOT recommend removal
// dev needs to take a closer look at what they were trying to accomplish
[PrincipalPermission(SecurityAction.Demand, ...)]
public void SomeMethod() { /* ... */ } In the cases above, the .NET Core runtime does not honor the attributes. The runtime itself behaves as if the attributes were not present. But the only logical reason for a dev to have written these attributes in the first place is that they expected the runtime to perform a check on method entry. The dev should be made aware of this disconnect: "You put these because presumably you wanted a side effect, but the current runtime will no-op when it sees them. What did you actually intend to do?" public void SomeMethod()
{
// fixer should NOT recommend removal
// dev needs to take a closer look at what they were trying to accomplish
// n.b. this call will always result in PNSE at runtime
new SecurityPermission(...).Deny();
} In the case above, the call to public void SomeMethod()
{
// fixer should NOT recommend removal; PrincipalPermission does not subclass CodeAccessPermission
// dev needs to take a closer look at what they were trying to accomplish
new PrincipalPermission(...).Demand().
} In the case above, the call to |
@GrabYourPitchforks / @terrajobst - I've removed this from scope for .NET 6. Do you think we need to present this in API Review, or could we could ahead and mark it as up-for-grabs? |
Per dotnet/designs#139, we want to obsolete some of the CAS-related APIs in .NET 5.0. The obsoleted APIs are primarily classes that derive from
CodeAccessSecurityAttribute
andCodeAccessPermission
.The fixer should help apps migrate away from these now-obsolete types.
For
CodeAccessSecurityAttribute
-derived which are obsolete (exceptPrincipalPermissionAttribute
), the fixer should look at theSecurityAction
parameter passed into the attribute ctor. If the value is one ofSecurityAction.Assert
,Demand
,InheritanceDemand
,LinkDemand
,RequestMinimum
, orRequestOptional
, the fixer should recommend that the attribute declaration be removed entirely. If theSecurityAction
enum value is anything else, the fixer should make no recommendation.For
CodeAccessPermission
-derived types which are obsolete (n.b.PrincipalPermission
does not subclass this type and should be excluded), the fixer should suggest calls toAssert
andDemand
be removed. If any other API is called, the fixer should make no recommendation.Examples:
For
PrincipalPermissionAttribute
andPrincipalPermission
specifically, we should steer the developer toward using ASP.NET's built-in AuthN / AuthZ features.The text was updated successfully, but these errors were encountered: