Documentation
¶
Overview ¶
Package safeinput provides context-aware input sanitization for Go applications. It addresses MITRE CWE Top 25 injection vulnerabilities including:
- CWE-79: Cross-site Scripting (XSS)
- CWE-89: SQL Injection
- CWE-22: Path Traversal
- CWE-78: OS Command Injection
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func SanitizeShellArg ¶
SanitizeShellArg sanitizes shell command arguments (CWE-78). Only allows alphanumeric characters, dash, underscore, period, and forward slash.
func StripNullBytes ¶
StripNullBytes removes null bytes from a string.
Types ¶
type Config ¶
type Config struct {
MaxInputLength int
AllowedHTMLTags []string
BasePath string
StrictMode bool
StripNullBytes bool
}
Config holds sanitizer configuration options.
type Context ¶
type Context int
Context defines the output context for sanitization.
const ( // HTMLBody sanitizes for HTML body content (CWE-79). HTMLBody Context = iota // HTMLAttribute sanitizes for HTML attribute values (CWE-79). HTMLAttribute // SQLIdentifier sanitizes SQL identifiers (CWE-89). SQLIdentifier // SQLValue validates values before queries (CWE-89). SQLValue // FilePath sanitizes filesystem paths (CWE-22). FilePath // URLPath sanitizes URL path components. URLPath // URLQuery sanitizes URL query parameters. URLQuery // ShellArg sanitizes shell command arguments (CWE-78). ShellArg )
type Sanitizer ¶
type Sanitizer struct {
// contains filtered or unexported fields
}
Sanitizer provides the main sanitization interface.
func (*Sanitizer) MustSanitize ¶
MustSanitize panics on error.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
safeinput
command
Command safeinput provides a CLI for input sanitization.
|
Command safeinput provides a CLI for input sanitization. |
|
Package html provides XSS prevention (CWE-79) using pure Go.
|
Package html provides XSS prevention (CWE-79) using pure Go. |
|
Package path provides path traversal prevention (CWE-22).
|
Package path provides path traversal prevention (CWE-22). |
|
Package sql provides SQL injection prevention (CWE-89).
|
Package sql provides SQL injection prevention (CWE-89). |
Click to show internal directories.
Click to hide internal directories.