Files
tailscale/feature/taildrop/fileops.go
T
Mike Jensen 95696cbda2 feature/taildrop: prevent symlink escapes when receiving files (#22749) (#22762)
This change confines Taildrop filesystem operations to a persistent os.Root, preventing symlinks or receive-directory replacement from redirecting file access outside the intended directory. It also closes extension-owned roots during manager replacement and shutdown.

Fixes tailscale/corp#51118

Credit to Aditya @adios-404 for reporting

Change-Id: Ica39b3603221b3c7ba4460b176aae9b67eb64556

Change-Id: I37c836325eb319afd55a21a5b553175368a10783

(cherry picked from commit 6c0903552a)

Signed-off-by: Mike Jensen <[email protected]>
2026-11-30 18:58:23 -05:00

45 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
package taildrop
import (
"io"
"io/fs"
"os"
)
// FileOps abstracts over both local‐FS paths and Android SAF URIs.
type FileOps interface {
// OpenWriter creates or truncates a file named relative to the receiver's root,
// seeking to the specified offset. If the file does not exist, it is created with mode perm
// on platforms that support it.
//
// It returns an [io.WriteCloser] and the file's absolute path, or an error.
// This call may block. Callers should avoid holding locks when calling OpenWriter.
OpenWriter(name string, offset int64, perm os.FileMode) (wc io.WriteCloser, path string, err error)
// Remove deletes a file or directory relative to the receiver's root.
// It returns [io.ErrNotExist] if the file or directory does not exist.
Remove(name string) error
// Rename atomically renames oldPath to a new file named newName,
// returning the full new path or an error.
Rename(oldPath, newName string) (newPath string, err error)
// ListFiles returns just the basenames of all regular files
// in the root directory.
ListFiles() ([]string, error)
// Stat returns the FileInfo for the given name or an error.
Stat(name string) (fs.FileInfo, error)
// OpenReader opens the given basename for the given name or an error.
OpenReader(name string) (io.ReadCloser, error)
// Close releases any resources held by the receiver.
io.Closer
}
var newFileOps func(dir string) (FileOps, error)