{"record":{"id":"678b6235a0eebe94","repo":"unslothai/unsloth","slug":"native-path-grant-operation-is-invalid","errorCode":null,"errorMessage":"Native path grant operation is invalid.","messagePattern":"Native path grant operation is invalid\\.","errorType":"validation","errorClass":"NativePathLeaseError","httpStatus":400,"severity":"error","filePath":"studio/backend/utils/native_path_leases.py","lineNumber":323,"sourceCode":"    required = (\n        \"version\",\n        \"operation\",\n        \"canonical_path\",\n        \"path_kind\",\n        \"path_type\",\n        \"source_kind\",\n        \"token_id_hash\",\n        \"issued_at_ms\",\n        \"expires_at_ms\",\n        \"nonce\",\n    )\n    missing = [key for key in required if key not in payload]\n    if missing:\n        raise NativePathLeaseError(\"Native path grant payload is missing required fields.\")\n    if _required_int(payload, \"version\") != 1:\n        raise NativePathLeaseError(\"Native path grant version is unsupported.\")\n    if payload[\"operation\"] != operation:\n        raise NativePathLeaseError(\"Native path grant operation is invalid.\")\n    if expected_kind and payload[\"path_kind\"] != expected_kind:\n        raise NativePathLeaseError(\"Native path grant kind is invalid.\")\n    now_ms = int(time.time() * 1000)\n    issued_at_ms = _required_int(payload, \"issued_at_ms\")\n    expires_at_ms = _required_int(payload, \"expires_at_ms\")\n    if issued_at_ms >= expires_at_ms:\n        raise NativePathLeaseError(\"Native path grant timestamps are inconsistent.\")\n    if expires_at_ms <= now_ms:\n        raise NativePathLeaseError(\"Native path grant has expired.\")\n    if issued_at_ms > now_ms + 30_000:\n        raise NativePathLeaseError(\"Native path grant issue time is invalid.\")\n    for key in (\"canonical_path\", \"nonce\", \"token_id_hash\", \"display_label\"):\n        raw = payload.get(key)\n        if raw is None:\n            continue\n        if \"\\x00\" in str(raw):\n            raise NativePathLeaseError(\"Native path grant contains invalid characters.\")\n","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/utils/native_path_leases.py#L305-L341","documentation":"The grant's embedded operation string does not match the operation keyword passed to verify_native_path_lease(). Grants are single-purpose: a grant signed for 'import_gguf' cannot be replayed against an endpoint that verifies with operation='export_model', preventing cross-endpoint grant reuse.","triggerScenarios":"Frontend reuses a lease from one flow (e.g. a file import dialog) when calling a different endpoint (e.g. export or a data-recipe upload); shared lease state across features; or a backend call site passing the wrong operation string for the endpoint's semantics.","commonSituations":"Refactors that rename operation identifiers on one side only; copy-pasted API wrappers sending the import lease to the export endpoint; generic 'attach file' UI funneling all leases through one handler.","solutions":["Request a fresh grant from the picker flow that corresponds to the target operation, and send that lease to that endpoint.","Keep operation strings as shared constants (single source of truth) used by both the Rust signer invocation and the backend verifier.","Namespace per-flow lease storage in the frontend so grants can't cross wires.","When adding endpoints, double-check the operation literal matches what the shell signed for that dialog."],"exampleFix":"# before\nlease = await pick_file_for_import()\nverify_native_path_lease(lease, operation=\"export_model\")  # wrong purpose\n\n# after\nlease = await pick_file_for_export()\nverify_native_path_lease(lease, operation=\"export_model\")","handlingStrategy":"validation","validationCode":"# Frontend: bind each lease to the operation it was picked for\nif stored_lease.operation !== ENDPOINT_OPERATION: throw new Error('grant purpose mismatch');","typeGuard":null,"tryCatchPattern":"try:\n    grant = verify_native_path_lease(lease, operation=OP)\nexcept NativePathLeaseError as exc:\n    if \"operation is invalid\" in str(exc):\n        return error_response(400, \"This file selection cannot be used for that action.\")\n    raise","preventionTips":["Define operation identifiers as constants shared by signer and verifier.","Store leases keyed by operation in the frontend.","Always request a fresh grant when switching actions on the same file."],"tags":["authorization","operation-mismatch","api-contract","replay-protection"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}