Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

3.0 KB
Raw Blame
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0

"""trust_remote_code boundary: trusted_org gates auto-enable; remote_code_scan lists what would run;
explicit consent required before retrying with it enabled; detection reads raw config."""

from utils.security.consent import (  # noqa: F401
    RemoteCodeDecision,
    evaluate_remote_code_consent,
    evaluate_remote_code_consent_for_targets,
)
from utils.security.file_security import (  # noqa: F401
    FileSecurityDecision,
    evaluate_file_security,
    load_scan_target,
    security_load_subdirs,
)
from utils.security.remote_code_scan import (  # noqa: F401
    CRITICAL,
    HIGH,
    MEDIUM,
    Finding,
    RemoteCodeUnscannable,
    ScanResult,
    remote_code_config_paths,
    remote_code_fingerprint,
    repo_remote_code_files,
    scan_remote_code_files,
)
from utils.security.trusted_org import is_trusted_org_repo  # noqa: F401

__all__ = [
    "is_trusted_org_repo",
    "scan_remote_code_files",
    "repo_remote_code_files",
    "RemoteCodeUnscannable",
    "remote_code_fingerprint",
    "remote_code_config_paths",
    "should_block_remote_code",
    "evaluate_remote_code_consent",
    "evaluate_remote_code_consent_for_targets",
    "preflight_remote_code_consent",
    "preflight_remote_code_consent_for_targets",
    "evaluate_file_security",
    "load_scan_target",
    "security_load_subdirs",
    "FileSecurityDecision",
    "RemoteCodeDecision",
    "ScanResult",
    "Finding",
    "CRITICAL",
    "HIGH",
    "MEDIUM",
]


def preflight_remote_code_consent(
    model_name: str,
    hf_token = None,
    *,
    trust_remote_code: bool = True,
    approved_fingerprint = None,
    trusted_org = None,
    subject = None,
) -> "RemoteCodeDecision":
    """Consent preflight for the dialog; defaults trust_remote_code to True so the scan runs."""
    return evaluate_remote_code_consent(
        model_name,
        hf_token,
        trust_remote_code = trust_remote_code,
        approved_fingerprint = approved_fingerprint,
        trusted_org = trusted_org,
        subject = subject,
    )


def preflight_remote_code_consent_for_targets(
    targets,
    hf_token = None,
    *,
    trust_remote_code: bool = True,
    approved_fingerprint = None,
    subject = None,
    load_subdirs_by_target = None,
) -> "RemoteCodeDecision":
    """Scans all targets (adapter plus base) as one unit under a single pinning fingerprint."""
    return evaluate_remote_code_consent_for_targets(
        targets,
        hf_token,
        trust_remote_code = trust_remote_code,
        approved_fingerprint = approved_fingerprint,
        subject = subject,
        load_subdirs_by_target = load_subdirs_by_target,
    )


def should_block_remote_code(result: "ScanResult") -> bool:
    """Recommends blocking by default on CRITICAL or HIGH findings; advisory only, as the caller
    still surfaces findings and takes explicit consent."""
    sev = result.max_severity
    return sev in (CRITICAL, HIGH)