langflow-ai/langflow · error · HTTPException

Invalid path: {e}

Error message

Invalid path: {e}

What it means

HTTP 400: os.path.realpath() raised OSError/ValueError while canonicalising the CANDIDATE path (the client fs_path, or base_dir + relative part). Unlike the base-dir failure this one is usually caused by the submitted path itself being unresolvable on this host.

Source

Thrown at src/backend/base/langflow/api/v1/flows_helpers.py:96

    try:
        base_dir_resolved = os.path.realpath(str(base_dir))
    except (OSError, ValueError) as e:
        raise HTTPException(status_code=400, detail=f"Invalid base directory: {e}") from e

    # Determine if path is absolute (Unix or Windows style)
    is_absolute = normalized_path.startswith("/") or (len(normalized_path) > 1 and normalized_path[1] == ":")

    if is_absolute:
        candidate = normalized_path
    else:
        relative_part = normalized_path.lstrip("/")
        # os.path.join is deliberate here (PTH118) to match CodeQL's sanitiser model.
        candidate = os.path.join(base_dir_resolved, relative_part) if relative_part else base_dir_resolved  # noqa: PTH118

    try:
        resolved_str = os.path.realpath(candidate)
    except (OSError, ValueError) as e:
        raise HTTPException(status_code=400, detail=f"Invalid path: {e}") from e

    # SECURITY: containment check using os.path.realpath + startswith (CodeQL-recognised).
    if resolved_str != base_dir_resolved and not resolved_str.startswith(base_dir_resolved + os.sep):
        if is_absolute:
            raise HTTPException(
                status_code=400,
                detail="Absolute path must be within your flows directory",
            )
        raise HTTPException(
            status_code=400,
            detail="Invalid path: resolves outside allowed directory",
        )

    # Return the canonicalised path — safe for subsequent filesystem operations.
    return Path(resolved_str)


# Fields that may be updated via setattr on a Flow ORM instance.

View on GitHub (pinned to 976ec789d2)

Solutions

  1. Shorten/flatten fs_path to a simple filename under the user's flows dir (e.g. "my_flow.json").
  2. Inspect the exact fs_path bytes sent (hex dump) for stray control characters and fix client encoding.
  3. On the server, check permissions on <data_dir>/flows/<user_id> and any symlinked parents.
  4. Enable Windows long-path support if path length is the cause.

Example fix

# before
{"fs_path": "projects/2026/very/deeply/nested/.../flow.json"}  # >260 chars on Windows
# after
{"fs_path": "flow-2026.json"}
Defensive patterns

Strategy: validation

Validate before calling

if (fsPath.length > 200) throw new Error('fs_path too long; use a flat filename');

Type guard

const isSafeLength = (p: string) => p.length <= 200 && !/[\x00-\x1f]/.test(p);

Prevention

When it happens

Trigger: fs_path containing embedded NULs that survived earlier checks, a path component that triggers OSError during realpath (permission denied walking a symlinked parent, path too long on Windows), or a ValueError from an ill-formed path string.

Common situations: Long nested fs_path values on Windows deployments; fs_path pointing through a symlink the backend user lacks permission to read; a client URL-decoding the payload incorrectly and injecting control characters.

Related errors


AI-assisted analysis of langflow-ai/langflow@976ec789d2 (2026-08-14). Data as JSON: /api/errors/c63ecdacfa3f699a. Report an issue: GitHub.