Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion vulnerabilities/pipelines/enhance_with_exploitdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,19 @@ def add_exploit_references(ref_id, direct_url, path, vul_id, logger):
"direct_url": direct_url,
}

MAX_REF_LEN = 200
if ref_id and len(ref_id) > MAX_REF_LEN:
safe_ref_id = ref_id[:MAX_REF_LEN] + "..."
else:
safe_ref_id = ref_id

for key, url in url_map.items():
if url:
try:
ref, created = VulnerabilityReference.objects.update_or_create(
url=url,
defaults={
"reference_id": ref_id,
"reference_id": safe_ref_id,
"reference_type": VulnerabilityReference.EXPLOIT,
Comment on lines +143 to 144
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test for this change.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. I’ve already added the truncation with ellipsis update, and I’m now adding a dedicated test case for this behavior in the ExploitDB pipeline tests. I’ll push the update shortly.

},
)
Expand Down
26 changes: 26 additions & 0 deletions vulnerabilities/tests/pipelines/test_enhance_with_exploitdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,29 @@ def test_invalid_exploit_db_improver(mock_get):
status, _ = improver.execute()
assert status == 0
assert Exploit.objects.count() == 0
@pytest.mark.django_db
@mock.patch("requests.get")
def test_reference_id_is_truncated_with_ellipsis(mock_get):
mock_response = Mock(status_code=200)

with open(TEST_DATA, "r") as f:
data = f.read()

# make long exploit id/reference text
data = data.replace("CVE-2009-3699", "A" * 300)

mock_response.text = data
mock_get.return_value = mock_response

v1 = Vulnerability.objects.create(vulnerability_id="VCIO-123-2002")
v1.save()

Alias.objects.create(alias="A" * 300, vulnerability=v1)

improver = ExploitDBImproverPipeline()
improver.execute()

exploit = Exploit.objects.first()
assert exploit is not None
assert len(exploit.reference_id) <= 200
assert exploit.reference_id.endswith("...")