fix: reject malformed ZoomEye URL fields

This commit is contained in:
NotoriousRebel
2026-08-16 00:36:14 -04:00
parent 2ac59f3a38
commit 02deafa6f1
2 changed files with 12 additions and 5 deletions
+6 -2
View File
@@ -181,11 +181,15 @@ async def test_numbered_pages_keep_a_stable_size_and_slice_the_final_page(monkey
@pytest.mark.asyncio
async def test_early_malformed_rows_and_later_valid_evidence_are_partial(monkeypatch: pytest.MonkeyPatch) -> None:
@pytest.mark.parametrize('malformed_match', [7, {'url': ['https://api.example.com']}])
async def test_early_malformed_rows_and_later_valid_evidence_are_partial(
monkeypatch: pytest.MonkeyPatch,
malformed_match: Any,
) -> None:
monkeypatch.setattr(zoomeyesearch.Core, 'zoomeye_key', staticmethod(lambda: 'test-key'))
monkeypatch.setattr(zoomeyesearch.SearchZoomEye, 'PAGE_SIZE', 1)
responses = [
FetcherResponse({'code': 60000, 'total': 2, 'data': [7]}, 200, {}),
FetcherResponse({'code': 60000, 'total': 2, 'data': [malformed_match]}, 200, {}),
FetcherResponse({'code': 60000, 'total': 2, 'data': [{'hostname': 'api.example.com'}]}, 200, {}),
]
+6 -3
View File
@@ -167,13 +167,16 @@ class SearchZoomEye:
elif (hostname := normalize_scoped_hostname(value, self.target)) and hostname != self.target:
hostnames.add(hostname)
if raw_url := match.get('url'):
if normalized_url := self._normalize_url(raw_url):
raw_url = match.get('url')
if raw_url is not None:
if not isinstance(raw_url, str):
malformed = True
elif normalized_url := self._normalize_url(raw_url):
urls.add(normalized_url)
if url_hostname := normalize_scoped_hostname(urlsplit(normalized_url).hostname, self.target):
if url_hostname != self.target:
hostnames.add(url_hostname)
elif isinstance(raw_url, str):
else:
malformed = True
text_values: list[str] = []