{"record":{"id":"617aae27701efcfa","repo":"ComposioHQ/composio","slug":"refusing-to-write-label-containing-characters-re","errorCode":null,"errorMessage":"Refusing to write {label} containing characters reserved by Windows: {name!r}","messagePattern":"Refusing to write (.+?) containing characters reserved by Windows: (.+?)","errorType":"exception","errorClass":"UnsafePathComponentError","httpStatus":null,"severity":"error","filePath":"python/composio/utils/safe_path.py","lineNumber":181,"sourceCode":"        is unsafe to write.\n    \"\"\"\n    if not isinstance(name, str):\n        raise UnsafePathComponentError(\n            f\"Refusing to write a non-string {label}: {name!r}\"\n        )\n\n    raw_basename = PureWindowsPath(name).name\n    if not raw_basename or not raw_basename.strip() or set(raw_basename) == {\".\"}:\n        raise UnsafePathComponentError(\n            f\"Path traversal detected: {label} {name!r} leaves no usable \"\n            \"basename to write to.\"\n        )\n    if \"\\x00\" in raw_basename:\n        raise UnsafePathComponentError(\n            f\"Refusing to write {label} containing a NUL byte: {name!r}\"\n        )\n    if any(ord(char) < 32 or char in '<>:\"|?*' for char in raw_basename):\n        raise UnsafePathComponentError(\n            f\"Refusing to write {label} containing characters reserved by \"\n            f\"Windows: {name!r}\"\n        )\n    if raw_basename.endswith((\" \", \".\")):\n        raise UnsafePathComponentError(\n            f\"Refusing to write {label} ending in a space or dot: {name!r}\"\n        )\n\n    basename = raw_basename.strip()\n    try:\n        encoded_length = len(os.fsencode(basename))\n    except UnicodeEncodeError as e:\n        raise UnsafePathComponentError(\n            f\"Refusing to write {label} containing invalid Unicode: {name!r}\"\n        ) from e\n    if encoded_length > MAX_COMPONENT_LENGTH:\n        raise UnsafePathComponentError(\n            f\"Refusing to write {label} longer than {MAX_COMPONENT_LENGTH} bytes: \"","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/ComposioHQ/composio/blob/64b1b85502b1beeb2379e6c9e8bf1104504fa637/python/composio/utils/safe_path.py#L163-L199","documentation":"safe_basename rejects filenames containing characters Windows reserves — control characters (ord < 32) or any of <>:\"|?*. Catching these on every platform prevents files that would be unwritable or unopenable when the workspace syncs to a Windows machine.","triggerScenarios":"secure_basename_join(base, name) where name contains characters like 'report<1>.pdf', 'file|name', 'q?.txt', or embedded control chars.","commonSituations":"Filenames from Unix-only sources that never considered Windows; adversarial pipe/colon names; CSV/emoji control characters in filenames.","solutions":["Sanitize by replacing reserved characters with '-' or '_' before download","Generate your own filename and keep the original only in metadata"],"exampleFix":"# before\nsecure_basename_join(base, 'report<1>.pdf')\n# after\nimport re\nsafe = re.sub(r'[<>:\"|?*]', '_', 'report<1>.pdf')\nsecure_basename_join(base, safe)","handlingStrategy":"validation","validationCode":"import re\nRESERVED = re.compile(r'[<>:\"|?*\\x00-\\x1f]')\ndef windows_clean(v):\n    return isinstance(v, str) and not RESERVED.search(v)","typeGuard":"import re\ndef is_windows_safe_name(v: str) -> bool:\n    return not re.search(r'[<>:\"|?*\\x00-\\x1f]', v)","tryCatchPattern":"from composio.exceptions import UnsafePathComponentError\nimport re\ntry:\n    p = secure_basename_join(base, name)\nexcept UnsafePathComponentError:\n    p = secure_basename_join(base, re.sub(r'[<>:\"|?*]', '_', name))","preventionTips":["Sanitize filenames to a conservative charset (alnum, dot, dash, underscore)","Assume files will eventually land on Windows"],"tags":["windows","filename-validation","python"],"backgroundTag":"invalid-filename-characters","analyzedSha":"64b1b85502b1beeb2379e6c9e8bf1104504fa637","analyzedAt":"2026-08-28T15:39:33.623Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}