Skip to main content

Safe path handling for VCollab applications

Project description

Path Utilities

Overview

Safe path handling for VCollab applications -- filename validation, file identity (POSIX-style relative paths as stable IDs), and path resolution with access validation. It gives you one place to validate untrusted names and file IDs before touching the filesystem, and a stable, platform-independent way to identify files inside a base directory. FileId.resolve_path rejects absolute paths, .. traversal, and symbolic links so a resolved ID cannot escape its base directory.

This package has zero external dependencies.


Installation

pip install vcti-path

In requirements.txt

vcti-path>=1.1.0

In pyproject.toml dependencies

dependencies = [
    "vcti-path>=1.1.0",
]

Quick Start

Validate filenames

from vcti.path import FileNameValidator

FileNameValidator.is_valid("report.pdf")     # True
FileNameValidator.is_valid("bad|name")       # False
FileNameValidator.is_valid("..")             # False

FileNameValidator.validate("data.json")      # OK
FileNameValidator.validate("bad/name")       # Raises ValueError

File IDs -- stable POSIX-style identifiers

A file ID is a POSIX-format relative path that uniquely identifies a file or directory within a base directory. No leading /, ./, or ../.

from pathlib import Path
from vcti.path import FileId

# Validate
FileId.is_valid("scripts/setup.sh")     # True
FileId.is_valid("/absolute/path")       # False
FileId.is_valid("../escape")            # False

# Resolve to filesystem path
base = Path("/project")
FileId.resolve_path("src/main.py", base)
# -> Path("/project/src/main.py")

# Extract file ID from a path
src = Path("/project/src/main.py")
FileId.get_file_id(src, base)
# -> "src/main.py"

Path resolution and access validation

from vcti.path import abs_path, validate_file_access, resolve_path

# Absolute path resolution
abs_path("relative/file.txt")
# -> Path("<cwd>/relative/file.txt")

# Validate that a file exists and is readable
validate_file_access("config.yaml")
# Raises FileNotFoundError, IsADirectoryError, or PermissionError

# Resolve relative to a base directory
resolve_path("data/input.csv", "/project")
# -> Path("/project/data/input.csv")

Public API

Symbol Type Purpose
FileNameValidator.is_valid(name) classmethod Check if a filename is valid
FileNameValidator.validate(name) classmethod Validate filename, raise ValueError if invalid
FileId.is_valid(file_id) staticmethod Check if a POSIX file ID is valid
FileId.validate(file_id) staticmethod Validate file ID, raise ValueError if invalid
FileId.resolve_path(file_id, base_dir) staticmethod Resolve file ID to absolute path
FileId.get_file_id(file_path, base_dir) staticmethod Extract file ID from absolute path
abs_path(fp) function Convert to absolute resolved Path
validate_file_access(fp) function Validate file exists and is readable
validate_folder_access(fp) function Validate directory exists
resolve_path(path, base_dir) function Resolve path relative to base directory

Documentation

If you want to… Read
Get started using the package Quick Start above
Understand the concepts and design decisions docs/design.md
Navigate and understand the source docs/source-guide.md
Look up a specific function or type docs/api.md

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vcti_path-1.1.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vcti_path-1.1.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file vcti_path-1.1.0.tar.gz.

File metadata

  • Download URL: vcti_path-1.1.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for vcti_path-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7999d2928b787a83594fa73e0f07ec53a6f5c3ec444a36af632f598d543a9084
MD5 27632aae6b551228e7617e0e7f050264
BLAKE2b-256 7fe70e10172665eb73cc9fffe02204ae3f961160bc4854c54dd1b023213a8445

See more details on using hashes here.

Provenance

The following attestation bundles were made for vcti_path-1.1.0.tar.gz:

Publisher: release.yml on vcollab/vcti-python-path

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vcti_path-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: vcti_path-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for vcti_path-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ceb9240366f8a93b6893047850f275df0fb92438e12ea6b995669e2206e55049
MD5 8dffa55ee9ffe6d1fb6bd9682c85ab1b
BLAKE2b-256 6d2dce0026ea3c7315614514c8e67a44bf3d693a8409f60e4973a77fbfdee558

See more details on using hashes here.

Provenance

The following attestation bundles were made for vcti_path-1.1.0-py3-none-any.whl:

Publisher: release.yml on vcollab/vcti-python-path

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page