unslothai/unsloth · error · NativePathLeaseError

Native path grant payload is invalid.

Error message

Native path grant payload is invalid.

What it means

The payload half of the lease could not be base64url-decoded and parsed as UTF-8 JSON — _b64decode or json.loads raised inside _decode_payload. Signature verification already passed (it covers the raw segment bytes), so this indicates a signer bug or an environment where a valid signature exists over garbage payload bytes.

Source

Thrown at studio/backend/utils/native_path_leases.py:296

def _split_lease(lease: str) -> tuple[str, str]:
    if not isinstance(lease, str):
        raise NativePathLeaseError("Native path grant has an invalid format.")
    try:
        lease.encode("ascii")
    except UnicodeEncodeError as exc:
        raise NativePathLeaseError("Native path grant has an invalid format.") from exc
    parts = lease.split(".")
    if len(parts) != 2 or not parts[0] or not parts[1]:
        raise NativePathLeaseError("Native path grant has an invalid format.")
    return parts[0], parts[1]


def _decode_payload(payload_b64: str) -> dict[str, Any]:
    try:
        payload = json.loads(_b64decode(payload_b64).decode("utf-8"))
    except Exception as exc:
        raise NativePathLeaseError("Native path grant payload is invalid.") from exc
    if not isinstance(payload, dict):
        raise NativePathLeaseError("Native path grant payload is invalid.")
    return payload


def _validate_payload(
    payload: dict[str, Any], *, operation: str, expected_kind: str | None
) -> None:
    required = (
        "version",
        "operation",
        "canonical_path",
        "path_kind",
        "path_type",
        "source_kind",
        "token_id_hash",
        "issued_at_ms",
        "expires_at_ms",

View on GitHub (pinned to 203007d190)

Solutions

  1. Use the managed Tauri shell to issue grants, or replicate its exact format: base64url(json_utf8) + '.' + base64url(hmac_sha256(payload_b64_ascii)).
  2. Check your test signer uses urlsafe encoding without embedded '+', '/', or misplaced '=' padding.
  3. Confirm both halves are encoded, not just the signature — the payload segment must also be base64url.

Example fix

# before (test signer)
payload_b64 = base64.b64encode(json.dumps(p).encode()).decode()      # standard base64

# after
payload_b64 = base64.urlsafe_b64encode(json.dumps(p).encode()).decode().rstrip('=')
lease = payload_b64 + '.' + base64.urlsafe_b64encode(sig).decode().rstrip('=')
Defensive patterns

Strategy: try-catch

Validate before calling

import base64, json

def payload_decodes(lease: str) -> bool:
    try:
        seg = lease.split(".")[0]
        json.loads(base64.urlsafe_b64decode(seg + "=" * (-len(seg) % 4)).decode("utf-8"))
        return True
    except Exception:
        return False

Try / catch

try:
    grant = verify_native_path_lease(lease, operation=OP)
except NativePathLeaseError as exc:
    if "payload is invalid" in str(exc):
        return error_response(400, "File grant payload is malformed.")
    raise

Prevention

When it happens

Trigger: A signing implementation (custom dev harness) that produces a correct HMAC over a payload segment that isn't valid base64url JSON; padding characters misplaced inside the segment; or a payload segment built with standard base64 ('+','/') instead of base64url ('-','_').

Common situations: Writing your own Rust/Python test signer rather than using the desktop shell's; version drift between an old signer that used standard base64 and the current urlsafe decoder; or hand-crafted tokens in security tests.

Related errors


AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15). Data as JSON: /api/errors/ac775900eb072f61. Report an issue: GitHub.