This rule ensures that all network sockets used in your Kotlin application are secured using SSL/TLS encryption. Unencrypted network communication is a significant security risk because it allows attackers to intercept and manipulate the data being transmitted. This can lead to data breaches, unauthorized access, and other security issues.
In Kotlin, you can ensure your sockets are encrypted by using the SSLSocketFactory or SSLServerSocketFactory classes to create your sockets. If you need to use a socket with custom configuration, you can still ensure it is encrypted by using the SSLContext class to create a configured SSL socket. Avoid using the Socket or ServerSocket classes directly, because these classes create unencrypted sockets by default.
Non-Compliant Code Examples
// Example 1: Basic Socket usage
funcreateConnection(){// UNSAFE: Unencrypted socket
valsocket=Socket("api.example.com",80)socket.getOutputStream().write(data)}// Example 2: ServerSocket usage
funstartServer(){// UNSAFE: Unencrypted server socket
valserverSocket=ServerSocket(8080)valclient=serverSocket.accept()}// Example 3: Socket with custom configuration
funconfiguredSocket(){// UNSAFE: Still unencrypted despite configuration
valsocket=Socket("api.example.com",8080,true)socket.soTimeout=5000}
Compliant Code Examples
// Example 1: SSLSocket usage
funcreateSecureConnection(){// SAFE: Using SSL socket factory
valsocket=SSLSocketFactory.getDefault().createSocket("api.example.com",443)socket.getOutputStream().write(data)}// Example 2: SSL ServerSocket usage
funstartSecureServer(){// SAFE: Using SSL server socket factory
valserverSocket=SSLServerSocketFactory.getDefault().createServerSocket(8443)valclient=serverSocket.accept()}// Example 3: Configured SSLSocket
funconfiguredSecureSocket(){valcontext=SSLContext.getInstance("TLS")context.init(null,null,null)// SAFE: Using configured SSL socket
valsocket=context.socketFactory.createSocket("api.example.com",443)}
원활한 통합. Datadog Code Security를 경험해 보세요
Datadog Code Security
이 규칙을 사용해 Datadog Code Security로 코드를 분석하세요
규칙 사용 방법
1
2
rulesets:- kotlin-security # Rules to enforce Kotlin security.
리포지토리 루트에 위의 내용을 포함하는 static-analysis.datadog.yml을 만듭니다
무료 IDE 플러그인을 사용하거나 CI 파이프라인에 Code Security 검사를 추가합니다