Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Default maximum file size (100MB) DefaultMaxFileSize int64 = 100 * 1024 * 1024 // Allowed file formats AllowedFileFormats = map[string]bool{ ".jpg": true, ".jpeg": true, ".png": true, ".gif": true, ".webp": true, ".bmp": true, ".tiff": true, ".svg": true, ".heic": true, ".heif": true, ".avif": true, ".pdf": true, ".doc": true, ".docx": true, ".xls": true, ".xlsx": true, ".ppt": true, ".pptx": true, ".csv": true, ".zip": true, ".sql": true, ".wav": true, ".mp3": true, ".mp4": true, ".mov": true, ".3gp": true, ".avi": true, } // Allowed MIME types AllowedMimeTypes = map[string]bool{ "image/jpeg": true, "image/jpg": true, "image/pjpeg": true, "image/png": true, "image/x-png": true, "image/gif": true, "image/webp": true, "image/bmp": true, "image/x-ms-bmp": true, "image/tiff": true, "image/svg+xml": true, "image/heic": true, "image/heif": true, "image/avif": true, "application/octet-stream": true, "application/pdf": true, "application/msword": true, "application/vnd.openxmlformats-officedocument.wordprocessingml.document": true, "application/vnd.ms-excel": true, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": true, "application/vnd.ms-powerpoint": true, "application/vnd.openxmlformats-officedocument.presentationml.presentation": true, "text/plain": true, "application/sql": true, "text/csv": true, "application/csv": true, "application/zip": true, "application/x-zip-compressed": true, "audio/wav": true, "audio/wave": true, "audio/mpeg": true, "audio/mp3": true, "video/mp4": true, "video/quicktime": true, "video/3gpp": true, "video/x-msvideo": true, } )
Functions ¶
func NewSafeHTTPClient ¶ added in v1.7.0
NewSafeHTTPClient returns an http.Client that rejects connections to disallowed IP ranges at dial time (no DNS TOCTOU window) and bounds redirects to 3 hops, re-validating the scheme on each. When UPLOAD_URL_ALLOW_PRIVATE is set, the IP check is skipped.
func ValidateFile ¶
func ValidateFile(file *multipart.FileHeader) error
ValidateFile performs file validation
func ValidateFileContent ¶
ValidateFileContent validates file content
func ValidateStruct ¶
ValidateStruct validates a struct using validator tags
func ValidateUploadURL ¶ added in v1.7.0
ValidateUploadURL enforces scheme and, for literal-IP hosts, IP-range policy before any network request is made. Hostname-based targets are additionally re-checked at connect time by NewSafeHTTPClient's dialer (defeats DNS rebinding), so this function only rejects the statically-detectable cases.
Types ¶
type FileValidationError ¶
FileValidationError custom error type
func (*FileValidationError) Error ¶
func (e *FileValidationError) Error() string