{"record":{"id":"1ee8752e19f9ccb1","repo":"unslothai/unsloth","slug":"native-path-grant-has-an-invalid-format","errorCode":null,"errorMessage":"Native path grant has an invalid format.","messagePattern":"Native path grant has an invalid format\\.","errorType":"validation","errorClass":"NativePathLeaseError","httpStatus":400,"severity":"error","filePath":"studio/backend/utils/native_path_leases.py","lineNumber":281,"sourceCode":"        with _NATIVE_PATH_ENV_LOCK:\n            encoded = os.environ.get(LEASE_SECRET_ENV)\n            if encoded is None and _SCRUB_SAVED_SECRET is not None:\n                encoded = _SCRUB_SAVED_SECRET\n        if not encoded:\n            raise NativePathLeaseError(\"Native path grants require the managed desktop backend.\")\n        try:\n            secret = _b64decode(encoded)\n        except Exception as exc:\n            raise NativePathLeaseError(\"Native path grant secret is invalid.\") from exc\n        if len(secret) < _MIN_LEASE_SECRET_BYTES:\n            raise NativePathLeaseError(\"Native path grant secret is invalid.\")\n        _CACHED_LEASE_SECRET = secret\n        return secret\n\n\ndef _split_lease(lease: str) -> tuple[str, str]:\n    if not isinstance(lease, str):\n        raise NativePathLeaseError(\"Native path grant has an invalid format.\")\n    try:\n        lease.encode(\"ascii\")\n    except UnicodeEncodeError as exc:\n        raise NativePathLeaseError(\"Native path grant has an invalid format.\") from exc\n    parts = lease.split(\".\")\n    if len(parts) != 2 or not parts[0] or not parts[1]:\n        raise NativePathLeaseError(\"Native path grant has an invalid format.\")\n    return parts[0], parts[1]\n\n\ndef _decode_payload(payload_b64: str) -> dict[str, Any]:\n    try:\n        payload = json.loads(_b64decode(payload_b64).decode(\"utf-8\"))\n    except Exception as exc:\n        raise NativePathLeaseError(\"Native path grant payload is invalid.\") from exc\n    if not isinstance(payload, dict):\n        raise NativePathLeaseError(\"Native path grant payload is invalid.\")\n    return payload","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/utils/native_path_leases.py#L263-L299","documentation":"_split_lease() was given a lease that is not a string (e.g. a dict, bytes, or None passed as a non-falsy object like a list). The grant must be a single ASCII string of the form 'payload.signature'; anything with a different Python type is rejected before parsing.","triggerScenarios":"Passing the parsed JSON body (dict) instead of the lease field; forwarding bytes from a raw HTTP layer; a client that wraps the lease in a list/one-element array; or a truthy non-string default like 0/False coerced into an object.","commonSituations":"API handlers that accept the whole request object and pass it where the lease string belongs; JavaScript clients sending lease: [token] or lease: {token} via JSON; middleware that decodes the body to bytes before the route handler runs.","solutions":["Extract the actual string: use body['lease'] (or the request field your API defines), not the whole body object.","On the client, ensure the JSON value for the lease key is a plain string.","Add an isinstance(lease, str) assertion at the API boundary to fail with a clearer message."],"exampleFix":"# before\nverify_native_path_lease(payload, operation=\"read\")  # passed whole dict\n\n# after\nverify_native_path_lease(payload.get(\"lease\"), operation=\"read\")","handlingStrategy":"type-guard","validationCode":"def extract_lease(body):\n    lease = body.get(\"lease\") if isinstance(body, dict) else None\n    return lease if isinstance(lease, str) and lease else None","typeGuard":"def is_lease(value: object) -> bool:\n    return isinstance(value, str)","tryCatchPattern":"try:\n    grant = verify_native_path_lease(lease, operation=OP)\nexcept NativePathLeaseError as exc:\n    if \"invalid format\" in str(exc):\n        return error_response(400, \"Malformed file grant.\")\n    raise","preventionTips":["Extract the lease field explicitly from request bodies; never pass the body object.","Keep the client-side value a plain JSON string.","Add schema validation (e.g. pydantic lease: str) at the API boundary."],"tags":["type-error","api-contract","validation"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}