The vulnerability lies in the way Spring for Apache Kafka's JsonKafkaHeaderMapper and DefaultKafkaHeaderMapper handle trusted packages for deserialization. The root cause is the use of a startsWith check instead of an exact match when verifying if a package is trusted. This allows an attacker to craft a malicious header that points to a class in a subpackage of a trusted package, leading to the deserialization of arbitrary JDK types and potential remote code execution.
The analysis of the patch commits between the vulnerable and fixed versions clearly shows the removal of the startsWith logic in the isTrustedPackage method of both affected classes. The vulnerable functions are org.springframework.kafka.support.JsonKafkaHeaderMapper.isTrustedPackage and org.springframework.kafka.support.mapping.DefaultKafkaHeaderMapper.isTrustedPackage, as these are the methods containing the flawed logic that would be called during the deserialization process of a malicious Kafka message header.