Keep provider priority inside an exploit type
This commit is contained in:
1 parent
0b0f1151fd
commit
0a1d9f67b9
2 files changed
+16
-2
No files matched your search
@@ -489,7 +489,12 @@ def _exploit_refs(group: Group) -> list[dict[str, Any]]:
|
||||
if url is None:
|
||||
continue
|
||||
selected.setdefault((kind, url), dict(value) | {'type': kind, 'url': url})
|
||||
return sorted(selected.values(), key=lambda ref: (_EXPLOIT_ORDER[ref['type']], ref['url']))[:_EXPLOIT_CAP]
|
||||
# The sort is stable, so a provider's own priority (verified, newest) survives:
|
||||
# only the type grouping and the verified preference reorder anything.
|
||||
return sorted(
|
||||
selected.values(),
|
||||
key=lambda ref: (_EXPLOIT_ORDER[ref['type']], ref.get('verified') is not True),
|
||||
)[:_EXPLOIT_CAP]
|
||||
|
||||
|
||||
def _exploitation(group: Group) -> dict[str, Any] | None:
|
||||
|
||||
+10
-1
@@ -36,7 +36,7 @@ def _hit(group: Group, asset: AssetFacts | None = None):
|
||||
return _render(group, query, target, [], _index())
|
||||
|
||||
|
||||
def test_refs_are_ordered_by_type_then_url() -> None:
|
||||
def test_refs_are_ordered_by_type() -> None:
|
||||
group = _group(
|
||||
_claim('pocs', CVE, {'exploit_refs': [{'type': 'poc_repo', 'url': POC}]}),
|
||||
_claim('nuclei', CVE, {'exploit_refs': [{'type': 'detection_template', 'url': TEMPLATE}]}),
|
||||
@@ -48,6 +48,15 @@ def test_refs_are_ordered_by_type_then_url() -> None:
|
||||
]
|
||||
|
||||
|
||||
def test_verified_refs_precede_unverified_ones_of_the_same_type() -> None:
|
||||
group = _group(_claim('exploitdb', CVE, {'exploit_refs': [
|
||||
{'type': 'exploit_db', 'url': EDB + '9'},
|
||||
{'type': 'exploit_db', 'url': EDB + '1', 'verified': True},
|
||||
{'type': 'exploit_db', 'url': EDB + '5'},
|
||||
]}))
|
||||
assert [ref['url'] for ref in _hit(group).exploit_refs] == [EDB + '1', EDB + '9', EDB + '5']
|
||||
|
||||
|
||||
def test_refs_dedup_by_type_and_url_and_keep_extra_fields() -> None:
|
||||
group = _group(
|
||||
_claim('exploitdb', CVE, {'exploit_refs': [
|
||||
|
||||
Reference in new issue
Block a user