validation

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package validation provides validation utilities for config files and other inputs.

Index

Constants

This section is empty.

Variables

View Source
var IsSecurePath = func(path string) error {
	clean := filepath.Clean(path)
	parts := strings.Split(clean, string(os.PathSeparator))
	for _, part := range parts {
		if part == ".." {
			return fmt.Errorf("path contains '..', which is not allowed")
		}
	}
	return nil
}

IsSecurePath checks if a given file path is secure and does not contain any path traversal sequences ("../" or "..\\"). This function is crucial for preventing directory traversal attacks, where a malicious actor could otherwise access or manipulate files outside of the intended directory.

path is the file path to be validated. It returns an error if the path is found to be insecure, and nil otherwise. IsSecurePath checks if a given file path is secure. It is a variable to allow mocking in tests.

Functions

func FileExists

func FileExists(path string) error

FileExists checks if a file exists at the given path.

func IsValidBindAddress

func IsValidBindAddress(s string) error

IsValidBindAddress checks if a given string is a valid bind address. A valid bind address is in the format "host:port".

func IsValidURL

func IsValidURL(s string) bool

IsValidURL checks if a given string is a valid URL. This function performs several checks, including for length, whitespace, the presence of a scheme, and host, considering special cases for schemes like "unix" or "mailto" that do not require a host.

s is the string to be validated. It returns true if the string is a valid URL, and false otherwise.

func ValidateHTTPServiceDefinition

func ValidateHTTPServiceDefinition(def *configv1.HttpCallDefinition) error

ValidateHTTPServiceDefinition checks the validity of an HttpCallDefinition. It ensures that the endpoint path is specified and correctly formatted, and that a valid HTTP method is set.

def is the HttpCallDefinition to be validated. It returns an error if the definition is invalid, and nil otherwise.

Types

This section is empty.

Jump to

Keyboard shortcuts

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