{"record":{"id":"e65fa2d6e80ae815","repo":"langflow-ai/langflow","slug":"invalid-base-directory-e","errorCode":null,"errorMessage":"Invalid base directory: {e}","messagePattern":"Invalid base directory: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"src/backend/base/langflow/api/v1/flows_helpers.py","lineNumber":81,"sourceCode":"\n    # Reject directory traversal and null bytes (check normalized path)\n    if \"..\" in normalized_path:\n        raise HTTPException(\n            status_code=400,\n            detail=\"Invalid fs_path: directory traversal (..) is not allowed\",\n        )\n    if \"\\x00\" in normalized_path:\n        raise HTTPException(\n            status_code=400,\n            detail=\"Invalid fs_path: null bytes are not allowed\",\n        )\n\n    # Build and canonicalise the safe base directory path.\n    base_dir = storage_service.data_dir / \"flows\" / str(user_id)\n    try:\n        base_dir_resolved = os.path.realpath(str(base_dir))\n    except (OSError, ValueError) as e:\n        raise HTTPException(status_code=400, detail=f\"Invalid base directory: {e}\") from e\n\n    # Determine if path is absolute (Unix or Windows style)\n    is_absolute = normalized_path.startswith(\"/\") or (len(normalized_path) > 1 and normalized_path[1] == \":\")\n\n    if is_absolute:\n        candidate = normalized_path\n    else:\n        relative_part = normalized_path.lstrip(\"/\")\n        # os.path.join is deliberate here (PTH118) to match CodeQL's sanitiser model.\n        candidate = os.path.join(base_dir_resolved, relative_part) if relative_part else base_dir_resolved  # noqa: PTH118\n\n    try:\n        resolved_str = os.path.realpath(candidate)\n    except (OSError, ValueError) as e:\n        raise HTTPException(status_code=400, detail=f\"Invalid path: {e}\") from e\n\n    # SECURITY: containment check using os.path.realpath + startswith (CodeQL-recognised).\n    if resolved_str != base_dir_resolved and not resolved_str.startswith(base_dir_resolved + os.sep):","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/api/v1/flows_helpers.py#L63-L99","documentation":"HTTP 400: os.path.realpath() raised OSError/ValueError while canonicalising the BASE directory (storage_service.data_dir / \"flows\" / <user_id>). This is a server-side configuration problem, not a bad client path — the user-supplied fs_path has not even been joined yet.","triggerScenarios":"The configured LANGFLOW_DATA_DIR (or the drive it lives on) is invalid on the host: extremely long path on Windows (OSError), a data_dir containing embedded NUL bytes from a mis-set env var, or a filesystem error while resolving symlinks in the base directory.","commonSituations":"LANGFLOW_DATA_DIR env var set to a bad value (trailing NUL from a script, nonexistent drive letter on Windows, path exceeding MAX_PATH without long-path support); Docker volume whose underlying mount is broken; a symlink loop in the data directory tree.","solutions":["Check the LANGFLOW_DATA_DIR (or storage service data_dir) setting on the server and fix/normalise it.","On Windows, enable long-path support (>260 chars) or shorten the data dir.","Verify the data directory and its parents resolve (readlink/realpath) with the same user the backend runs as.","Recreate the flows/<user_id> directory if it was replaced by a broken symlink."],"exampleFix":"# before\nLANGFLOW_DATA_DIR=\"/data/flows\\u0000\"  # corrupted env\n# after\nLANGFLOW_DATA_DIR=/data/flows","handlingStrategy":"validation","validationCode":"python -c \"import os; print(os.path.realpath('PATH_TO_DATA_DIR'))\"  # run as the backend user before startup","typeGuard":null,"tryCatchPattern":"try: create_flow(...) except HTTPException as e: if e.status_code == 400 and 'base directory' in e.detail: alert_ops_bad_datadir(); raise","preventionTips":["Smoke-test LANGFLOW_DATA_DIR resolution at deploy time","Avoid NUL/control chars in env vars set by scripts","Keep data dir paths short on Windows"],"tags":["configuration","filesystem","http-400","fs-path","environment"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}