sec

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package sec provides security utilities for safe file path handling and directory traversal prevention.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filename

func Filename(root string, elem ...string) (string, error)

Filename joins a root directory with one or more path elements and ensures the resulting path is safely within the root.

Example
package main

import (
	"fmt"

	"github.com/foomo/go/sec"
)

func main() {
	path, err := sec.Filename("/tmp", "a", "b", "file.txt")
	if err != nil {
		fmt.Println("error:", err)
		return
	}

	fmt.Println(path)

}
Output:
/tmp/a/b/file.txt
Example (Traversal)
package main

import (
	"fmt"

	"github.com/foomo/go/sec"
)

func main() {
	_, err := sec.Filename("/tmp", "../etc/passwd")
	fmt.Println(err)

}
Output:
path traversal attempt

Types

This section is empty.

Jump to

Keyboard shortcuts

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