fix(security): close MEDIUM ASVS findings — JWT pinning, SSE tickets, SSRF, mTLS pin, rate limits + correctness bugs
Auth (V2.1.1/V3.1.2, V2.1.3, V3.1.1): - Pin JWT iss/aud/typ at mint and require+verify them at decode; revocation (jti denylist + tokens_valid_from) still enforced. - Change-password now requires min_length=12. - SSE auth moves off JWT-in-URL to a single-use 60s opaque ticket (POST /auth/sse-ticket); raw JWT in query no longer authenticates a stream. Removed dead fail-open get_stream_user helper. Egress (V5.1.1, V9.1.1/V14.1.3): - Webhook delivery + CRUD reject SSRF destinations (private/loopback/link-local/ metadata, IPv4-mapped, multi-A-record) via resolved-IP validation, pin to the vetted IP, and never auto-follow redirects. Opt-out via DECNET_WEBHOOK_ALLOW_PRIVATE. - UpdaterClient pins the worker leaf cert SHA-256 against the stored per-host fingerprint (fail closed on missing/mismatch); DECNET_VERIFY_HOSTNAME now defaults True. Hardening (V13.1.3, V4.1.4, V13.1.2): - Rate-limit change-password (5/min), enroll-bundle (10/min), webhook-create (20/min), host-delete (20/min) via the existing slowapi limiter. - Correct false 'global auth middleware' comment; document enroll-bundle proxy trust. Correctness (BUG-7..11): - BUG-7 unbound bus in finally; BUG-8 apply_ceiling clamps to min(base,ceiling); BUG-9 commit before emit; BUG-10 multi-actor rearm for sub-threshold identities; BUG-11 normalize naive timestamps to UTC. Already-closed (no change): V14.1.1, V2.1.2/V3.1.3, V5.1.2. Tests added for every fix; unanimous adversarial review.
This commit is contained in:
@@ -345,9 +345,18 @@ def test_expired_state_treated_as_disabled_by_is_active() -> None:
|
||||
def test_apply_ceiling_only_clamps_clipped() -> None:
|
||||
from decnet.ttp.impl._state import apply_ceiling
|
||||
|
||||
# ceiling is ignored unless state is clipped
|
||||
enabled = RuleState(state="enabled", confidence_max=0.5)
|
||||
assert apply_ceiling(0.9, enabled) == 0.9 # ceiling ignored unless clipped
|
||||
assert apply_ceiling(0.9, enabled) == 0.9
|
||||
|
||||
# clipped + base > ceiling → clamped to ceiling (not scaled)
|
||||
clipped = RuleState(state="clipped", confidence_max=0.5)
|
||||
assert apply_ceiling(0.9, clipped) == pytest.approx(0.45)
|
||||
assert apply_ceiling(0.9, clipped) == pytest.approx(0.5)
|
||||
|
||||
# clipped + base <= ceiling → base passes through unchanged
|
||||
clipped_below = RuleState(state="clipped", confidence_max=0.8)
|
||||
assert apply_ceiling(0.6, clipped_below) == pytest.approx(0.6)
|
||||
|
||||
# clipped + no ceiling declared → base passes through
|
||||
clipped_no_max = RuleState(state="clipped", confidence_max=None)
|
||||
assert apply_ceiling(0.9, clipped_no_max) == 0.9
|
||||
|
||||
Reference in New Issue
Block a user