safeoutput

package
v5.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package safeoutput writes generated and scaffolded files through an os.Root-confined, atomic rename so that a symlink in the destination path cannot redirect a write to an unrelated victim file outside its intended directory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteFileAtomic

func WriteFileAtomic(path string, data []byte, perm fs.FileMode) (err error)

WriteFileAtomic writes data to path, creating missing parent directories with mode 0o700. It refuses a symlinked parent component that resolves outside the nearest real ancestor directory of path, and replaces rather than follows a symlink at the final component. The file is written to a temporary file in the destination directory and renamed into place.

func WriteFileWithin

func WriteFileWithin(root, relPath string, data []byte, perm fs.FileMode) (err error)

WriteFileWithin writes data to relPath beneath root, creating missing parent directories with mode 0o750. relPath must be relative and must not escape root. Parent components are resolved with root confinement: a symlinked parent that resolves outside root is refused, while a symlink that stays within root is followed. A symlink at the final component is replaced rather than followed. The file is written to a temporary file in the destination directory and renamed into place.

root must already exist and is treated as the containment anchor; callers that must also reject a symlinked root should check that beforehand.

Types

This section is empty.

Jump to

Keyboard shortcuts

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