mirror of
https://github.com/yogeshojha/rengine.git
synced 2026-10-20 07:11:28 +02:00
Every result and management table gains multi-row selection and the floating action bar targets and scans already had: copy, export selection, delete, and the dimension's own actions. Rescan and triage move off the inline strip, which now only offers the rescan that acts on the whole query. Delete is dimension-local. A row takes only what cannot stand without it: a web asset its stored responses, a secret its sightings. Endpoints, services and findings on a deleted host are kept, so every count stays equal to its table. POST /surface/delete is the one route and the scope is a WHERE, so an id from another scan deletes nothing. Vulnerabilities are addressable by template_id so the Issues view deletes a whole check. Exposures dismiss rather than delete: an exposure row is a web asset. Selection export runs through the export pipeline. Every surface filter gains ids, capped by MAX_SELECTED_ROWS. Secrets and software become exportable, which fixes two breaks: a bundle export raised KeyError on the secrets dimension, and mcp read a SURFACE_COLUMNS entry for secrets that did not exist. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XyDpdVXL7YVsr5D7BVj2zt
79 lines
2.1 KiB
Python
79 lines
2.1 KiB
Python
"""Software CVE statement building, shared by the api's search and the worker's export."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from sqlalchemy import func, select
|
|
|
|
from shared.definitions.asset_query import SOFTWARE_QUERY
|
|
from shared.models.software import SoftwareCve
|
|
from shared.services.asset_query import (
|
|
QueryScope,
|
|
SoftwareQueryContext,
|
|
compile_software_query,
|
|
parse_query,
|
|
)
|
|
|
|
if TYPE_CHECKING:
|
|
from datetime import datetime
|
|
|
|
from shared.models.software import SoftwareFilter
|
|
|
|
_SORTS = {
|
|
"rank": SoftwareCve.exploit_score,
|
|
"cvss": SoftwareCve.cvss_score,
|
|
"epss": SoftwareCve.epss_score,
|
|
"cve": SoftwareCve.cve,
|
|
"software": SoftwareCve.name,
|
|
"host": SoftwareCve.host,
|
|
"seen": SoftwareCve.discovered_at,
|
|
}
|
|
|
|
|
|
def severity_rank():
|
|
return func.coalesce(SoftwareCve.cvss_score, 0.0)
|
|
|
|
|
|
def context(scope: QueryScope, now: datetime) -> SoftwareQueryContext:
|
|
return SoftwareQueryContext(scope=scope, now=now)
|
|
|
|
|
|
def apply_filter(query, f: SoftwareFilter):
|
|
if f.ids:
|
|
query = query.where(SoftwareCve.id.in_(f.ids))
|
|
return query
|
|
|
|
|
|
def order(query, f: SoftwareFilter):
|
|
column = _SORTS.get((f.sort or "").lower())
|
|
if column is None:
|
|
return query.order_by(
|
|
SoftwareCve.exploit_score.desc(),
|
|
severity_rank().desc(),
|
|
SoftwareCve.cve.desc(),
|
|
SoftwareCve.id,
|
|
)
|
|
descending = (f.direction or "desc").lower() != "asc"
|
|
ordered = column.desc() if descending else column.asc()
|
|
return query.order_by(ordered, SoftwareCve.cve, SoftwareCve.id)
|
|
|
|
|
|
def scoped(scope: QueryScope, f: SoftwareFilter, columns=None):
|
|
base = select(SoftwareCve) if columns is None else select(*columns)
|
|
return apply_filter(base.where(scope.match(SoftwareCve.scan_id)), f)
|
|
|
|
|
|
def compiled(scope: QueryScope, f: SoftwareFilter, now: datetime):
|
|
return compile_software_query(parse_query(f.q, SOFTWARE_QUERY), context(scope, now))
|
|
|
|
|
|
__all__ = [
|
|
"apply_filter",
|
|
"compiled",
|
|
"context",
|
|
"order",
|
|
"scoped",
|
|
"severity_rank",
|
|
]
|