다음을 통해 공유


대부분의 코드 액세스 보안 API가 사용되지 않음

.NET의 CAS(코드 액세스 보안) 관련 형식은 대부분 경고로 표시되며 사용되지 않습니다. 여기에는 SecurityPermissionAttribute, CAS 권한 개체(예: SocketPermission), EvidenceBase 파생 형식 및 기타 지원되는 API와 같은 CAX 특성이 포함됩니다.

변경 내용 설명

.NET Framework 2.x - 4.x에서 CAS 특성 및 API는 CAS 요청 스택이 성공하거나 실패하도록 하는 등 코드 실행 과정에 영향을 줄 수 있습니다.

// In .NET Framework, the attribute causes CAS stack walks
// to terminate successfully when this permission is demanded.
[SocketPermission(SecurityAction.Assert, Host = "contoso.com", Port = "443")]
public void DoSomething()
{
    // open a socket to contoso.com:443
}

.NET Core 2.x - 3.x에서 런타임은 CAS 특성이나 CAS API를 적용하지 않습니다. 런타임은 메서드 항목의 특성을 무시하고 대부분의 프로그래밍 API는 영향을 주지 않습니다.

// The .NET Core runtime ignores the following attribute.
[SocketPermission(SecurityAction.Assert, Host = "contoso.com", Port = "443")]
public void DoSomething()
{
    // open a socket to contoso.com:443
}

또한 광범위한 API에 대한 프로그래밍 방식 호출(Assert)은 항상 성공하지만 제한적 API에 대한 프로그래밍 방식 호출(Deny, PermitOnly)은 런타임에 항상 예외를 throw합니다. (PrincipalPermission은 이 규칙의 예외입니다. 아래의 권장 사항 섹션을 참조하세요.)

public void DoAssert()
{
    // The line below has no effect at run time.
    new SocketPermission(PermissionState.Unrestricted).Assert();
}

public void DoDeny()
{
    // The line below throws PlatformNotSupportedException at run time.
    new SocketPermission(PermissionState.Unrestricted).Deny();
}

.NET 5 이상 버전에서 대부분의 CAS 관련 API는 더 이상 사용되지 않으며 SYSLIB0003 컴파일 시간 경고를 생성합니다.

[SocketPermission(SecurityAction.Assert, Host = "contoso.com", Port = "443")] // warning SYSLIB0003
public void DoSomething()
{
    new SocketPermission(PermissionState.Unrestricted).Assert(); // warning SYSLIB0003
    new SocketPermission(PermissionState.Unrestricted).Deny(); // warning SYSLIB0003
}

이는 컴파일 시간 전용 변경입니다. .NET Core의 이전 버전에서 런타임 변경은 없습니다. .NET Core 2.x - 3.x에서 작업을 수행하지 않는 메서드는 .NET 5 이상에서도 런타임에 계속 작업을 수행하지 않습니다. .NET Core 2.x - 3.x에서 PlatformNotSupportedException을 throw하는 메서드는 .NET 5 이상에서도 런타임에 PlatformNotSupportedException을 계속 throw합니다.

변경 이유

CAS(코드 액세스 보안)는 지원되지 않는 레거시 기술입니다. CAS를 사용하도록 설정하는 인프라는 .NET Framework 2.x - 4.x에만 있지만 사용되지 않으며 서비스 또는 보안 수정을 받지 않습니다.

CAS가 사용되지 않기 때문에 지원 인프라가 .NET Core 또는 .NET 5 이상으로 전달되지 않았습니다. 그러나 앱이 .NET Framework 및 .NET Core에 대해 크로스 컴파일을 수행할 수 있도록 API가 전달되었습니다. 따라서 일부 CAS 관련 API가 존재하고 호출할 수 있지만 런타임에 작업을 수행하지 않는 “열기 실패” 시나리오가 됩니다. 그러면 런타임에서 CAS 관련 특성 또는 프로그래밍 API 호출을 적용하도록 하는 구성 요소에 대한 보안 문제가 발생할 수 있습니다. 런타임에서 이러한 특성이나 API를 사용하지 않음을 더욱 잘 전달하기 위해 .NET 5.0에서는 대부분 사용되지 않음으로 설정했습니다.

도입된 버전

5.0

  • 보안 권한을 어설션하려면 사용 권한을 어설션하는 호출이나 특성을 제거하세요.

    // REMOVE the attribute below.
    [SecurityPermission(SecurityAction.Assert, ControlThread = true)]
    public void DoSomething()
    {
    }
    
    public void DoAssert()
    {
        // REMOVE the line below.
        new SecurityPermission(SecurityPermissionFlag.ControlThread).Assert();
    }
    
  • PermitOnly를 통해 사용 권한을 거부하거나 제한하려면 보안 관리자에게 문의하세요. CAS 특성은 .NET 5 이상 런타임에 적용되지 않기 때문에 CAS 인프라를 사용하여 이러한 메서드에 대한 액세스를 제한하는 경우 애플리케이션에서 보안 허점이 발생할 수 있습니다.

    // REVIEW the attribute below; could indicate security vulnerability.
    [SecurityPermission(SecurityAction.Deny, ControlThread = true)]
    public void DoSomething()
    {
    }
    
    public void DoPermitOnly()
    {
        // REVIEW the line below; could indicate security vulnerability.
        new SecurityPermission(SecurityPermissionFlag.ControlThread).PermitOnly();
    }
    
  • PrincipalPermission을 제외한 모든 사용 권한을 요청하려면 요청을 제거하세요. 모든 요청은 런타임에 성공합니다.

    // REMOVE the attribute below; it will always succeed.
    [SecurityPermission(SecurityAction.Demand, ControlThread = true)]
    public void DoSomething()
    {
    }
    
    public void DoDemand()
    {
        // REMOVE the line below; it will always succeed.
        new SecurityPermission(SecurityPermissionFlag.ControlThread).Demand();
    }
    
  • PrincipalPermission을 요청하려면 PrincipalPermissionAttribute가 오류로 사용되지 않음에 대한 지침을 참조하세요. 이 지침은 PrincipalPermissionPrincipalPermissionAttribute 모두에 적용됩니다.

  • 이러한 경고를 반드시 사용하지 않도록 설정해야 하는 경우(권장되지 않음) 코드에서 SYSLIB0003 경고를 표시하지 않을 수 있습니다.

    #pragma warning disable SYSLIB0003 // disable the warning
    [SecurityPermission(SecurityAction.Demand, ControlThread = true)]
    #pragma warning restore SYSLIB0003 // re-enable the warning
    public void DoSomething()
    {
    }
    
    public void DoDemand()
    {
    #pragma warning disable SYSLIB0003 // disable the warning
        new SecurityPermission(SecurityPermissionFlag.ControlThread).Demand();
    #pragma warning restore SYSLIB0003 // re-enable the warning
    }
    

    프로젝트 파일에서 경고를 표시하지 않을 수도 있습니다. 이렇게 하면 프로젝트 내의 모든 소스 파일에 대한 경고를 사용할 수 없게 됩니다.

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <TargetFramework>net5.0</TargetFramework>
        <!-- NoWarn below suppresses SYSLIB0003 project-wide -->
        <NoWarn>$(NoWarn);SYSLIB0003</NoWarn>
      </PropertyGroup>
    </Project>
    

    참고 항목

    SYSLIB0003을 표시하지 않으면 CAS 관련 사용되지 않음 경고만 사용하지 않도록 설정합니다. 다른 경고를 사용하지 않도록 설정하거나 .NET 5 이상 런타임의 동작을 변경하지는 않습니다.

  • 보안

영향을 받는 API