다음을 통해 공유


재정의 링크 요청은 기본 형식의 링크 요청과 같아야 합니다.

업데이트: 2007년 11월

TypeName

OverrideLinkDemandsShouldBeIdenticalToBase

CheckId

CA2123

범주

Microsoft.Security

변경 수준

주요 변경

원인

public 형식의 public 또는 protected 메서드가 메서드를 재정의하거나 인터페이스를 구현하고 이 메서드의 링크 요청이 인터페이스 또는 가상 메서드의 링크 요청과 같지 않습니다.

규칙 설명

이 규칙에서는 메서드를 다른 형식의 인터페이스이거나 가상 메서드인 기본 메서드에 일치시킨 다음 각각에 대해 링크 요청을 비교합니다. 메서드와 기본 메서드 중 하나에만 링크 요청이 있고 나머지 다른 하나에는 링크 요청이 없는 경우 위반이 보고됩니다.

이 규칙이 위반된 경우 악의적인 호출자가 보안상 위험한 메서드를 호출하여 링크 요청을 우회할 수 있습니다.

위반 문제를 해결하는 방법

이 규칙 위반 문제를 해결하려면 링크 요청이 없는 메서드에 링크 요청을 적용합니다.

경고를 표시하지 않는 경우

이 규칙에서는 경고를 표시해야 합니다.

예제

다음 예제에서는 이 규칙이 위반되는 다양한 형태를 보여 줍니다.

using System.Security;
using System.Security.Permissions;
using System;

namespace SecurityRulesLibrary
{
   public interface ITestOverrides
   {  
      [EnvironmentPermissionAttribute(SecurityAction.LinkDemand, Unrestricted=true)]
      Object GetFormat(Type formatType);
   }

   public class OverridesAndSecurity : ITestOverrides
   {
      // Rule violation: The interface has security, and this implementation does not.
      object ITestOverrides.GetFormat(Type formatType)
      {
         return (formatType == typeof(OverridesAndSecurity) ? this : null);
      }

      // These two methods are overridden by DerivedClass and DoublyDerivedClass.
      [EnvironmentPermissionAttribute(SecurityAction.LinkDemand, Unrestricted=true)]
      public virtual void DoSomething()
      {
         Console.WriteLine("Doing something.");
      }

      public virtual void DoSomethingElse()
      {
         Console.WriteLine("Doing some other thing.");
      }
   }

   public class DerivedClass : OverridesAndSecurity, ITestOverrides
   {
      //  Rule violation: The interface has security, and this implementation does not.
      public object GetFormat(Type formatType)
      {
         return (formatType == typeof(OverridesAndSecurity) ? this : null);
      }

      // Rule violation: This does not have security, but the base class version does.
      public override void DoSomething()
      {
         Console.WriteLine("Doing some derived thing.");
      }

      // Rule violation: This has security, but the base class version does not.
      [EnvironmentPermissionAttribute(SecurityAction.LinkDemand, Unrestricted=true)]
      public override void DoSomethingElse()
      {
         Console.WriteLine("Doing some other derived thing.");
      }
   }

   public class DoublyDerivedClass : DerivedClass
   {
      // The OverridesAndSecurity version of this method does not have security. 
      // Base class DerivedClass's version does. 
      // The DoublyDerivedClass version does not violate the rule, but the 
      // DerivedClass version does violate the rule.
      public override void DoSomethingElse()
      {
         Console.WriteLine("Doing some other derived thing.");
      }
   }
}

참고 항목

개념

링크 요청

기타 리소스

보안 코딩 지침