다음을 통해 공유


CA2141: 투명한 메서드는 LinkDemands를 충족해서는 안 됩니다

TypeName

TransparentMethodsMustNotSatisfyLinkDemands

CheckId

CA2141

범주

Microsoft.Security

변경 수준

주요 변경

원인

보안 투명 메서드는 AllowPartiallyTrustedCallersAttribute (APTCA) 특성으로 표시된 어셈블리의 메서드를 호출하거나 보안 투명 메서드는 형식 또는 메서드에 대한 SecurityAction().LinkDemand를 충족합니다.

규칙 설명

LinkDemand 충족이 의도하지 않은 권한 상승을 발생시킬 수 있는 보안에 중요한 작업입니다. 보안에 중요한 코드와 같은 보안 감사 요구 사항이 적용되지 않기 때문에 보안 투명 코드는 LinkDemands를 충족해서는 안 됩니다. 보안 규칙 집합 수준 1 어셈블리의 투명 메서드는 모든 LinkDemands가 런타임에 전체 요구로 변환되기에 충분하여 성능 문제를 초래할 수 있습니다. 보안 규칙 집합 수준 2 어셈블리에서 투명한 메서드는 LinkDemand를 충족하는 경우 JIT(Just-In-Time) 컴파일러에서 컴파일할 수 없게 됩니다.

수준 2 보안을 사용하는 어셈블리에서 LinkDemand를 충족시키거나 비 APTCA 어셈블리에서 메서드를 호출하려고 보안 투명 메서드에 의한 시도는 MethodAccessException을 발생시킵니다. 수준 1 어셈블리에서 LinkDemand는 완전 요청이 됩니다.

위반 문제를 해결하는 방법

이 규칙의 위반 문제를 해결하려면 SecurityCriticalAttribute 또는 SecuritySafeCriticalAttribute 특성으로 액세스 메서드를 표시하거나 액세스된 메서드에서 LinkDemand를 제거하십시오.

경고를 표시하지 않는 경우

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

예제

이 예제에서는 투명 메서드는 LinkDemand가 있는 메서드를 호출하려고 시도합니다. 이 규칙은 이 코드를 실행하지 않습니다.

using System;
using System.Security.Permissions;


namespace TransparencyWarningsDemo
{

    public class TransparentMethodSatisfiesLinkDemandsClass
    {
        [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
        public void LinkDemandMethod() { }


        public void TransparentMethod()
        {
            // CA2141 violation - transparent method calling a method protected with a link demand.  Any of the
            // following fixes will work here:
            //  1. Make TransparentMethod critical
            //  2. Make TransparentMethod safe critical
            //  3. Remove the LinkDemand from LinkDemandMethod  (In this case, that would be recommended anyway
            //     since it's level 2 -- however you could imagine it in a level 1 assembly)
            LinkDemandMethod();
        }
    }
}