|
| 1 | +# |
| 2 | +# Copyright (c) nexB Inc. and others. All rights reserved. |
| 3 | +# VulnerableCode is a trademark of nexB Inc. |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | +# See http://www.apache.org/licenses/LICENSE-2.0 for the license text. |
| 6 | +# See https://github.com/aboutcode-org/vulnerablecode for support or download. |
| 7 | +# See https://aboutcode.org for more information about nexB OSS projects. |
| 8 | +# |
| 9 | + |
| 10 | + |
| 11 | +from pathlib import Path |
| 12 | +from unittest import TestCase |
| 13 | + |
| 14 | +from bs4 import BeautifulSoup |
| 15 | + |
| 16 | +from vulnerabilities.pipes.apache_kafka import get_original_advisory |
| 17 | +from vulnerabilities.pipes.apache_kafka import parse_range |
| 18 | +from vulnerabilities.pipes.apache_kafka import parse_summary |
| 19 | +from vulnerabilities.tests.pipelines import TestLogger |
| 20 | + |
| 21 | +TEST_DATA = Path(__file__).parent.parent / "test_data" / "apache_kafka" |
| 22 | + |
| 23 | + |
| 24 | +class TestPipeApacheKafka(TestCase): |
| 25 | + def setUp(self): |
| 26 | + self.logger = TestLogger() |
| 27 | + cve_list = TEST_DATA / "cve-list-2026_01_23.html" |
| 28 | + advisory_data = open(cve_list).read() |
| 29 | + soup = BeautifulSoup(advisory_data, features="lxml") |
| 30 | + self.tables = soup.find(class_="td-content").find_all("table") |
| 31 | + self.tables = list(self.tables) |
| 32 | + |
| 33 | + def test_vulnerability_pipes_apache_kafka_get_summary(self): |
| 34 | + table = self.tables[0] |
| 35 | + cve_h2 = table.find_previous("h2") |
| 36 | + |
| 37 | + result = parse_summary( |
| 38 | + cve_h2=cve_h2, |
| 39 | + table=table, |
| 40 | + ) |
| 41 | + expected = ( |
| 42 | + "In CVE-2023-25194, we announced the RCE/Denial of service attack via SASL " |
| 43 | + "JAAS JndiLoginModule configuration in Kafka Connect API. But not only Kafka " |
| 44 | + "Connect API is vulnerable to this attack, the Apache Kafka brokers also have " |
| 45 | + "this vulnerability. To exploit this vulnerability, the attacker needs to be " |
| 46 | + "able to connect to the Kafka cluster and have the AlterConfigs permission on " |
| 47 | + "the cluster resource. Since Apache Kafka 3.4.0, we have added a system property " |
| 48 | + '("-Dorg.apache.kafka.disallowed.login.modules") to disable the problematic login ' |
| 49 | + "modules usage in SASL JAAS configuration. Also by default " |
| 50 | + "“com.sun.security.auth.module.JndiLoginModule” is disabled in Apache Kafka 3.4.0, " |
| 51 | + "and “com.sun.security.auth.module.JndiLoginModule,com.sun.security.auth.module.LdapLoginModule” " |
| 52 | + "is disabled by default in Apache Kafka 3.9.1/4.0.0. " |
| 53 | + ) |
| 54 | + self.assertEqual(result, expected) |
| 55 | + |
| 56 | + def test_vulnerability_pipes_apache_kafka_get_original_advisory(self): |
| 57 | + table = self.tables[0] |
| 58 | + cve_h2 = table.find_previous("h2") |
| 59 | + |
| 60 | + result = get_original_advisory( |
| 61 | + cve_h2=cve_h2, |
| 62 | + table=table, |
| 63 | + ) |
| 64 | + |
| 65 | + self.assertIn('id="CVE-2025-27819"', result) |
| 66 | + self.assertIn("<p>2.0.0 - 3.3.2</p>", result) |
| 67 | + |
| 68 | + def test_vulnerability_pipes_apache_kafka_parse_range(self): |
| 69 | + affected = "2.8.0 - 2.8.1, 3.0.0 - 3.0.1, 3.1.0 - 3.1.1, 3.2.0 - 3.2.1" |
| 70 | + |
| 71 | + result_affected = parse_range(affected) |
| 72 | + result_affected = [str(const) for const in result_affected] |
| 73 | + expected_affected = [ |
| 74 | + ">=2.8.0", |
| 75 | + "<=2.8.1", |
| 76 | + ">=3.0.0", |
| 77 | + "<=3.0.1", |
| 78 | + ">=3.1.0", |
| 79 | + "<=3.1.1", |
| 80 | + ">=3.2.0", |
| 81 | + "<=3.2.1", |
| 82 | + ] |
| 83 | + |
| 84 | + self.assertCountEqual(result_affected, expected_affected) |
| 85 | + |
| 86 | + def test_vulnerability_pipes_apache_kafka_parse_range_dirty_range(self): |
| 87 | + affected = "Apache Kafka Connect API (connect-api,connect-runtime) : 2.3.0 - 3.3.2" |
| 88 | + |
| 89 | + result_affected = parse_range(affected) |
| 90 | + result_affected = [str(const) for const in result_affected] |
| 91 | + expected_affected = [">=2.3.0", "<=3.3.2"] |
| 92 | + |
| 93 | + self.assertCountEqual(result_affected, expected_affected) |
0 commit comments