util

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CryptoRandomBytes

func CryptoRandomBytes(length int64) ([]byte, error)

CryptoRandomBytes generates cryptographically secure random bytes

func CryptoRandomString

func CryptoRandomString(length int) (string, error)

CryptoRandomString generates a random hex string for salts

func GetIPFromContext

func GetIPFromContext(ctx context.Context) string

GetIPFromContext extracts the client IP address from the context. Returns empty string if IP cannot be determined.

func HashToken

func HashToken(token, salt string) string

HashToken returns PBKDF2 hash of token with salt Parameters match Gitea's implementation for security consistency

func IsRedirectSafe added in v0.14.0

func IsRedirectSafe(redirectURL, baseURL string) bool

IsRedirectSafe validates that a redirect URL is safe to use. It only allows: 1. Relative paths starting with "/" but not "//" 2. Absolute URLs that match the baseURL host

func SetIPContext added in v0.14.0

func SetIPContext(ctx context.Context, ip string) context.Context

SetIPContext embeds client IP into a standard context

Types

This section is empty.

Jump to

Keyboard shortcuts

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