files

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package files exposes shared filesystem helpers. The Code tab HTTP handlers (server/handlers/code.go) resolve every user-supplied path through SafeJoin so traversal attempts (../, absolute paths, NUL bytes, escaping symlinks) cannot read files outside of the workspace or worktree root.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPath = errors.New("invalid path")

ErrInvalidPath is returned when the user-supplied path contains characters that are never acceptable (currently: NUL bytes).

View Source
var ErrPathEscape = errors.New("path escapes root")

ErrPathEscape is returned when a user-supplied path attempts to escape the provided root (via .., absolute path, or a symlink pointing outside).

Functions

func SafeJoin

func SafeJoin(root, userPath string) (string, error)

SafeJoin joins userPath onto root and returns the absolute, cleaned filesystem path.

It guarantees that the returned path lives inside root. SafeJoin rejects:

  • absolute userPaths (userPath must be relative)
  • paths containing NUL bytes
  • paths that, after cleaning, escape root via "../" segments
  • paths whose symlink target (or any ancestor's symlink target) escapes root

Root must be an absolute, existing directory; if root itself does not exist SafeJoin still returns an answer (no symlink check can run) but callers typically os.Stat the result immediately and handle ENOENT.

SafeJoin accepts an empty userPath (returns root).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL