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 ¶
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.
Click to show internal directories.
Click to hide internal directories.