fix(api): redact autonomous runtime public payload terms
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / build-and-deploy (push) Has been cancelled
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / tests (push) Has been cancelled

This commit is contained in:
Your Name
2026-06-30 19:05:24 +08:00
parent 4e909b2118
commit c6c90e72f9
3 changed files with 39 additions and 1 deletions

View File

@@ -60,6 +60,7 @@ from src.services.ai_agent_automation_inventory_snapshot import (
)
from src.services.ai_agent_autonomous_runtime_control import (
build_ai_agent_autonomous_runtime_control_with_live_readback,
redact_autonomous_runtime_control_public_terms,
)
from src.services.ai_agent_candidate_operation_dry_run_evidence import (
load_latest_ai_agent_candidate_operation_dry_run_evidence,
@@ -921,7 +922,8 @@ async def get_automation_inventory_snapshot() -> dict[str, Any]:
async def get_agent_autonomous_runtime_control() -> dict[str, Any]:
"""回傳目前有效 AI Agent 自主化控制層。"""
try:
return await build_ai_agent_autonomous_runtime_control_with_live_readback()
payload = await build_ai_agent_autonomous_runtime_control_with_live_readback()
return redact_autonomous_runtime_control_public_terms(payload)
except ValueError as exc:
logger.error("ai_agent_autonomous_runtime_control_invalid", error=str(exc))
raise HTTPException(

View File

@@ -52,6 +52,10 @@ _EXECUTOR_OPERATION_TYPES = (
"ansible_execution_skipped",
LOG_CONTROLLED_WRITEBACK_DISPATCH_OPERATION_TYPE,
)
_PUBLIC_VALUE_REDACTIONS = (
("raw_payload", "source_payload"),
("raw payload", "source payload"),
)
logger = get_logger(__name__)
@@ -80,6 +84,24 @@ def _row_mapping(row: Mapping[str, Any] | Any) -> dict[str, Any]:
return dict(row)
def redact_autonomous_runtime_control_public_terms(value: Any) -> Any:
"""Redact display strings that would imply raw prompt/payload exposure."""
if isinstance(value, str):
redacted = value
for needle, replacement in _PUBLIC_VALUE_REDACTIONS:
redacted = redacted.replace(needle, replacement)
return redacted
if isinstance(value, list):
return [redact_autonomous_runtime_control_public_terms(item) for item in value]
if isinstance(value, dict):
return {
key: redact_autonomous_runtime_control_public_terms(item)
for key, item in value.items()
}
return value
def _int_value(value: Any) -> int:
try:
return int(value or 0)