🇰🇷 한글 설명
Apache Kafka의 코드 생성 프로토콜 리더가 송신자가 선언한 배열 원소 수만큼 메모리를 미리 할당하는 문제입니다. 원소 수 검증이 요청 버퍼의 남은 바이트 수에만 기반해 원소당 약 1바이트를 가정하므로, 실제 버퍼보다 훨씬 큰 원소 수를 선언한 요청이 통과되어 수 배의 힙 메모리가 할당될 수 있습니다. 인증 이전 단계에서 발생하므로 인증이 없는 리스너에서도 악용될 수 있습니다.
💡 쉬운 설명
공격자가 수십 MB 크기의 요청을 여러 개 동시에 보내 브로커가 사용할 메모리를 크게 부풀리면 브로커가 메모리 부족으로 종료될 수 있습니다. 이 과정은 권한 확인 전에 일어나기 때문에 인증이 없는 경로에서도 위험합니다.
🇺🇸 원문 (English)
Apache Kafka's code-generated protocol readers pre-size an array's collection from the element count declared by the sender. That count is checked only against the bytes remaining in the request buffer, which assumes about one byte per element; because most elements need several bytes, a request can declare far more elements than the buffer holds and still pass. For a keyed array the reader then allocates an ImplicitLinkedHashCollection of capacity (2 * count +1), so a request of a few tens of megabytes can force a heap allocation several times larger before any element is read. The pattern is emitted into every generated reader, so it affects all Kafka API types with an array field.
Impact:
Request parsing happens before any authorization check. On a listener that does not require authentication (for example PLAINTEXT), an unauthenticated attacker can send a few concurrent requests that each declare a very large=
array length and allocate many times their wire size in broker heap, crashing the broker with an OutOfMemoryError. The reporter demonstrated three concurrent ~90 MB ProduceRequest (v3) connections exhausting a 1 GB heap (~8x amplification). On listeners that require authentication, the attacker needs valid credentials but no specific ACL, since parsing precedes authorization..
Mitigation:
Upgrade to Apache Kafka 4.2.2, 4.3.2, or 4.4.0. Until then, lowering socket.request.max.bytes and restricting network access to broker listeners reduces, but does not remove, exposure.
Resolution:
From Apache Kafka 4.2.2, 4.3.2, and 4.4.0: generated readers cap the initial array pre-allocation at MessageUtil.MAX_PREALLOCATED_ARRAY_CAPACITY (1000) and grow it on demand, and reject a declared array length above MessageUtil.MAX_ARRAY_LENGTH (1,000,000).
📍 영향받는 시스템
Apache Kafka 4.2.2 미만, 4.3.2 미만, 4.4.0 미만 버전
⚔️ 공격 벡터
인증 없이(또는 인증 후 ACL 없이) 원소 수를 과도하게 선언한 대용량 요청을 동시에 여러 개 전송해 브로커 힙 메모리를 고갈시킴
🛡️ 대응 방법
Apache Kafka 4.2.2, 4.3.2, 4.4.0 이상으로 업그레이드하고, 그 전까지는 socket.request.max.bytes를 낮추고 브로커 리스너에 대한 네트워크 접근을 제한
🔧 검증 코드
출력되는 jar 파일명의 버전(예: kafka_2.13-4.2.2.jar)을 확인해 4.2.2 이상(4.3.x는 4.3.2 이상, 4.4.x는 4.4.0 이상)이면 패치된 것이고, 그보다 낮으면 취약합니다.
kafka-broker-api-versions.sh --bootstrap-server localhost:9092 2>/dev/null | head -n 1; ls $(dirname $(readlink -f $(which kafka-server-start.sh 2>/dev/null) 2>/dev/null) 2>/dev/null)/../libs/kafka_*.jar 2>/dev/null | head -n 1