CA5398: 하드 코딩된 SslProtocols 값 방지
속성 | 값 |
---|---|
규칙 ID | CA5398 |
제목 | SslProtocols 값을 하드 코딩하지 마세요. |
범주 | 보안 |
수정 사항이 주요 변경인지 여부 | 주요 변경 아님 |
.NET 9에서 기본적으로 사용 | 아니요 |
원인
이 규칙은 다음 조건 중 하나가 충족될 때 발생합니다.
- 안전하지만 하드 코드된 System.Security.Authentication.SslProtocols 값이 참조되었습니다.
- 안전한 프로토콜 버전을 나타내는 정수 값이 변수에 SslProtocols 할당되거나 반환 값으로 SslProtocols 사용되거나 인수로 SslProtocols 사용되었습니다.
안전한 값:
- Tls12
- Tls13
규칙 설명
TLS(전송 계층 보안)는 가장 일반적으로 HTTPS(Hypertext Transfer Protocol Secure)를 사용하여 컴퓨터 간의 통신을 보호합니다. 프로토콜 버전 TLS 1.0 및 TLS 1.1은 사용되지 않으며 TLS 1.2 및 TLS 1.3은 최신 상태입니다. 나중에는 TLS 1.2 및 TLS 1.3도 사용되지 않을 수 있습니다. 애플리케이션을 안전하게 유지하려면 프로토콜 버전을 하드 코드하지 마세요. 자세한 내용은 .NET Framework를 사용한 TLS(전송 계층 보안) 모범 사례를 참조하세요.
위반 문제를 해결하는 방법
TLS 프로토콜 버전을 하드 코드하지 마세요.
경고를 표시하지 않는 경우
향후 TLS 프로토콜 버전을 사용하도록 업그레이드할 수 없는 레거시 서비스에 연결해야 하는 경우 경고를 표시하지 않아도 됩니다.
경고 표시 안 함
단일 위반만 표시하지 않으려면 원본 파일에 전처리기 지시문을 추가하여 규칙을 사용하지 않도록 설정한 후 다시 사용하도록 설정합니다.
#pragma warning disable CA5398
// The code that's violating the rule is on this line.
#pragma warning restore CA5398
파일, 폴더 또는 프로젝트에 대한 규칙을 사용하지 않도록 설정하려면 none
에서 심각도를 으로 설정합니다.
[*.{cs,vb}]
dotnet_diagnostic.CA5398.severity = none
자세한 내용은 방법: 코드 분석 경고 표시 안 함을 참조하세요.
의사 코드 예제
열거형 이름 위반
using System;
using System.Security.Authentication;
public class ExampleClass
{
public void ExampleMethod()
{
// CA5398 violation
SslProtocols sslProtocols = SslProtocols.Tls12;
}
}
Imports System
Imports System.Security.Authentication
Public Class TestClass
Public Function ExampleMethod() As SslProtocols
' CA5398 violation
Return SslProtocols.Tls12
End Function
End Class
정수 값 위반
using System;
using System.Security.Authentication;
public class ExampleClass
{
public SslProtocols ExampleMethod()
{
// CA5398 violation
return (SslProtocols) 3072; // TLS 1.2
}
}
Imports System
Imports System.Security.Authentication
Public Class TestClass
Public Function ExampleMethod() As SslProtocols
' CA5398 violation
Return CType(3072, SslProtocols) ' TLS 1.2
End Function
End Class
솔루션
using System;
using System.Security.Authentication;
public class TestClass
{
public void Method()
{
// Let the operating system decide what TLS protocol version to use.
// See https://learn.microsoft.com/dotnet/framework/network-programming/tls
SslProtocols sslProtocols = SslProtocols.None;
}
}
Imports System
Imports System.Security.Authentication
Public Class TestClass
Public Sub ExampleMethod()
' Let the operating system decide what TLS protocol version to use.
' See https://learn.microsoft.com/dotnet/framework/network-programming/tls
Dim sslProtocols As SslProtocols = SslProtocols.None
End Sub
End Class
관련 규칙
CA5364: 사용되지 않는 보안 프로토콜을 사용하지 마세요.
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET