How can I calm down FxCop when the getter / setter resource needs LinkDemand?

I have a Foo property on the Bar class:

public int Foo
{
   get
   {
      return GetFoo();
   }
   set
   {
      SetFoo(value);
   }
}

Both GetFooand SetFooare decorated:

[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]

As a result, FxCop correctly complains that the Foo property (or rather its implicit getter and setter methods) does not have the same LinkDemand:

CA2122: Microsoft.Security: 'Bar.Foo.get ()' calls 'Bar.GetFoo ()', which has LinkDemand. By selecting this call, "Bar.GetFoo ()" is indirectly exposed to user code. Check out the following call stack, which might open a way around security:

However, when I tried to apply the same attribute SecurityPermissionto a property to fix this warning, it turned out that the properties are not a valid target for this attribute.

How to fix this FxCop warning?

</" > : " LinkDemand"?

  • , Marshal.GetIUnknownForObject, LinkDemand .
  • FxCop, CA2122
  • googled CA2122 ,
  • google I LinkDemand

, , , , , . Demand vs. LinkDemand Demand .

+3
2

, :

public int Foo
{
   [SecurityPermission(...)]
   get
   {
      return GetFoo();
   }

   [SecurityPermission(...)]
   set
   {
      SetFoo(value);
   }
}
+6

,

[PermissionSetAttribute (SecurityAction.LinkDemand, Name= "FullTrust" )]

. : ( .Net Process)?

0

Source: https://habr.com/ru/post/1719416/


All Articles