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
7 changes: 6 additions & 1 deletion gateway/relay/descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ def from_json(cls, data: str) -> "CapabilityDescriptor":
fields this gateway does not know yet); missing optional keys fall back
to dataclass defaults.
"""
raw = json.loads(data)
try:
raw = json.loads(data)
except (json.JSONDecodeError, TypeError) as exc:
raise ValueError(f"Invalid handshake JSON: {exc}") from exc
if not isinstance(raw, dict):
raise ValueError(f"Expected JSON object, got {type(raw).__name__}")
known = {f for f in cls.__dataclass_fields__} # type: ignore[attr-defined]
filtered = {k: v for k, v in raw.items() if k in known}
return cls(**filtered)
Expand Down
7 changes: 6 additions & 1 deletion tools/osv_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@ def _query_osv(
)

with urllib.request.urlopen(req, timeout=_TIMEOUT) as resp:
result = json.loads(resp.read())
raw = resp.read()
try:
result = json.loads(raw)
except (json.JSONDecodeError, UnicodeDecodeError):

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.

A valid JSON but non-object response such as [] reaches this line and raises AttributeError, so the OSV check is still not fail-open for all malformed/unexpected response shapes. Please return [] when result is not a dict (and consider validating vulns is a list).

logger.warning("Non-JSON response from OSV API")
return []

vulns = result.get("vulns", [])
# Only malware advisories — ignore regular CVEs
Expand Down