{"record":{"id":"c61d26743143e5d3","repo":"unslothai/unsloth","slug":"native-path-contains-invalid-characters","errorCode":null,"errorMessage":"Native path contains invalid characters.","messagePattern":"Native path contains invalid characters\\.","errorType":"exception","errorClass":"NativePathLeaseError","httpStatus":400,"severity":"error","filePath":"studio/backend/utils/native_path_leases.py","lineNumber":415,"sourceCode":"\n\ndef _reject_network_or_device_path(path: Path) -> None:\n    text = str(path)\n    if os.name == \"nt\":\n        normalized = text.replace(\"/\", \"\\\\\").lower()\n        if normalized.startswith(\"\\\\\\\\?\\\\\"):\n            rest = normalized[4:]\n            is_local_drive = len(rest) >= 3 and rest[0].isalpha() and rest[1:3] == \":\\\\\"\n            if not is_local_drive:\n                raise NativePathLeaseError(\"Network paths are not supported for native grants.\")\n        elif normalized.startswith(\"\\\\\\\\\"):\n            raise NativePathLeaseError(\"Network paths are not supported for native grants.\")\n    if os.name != \"nt\":\n        for root in (\"/dev\", \"/proc\", \"/sys\"):\n            if path.is_relative_to(root):\n                raise NativePathLeaseError(\"Device and virtual filesystem paths are not supported.\")\n    if \"\\x00\" in text:\n        raise NativePathLeaseError(\"Native path contains invalid characters.\")\n\n\ndef _b64decode(value: str) -> bytes:\n    try:\n        padding = \"=\" * (-len(value) % 4)\n        return base64.urlsafe_b64decode((value + padding).encode(\"ascii\"))\n    except (UnicodeEncodeError, binascii.Error, ValueError) as exc:\n        raise NativePathLeaseError(\"Native path grant has an invalid format.\") from exc\n\n\ndef _same_native_path(resolved: Path, signed: Path) -> bool:\n    try:\n        return resolved.samefile(signed)\n    except OSError:\n        return os.path.normcase(str(resolved)) == os.path.normcase(str(signed))\n\n\ndef _optional_int(value: Any) -> int | None:","sourceCodeStart":397,"sourceCodeEnd":433,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/utils/native_path_leases.py#L397-L433","documentation":"The path string contains a NUL byte (\\x00), which cannot be a valid filesystem path on any supported OS (paths are NUL-terminated in C APIs). _reject_network_or_device_path() rejects it as invalid input before any stat is attempted. It exists to stop malformed or injection-style payloads early.","triggerScenarios":"verify_native_path_lease() where str(path) contains \\x00: signer embedded raw bytes into canonical_path; a test payload built from bytes buffers; corruption of the grant string or JSON payload with control characters.","commonSituations":"Rust signer writing non-UTF8 or fixed-width buffers into the path field; truncation/concat bugs producing embedded NULs; fuzzers feeding arbitrary bytes into path construction; JSON payloads built via string concatenation instead of a JSON serializer.","solutions":["Decode the payload and locate the NUL in canonical_path to confirm the source.","Fix the signer to validate canonical_path as clean UTF-8 with no control bytes before signing.","Regenerate the grant; the signed payload cannot be edited.","Add round-trip tests that assert the built path equals os.path-normalized expected value."],"exampleFix":"// before (Rust)\nlet p = String::from_utf8_lossy(&buf); // buf may contain trailing \\0\n\n// after\nlet p = String::from_utf8(buf)?.trim_end_matches('\\0').to_string();\nassert!(Path::new(&p).is_absolute() && !p.contains('\\0'));","handlingStrategy":"type-guard","validationCode":"def path_has_no_nul(path: str) -> bool:\n    return '\\x00' not in path","typeGuard":"def is_clean_path_string(value: object) -> bool:\n    return isinstance(value, str) and '\\x00' not in value and value == value.strip('\\x00')","tryCatchPattern":"try:\n    grant = verify_native_path_lease(lease, operation='read')\nexcept NativePathLeaseError as exc:\n    if 'invalid characters' in str(exc):\n        return respond(400, 'Corrupt grant; re-select the file to mint a fresh one.')\n    raise","preventionTips":["Validate paths as clean UTF-8 with no control characters at signing time.","Never build paths from raw byte buffers without trimming embedded NULs.","Add signer unit tests asserting canonical_path contains no NUL bytes."],"tags":["native-path-lease","injection","validation","path"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}