|
Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
|
Validates file paths to prevent security vulnerabilities. More...
#include <path_validator.h>

Public Member Functions | |
| path_validator (std::filesystem::path allowed_base) | |
| Construct with allowed base directory. | |
| common::VoidResult | validate (const std::filesystem::path &path, bool allow_symlinks=false, bool strict_filename=true) const |
| Validate a file path. | |
| const std::filesystem::path & | allowed_base () const |
| Get the allowed base directory. | |
Static Public Member Functions | |
| static bool | is_safe_filename (const std::string &name) |
| Check if a filename is safe (contains only allowed characters) | |
| static std::string | sanitize_filename (const std::string &name, char replacement='_') |
| Sanitize a filename by removing/replacing invalid characters. | |
| static result< std::filesystem::path > | safe_join (const std::filesystem::path &base, const std::filesystem::path &relative) |
| Create a safe path by joining base and relative path. | |
Private Attributes | |
| std::filesystem::path | allowed_base_ |
Validates file paths to prevent security vulnerabilities.
Security features:
Definition at line 30 of file path_validator.h.
|
inlineexplicit |
Construct with allowed base directory.
| allowed_base | All paths must be within this directory |
Definition at line 36 of file path_validator.h.
References allowed_base_.
|
inline |
Get the allowed base directory.
Definition at line 122 of file path_validator.h.
References allowed_base_.
|
inlinestatic |
Check if a filename is safe (contains only allowed characters)
| name | Filename to check |
Allowed characters:
Definition at line 137 of file path_validator.h.
Referenced by validate().

|
inlinestatic |
Create a safe path by joining base and relative path.
| base | Base directory |
| relative | Relative path to join |
Definition at line 196 of file path_validator.h.
References kcenon::logger::get_logger_error_code(), kcenon::logger::get_logger_error_message(), kcenon::logger::path_traversal_detected, and validate().

|
inlinestatic |
Sanitize a filename by removing/replacing invalid characters.
| name | Filename to sanitize |
| replacement | Character to use for invalid characters (default: '_') |
Definition at line 160 of file path_validator.h.
|
inline |
Validate a file path.
| path | Path to validate |
| allow_symlinks | Whether symbolic links are allowed (default: false) |
| strict_filename | Whether to enforce strict filename rules (default: true) |
Definition at line 60 of file path_validator.h.
References allowed_base_, kcenon::logger::invalid_filename, is_safe_filename(), kcenon::logger::make_logger_void_result(), kcenon::common::ok(), and kcenon::logger::path_traversal_detected.
Referenced by safe_join().


|
private |
Definition at line 231 of file path_validator.h.
Referenced by allowed_base(), path_validator(), and validate().