- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: kotlin-security/secure-jwt-algorithm
Language: Kotlin
Severity: Error
Category: Security
CWE: 327
This rule helps maintain the integrity and security of JSON Web Tokens (JWTs) in your Kotlin applications. JWTs are often used for authentication and information exchange, which makes them a prime target for malicious attacks. Using the none
algorithm in JWT creation means that the tokens are not signed or validated, which can lead to token forgery and unauthorized access to sensitive data.
This rule is important because an attacker can modify the token payload when the algorithm is none
. In this case, because there is no signature to verify that the content was not tampered with, the attacker can impersonate any user. This can lead to serious security breaches.
To adhere to this rule, always use a secure algorithm when creating JWTs. For instance, use HMAC combined with SHA-256 (HMAC256
). This ensures that the tokens are signed and validated, preventing token forgery. Additionally, handle exceptions properly to ensure your application can respond effectively to any JWT creation errors.
// Non-compliant: Using 'none' algorithm which allows token forgery
fun createUnsafeJwtToken(issuer: String): String {
try {
// WARNING: This allows attackers to forge tokens
val algorithm = Algorithm.none()
return JWT.create()
.withIssuer(issuer)
.sign(algorithm)
} catch (e: JWTCreationException) {
throw SecurityException("Failed to create JWT token", e)
}
}
// Compliant: Using secure HMAC256 algorithm
fun createSecureJwtToken(issuer: String, secretKey: String): String {
try {
// Secure algorithm with proper key
val algorithm = Algorithm.HMAC256(secretKey)
return JWT.create()
.withIssuer(issuer)
.withIssuedAt(Date())
.sign(algorithm)
} catch (e: JWTCreationException) {
throw SecurityException("Failed to create JWT token", e)
}
}