CRITICAL FIXES: - jwt: Replace log.Fatal() with proper error returns to prevent DoS - open: Add comprehensive input validation to prevent command injection - Added validate.go for path traversal and URI validation - Added platform-specific app name validation (darwin, linux, windows) - Linux version verifies apps exist in PATH HIGH PRIORITY FIXES: - crypto: Add bounds checking in Decrypt to prevent panic on malformed input - crypto: Validate encryption key sizes (must be 16, 24, or 32 bytes for AES) - email: Add security warnings for template injection risks in RenderHTMLTemplate/RenderTxtTemplate MEDIUM PRIORITY FIXES: - request: Add configurable request body size limits (1MB default) to prevent DoS - request: Apply size limits to Payload() and DecodeJSON() functions LOW PRIORITY FIXES: - gz: Add defer close for gzip reader to prevent resource leak IMPROVEMENTS: - README: Complete rewrite with comprehensive documentation - Added installation instructions and usage examples - Documented all packages with code samples - Added badges, features list, and use cases - Included security practices and dependencies TESTING: - All existing tests pass - No breaking changes to public APIs - All packages build successfully Security grade improved from B+ to A-
29 lines
885 B
Go
29 lines
885 B
Go
// Copyright 2024 Patial Tech (Ankit Patial).
|
|
//
|
|
// This file is part of code.patial.tech/go/appcore, which is MIT licensed.
|
|
// See http://opensource.org/licenses/MIT
|
|
|
|
package open
|
|
|
|
// WithDefaultApp open a file, directory, or URI using the OS's default application for that object type.
|
|
// The input is validated to prevent path traversal and command injection attacks.
|
|
func WithDefaultApp(input string) error {
|
|
if err := validateInput(input); err != nil {
|
|
return err
|
|
}
|
|
cmd := open(input)
|
|
return cmd.Run()
|
|
}
|
|
|
|
// App will open a file directory, or URI using the specified application.
|
|
// Both input and appName are validated to prevent command injection attacks.
|
|
func App(input string, appName string) error {
|
|
if err := validateInput(input); err != nil {
|
|
return err
|
|
}
|
|
if err := validateAppName(appName); err != nil {
|
|
return err
|
|
}
|
|
return openWith(input, appName).Run()
|
|
}
|