safeio

package
v0.1.0-proto2c Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package safeio centralizes every variable-path file open in gapi. All operator-supplied and discovered paths funnel through here: paths are cleaned and made absolute, and the *Under variants refuse to escape their root. This is the audited chokepoint for path-traversal (CWE-22) concerns; open a file through this package, not os, whenever the path is not a literal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(path string) (*os.File, error)

Create creates or truncates the resolved path.

func Open

func Open(path string) (*os.File, error)

Open opens the resolved path for reading.

func OpenUnder

func OpenUnder(root, path string) (*os.File, error)

OpenUnder opens path for reading after confining it to root.

func ReadFile

func ReadFile(path string) ([]byte, error)

ReadFile reads the resolved path.

func ReadFileUnder

func ReadFileUnder(root, path string) ([]byte, error)

ReadFileUnder reads path after confining it to root.

func ReplaceOwnerOnly

func ReplaceOwnerOnly(path string, data []byte) error

ReplaceOwnerOnly atomically replaces path with data, and the result is readable only by its owner. Use it for key material and anything else where the mode is part of the contract.

The bytes go to a temporary file in the destination's own directory - same directory because rename is only atomic within a filesystem - which is then renamed over path. os.CreateTemp opens with O_EXCL at 0600, and umask can only clear permission bits, never add them, so the data is owner-only from the instant it exists.

Replacing rather than writing through is the load-bearing part. A create mode applies only when the file does not already exist, and a trailing chmod runs after the bytes are on disk; either way an overwrite leaves the secret at the old file's mode for the duration of the write. A replaced destination has no old mode to inherit.

func Resolve

func Resolve(path string) (string, error)

Resolve cleans path and makes it absolute against the process working directory. Empty paths are rejected.

func ResolveUnder

func ResolveUnder(root, path string) (string, error)

ResolveUnder resolves path and rejects it unless the result stays at or under root. The check is lexical: symlinks inside an operator-owned root are the operator's to manage.

Types

This section is empty.

Jump to

Keyboard shortcuts

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