diff --git a/.github/workflows/wininspect-error-redaction.yml b/.github/workflows/wininspect-error-redaction.yml new file mode 100644 index 00000000..394178c3 --- /dev/null +++ b/.github/workflows/wininspect-error-redaction.yml @@ -0,0 +1,25 @@ +name: WinInspect RPC Identity-Redaction Regression +on: + pull_request: + paths: + - 'api/core/wininspect.py' + - 'tests/test_wininspect_error_redaction.py' + - 'scripts/ci/test.sh' + - '.github/workflows/wininspect-error-redaction.yml' +permissions: + contents: read +jobs: + strict-correlation-no-identity: + runs-on: ubuntu-24.04 + timeout-minutes: 5 + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd + with: + persist-credentials: false + - name: Install pinned public-only test runner + run: python3 -m pip install --disable-pip-version-check -r requirements/requirements-rel.txt pytest==8.4.2 + - name: Execute synthetic strict-correlation negative tests + run: | + set -euo pipefail + python3 -m pytest -q tests/test_wininspect_error_redaction.py + python3 -m py_compile api/core/wininspect.py diff --git a/api/core/wininspect.py b/api/core/wininspect.py index 0bc039d9..c8e8c649 100644 --- a/api/core/wininspect.py +++ b/api/core/wininspect.py @@ -287,9 +287,8 @@ def request(method: str, params: dict[str, Any] | None = None) -> dict[str, Any] response = _read_frame(sock) if response.get("id") != request_id: - raise WinInspectError( - f"unexpected WinInspect response id: {response.get('id')!r}; hello={hello!r}" - ) + # Never expose untrusted daemon hello identity in API-visible errors. + raise WinInspectError("WinInspect response correlation failed") if not response.get("ok"): error = response.get("error") or {} raise WinInspectError(str(error.get("message") or error or "WinInspect request failed")) diff --git a/scripts/ci/test.sh b/scripts/ci/test.sh index 8ca4ff8c..f0253ca2 100755 --- a/scripts/ci/test.sh +++ b/scripts/ci/test.sh @@ -25,4 +25,5 @@ pytest \ tests/test_ui_accessibility.py \ tests/test_visual_profile_cli.py \ tests/test_ci_trust_pack_provenance.py \ - tests/test_ci_public_conformance_summary.py + tests/test_ci_public_conformance_summary.py \ + tests/test_wininspect_error_redaction.py diff --git a/tests/test_wininspect_error_redaction.py b/tests/test_wininspect_error_redaction.py new file mode 100644 index 00000000..76649b55 --- /dev/null +++ b/tests/test_wininspect_error_redaction.py @@ -0,0 +1,59 @@ +"""WinInspect correlation diagnostics must not disclose daemon hello identity.""" + +import json +import struct +from unittest.mock import patch + +import pytest + +from api.core import wininspect as wi + + +class Socket: + def __init__(self, response): + hello = { + "type": "hello", "version": "0.3.0", + "hostname": "SYNTHETIC_HOST_NEVER_ECHO", + "name": "SYNTHETIC_PERSON_NEVER_ECHO", + "uuid": "SYNTHETIC_UUID_NEVER_ECHO", + } + self.incoming = bytearray() + for item in (hello, response): + raw = json.dumps(item).encode() + self.incoming.extend(struct.pack("!I", len(raw)) + raw) + + def recv(self, size): + value = bytes(self.incoming[:size]) + del self.incoming[:size] + return value + + def settimeout(self, timeout): + pass + + def sendall(self, value): + pass + + def __enter__(self): + return self + + def __exit__(self, *args): + return False + + +@pytest.mark.parametrize("bad_reply", [ + {"ok": True, "result": {"capabilities": {}}, "id": ""}, + {"ok": True, "result": {}, "id": "different-request"}, + {"ok": False, "error": {"message": "should not bypass ID check"}}, +]) +def test_mismatched_correlation_refuses_without_hello_disclosure(bad_reply): + sock = Socket(bad_reply) + with ( + patch.object(wi, "ensure_daemon", return_value={"running": True}), + patch.object(wi.socket, "create_connection", return_value=sock), + ): + with pytest.raises(wi.WinInspectError) as error: + wi.request("daemon.capabilities") + assert str(error.value) == "WinInspect response correlation failed" + for token in ("SYNTHETIC_HOST", "SYNTHETIC_PERSON", "SYNTHETIC_UUID", + "different-request"): + assert token not in str(error.value)