Skip to content
Merged
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 src/modulr_core/operations/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,13 @@ def _health_activity_nonneg_points(
f"{base}.{field}[{i}] must be a finite number",
code=ErrorCode.PAYLOAD_INVALID,
)
fv = float(p)
try:
fv = float(p)
except (OverflowError, ValueError):
raise WireValidationError(
f"{base}.{field}[{i}] must be a representable finite number",
code=ErrorCode.PAYLOAD_INVALID,
) from None
if fv < 0:
raise WireValidationError(
f"{base}.{field}[{i}] must be non-negative",
Expand Down
40 changes: 40 additions & 0 deletions tests/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,46 @@ def test_report_module_state_rejects_negative_jobs_point() -> None:
assert ei.value.code is ErrorCode.PAYLOAD_INVALID


def test_report_module_state_rejects_health_point_int_overflow_to_float() -> None:
"""Huge JSON integers must not become float(OverflowError) → 500."""
pk = Ed25519PrivateKey.generate()
conn = _conn()
sender_pub = pk.public_key().public_bytes(
encoding=Encoding.Raw,
format=PublicFormat.Raw,
)
reg = make_validated_inbound(
pk,
"register_module",
{
"module_name": "modulr.storage",
"module_version": MODULE_VERSION,
"route": {},
"signing_public_key": sender_pub.hex(),
},
"rms-of1",
)
dispatch_operation(reg, settings=_settings(), conn=conn, clock=lambda: 1.0)
bad = json.loads(_valid_report_module_state_detail())
jp = list(bad["health_activity_24h"]["jobs_points"])
jp[0] = 10**400
bad["health_activity_24h"] = {**bad["health_activity_24h"], "jobs_points": jp}
detail = json.dumps(bad, separators=(",", ":"), sort_keys=True)
req = make_validated_inbound(
pk,
"report_module_state",
{
"module_id": "modulr.storage",
"state_phase": "running",
"detail": detail,
},
"rms-of2",
)
with pytest.raises(WireValidationError) as ei:
dispatch_operation(req, settings=_settings(), conn=conn, clock=lambda: 2.0)
assert ei.value.code is ErrorCode.PAYLOAD_INVALID


def test_report_module_state_strips_unknown_health_keys_with_warning() -> None:
pk = Ed25519PrivateKey.generate()
conn = _conn()
Expand Down
Loading