68 行
2.2 KiB
Python
68 行
2.2 KiB
Python
"""P5-D default-off, reject-only security-event boundary.
|
|
|
|
This plugin has no host-issued, owner-verified cross-turn capability. P5-A
|
|
projections, P5-B request handles, P5-C deny audits, P3 carriers, P4 shadow
|
|
state, events, sessions, mappings, and page payloads are not substitutes.
|
|
Accordingly, an enabled P5-D operation has exactly one outcome: deny.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import logging
|
|
from typing import Any
|
|
|
|
|
|
logger = logging.getLogger("PrivateCompanion.P5D")
|
|
|
|
CROSS_TURN_CORRELATION_OPERATION = "cross_turn_correlation"
|
|
MANUAL_RECOVERY_OPERATION = "manual_recovery"
|
|
P5D_HOST_OWNER_CAPABILITY_UNAVAILABLE = "p5d_host_owner_capability_unavailable"
|
|
|
|
P5D_OPERATION_FLAGS = {
|
|
CROSS_TURN_CORRELATION_OPERATION: "enable_p5d_cross_turn_correlation",
|
|
MANUAL_RECOVERY_OPERATION: "enable_p5d_manual_recovery",
|
|
}
|
|
|
|
|
|
def p5d_security_event_allows(host: Any, operation: str, *opaque: Any) -> bool:
|
|
"""Bypass only while disabled; never derive allow from caller objects."""
|
|
|
|
# Do not inspect, serialize, compare, store, or log caller values. They
|
|
# are the future host contract's responsibility, not local credentials.
|
|
del opaque
|
|
flag = P5D_OPERATION_FLAGS.get(operation)
|
|
if not flag:
|
|
raise ValueError("p5d_unknown_operation")
|
|
try:
|
|
enabled = bool(getattr(host, flag, False))
|
|
except Exception:
|
|
enabled = True
|
|
if not enabled:
|
|
return True
|
|
|
|
audit = {
|
|
"operation": operation,
|
|
"outcome": "denied",
|
|
"reason_code": P5D_HOST_OWNER_CAPABILITY_UNAVAILABLE,
|
|
"ref_hash": hashlib.sha256(f"p5d:{operation}".encode("utf-8")).hexdigest(),
|
|
}
|
|
try:
|
|
entries = getattr(host, "_p5d_denial_audit", None)
|
|
if not isinstance(entries, list):
|
|
entries = []
|
|
setattr(host, "_p5d_denial_audit", entries)
|
|
entries.append(audit)
|
|
del entries[:-64]
|
|
except Exception:
|
|
pass
|
|
logger.warning("[PrivateCompanion][P5-D] gate=%s", audit)
|
|
return False
|
|
|
|
|
|
__all__ = [
|
|
"CROSS_TURN_CORRELATION_OPERATION",
|
|
"MANUAL_RECOVERY_OPERATION",
|
|
"P5D_HOST_OWNER_CAPABILITY_UNAVAILABLE",
|
|
"P5D_OPERATION_FLAGS",
|
|
"p5d_security_event_allows",
|
|
]
|