TASK-014: Add log path validation to prevent arbitrary file access
Restrict monitored log paths to a configurable allowlist of safe directories to prevent authenticated users from instructing fail2ban to monitor arbitrary files on the system, which could leak contents via fail2ban logging. Changes: - Add 'allowed_log_dirs' setting to Settings (defaults to /var/log, /config/log) - Add @field_validator to AddLogPathRequest to validate log paths at request time - Validator resolves paths to canonical form and checks against allowed prefixes - Use Path.is_relative_to() to prevent prefix bypass attacks like /var/log_evil - Add comprehensive tests for valid/invalid paths and symlink handling - Update Features.md and Backend-Development.md with security documentation Security improvements: - Blocks access to sensitive files (/etc/shadow, /etc/passwd, etc.) - Resolves symlinks before validation to prevent escape routes - Uses proper path comparison instead of string prefix matching - Configurable via BANGUI_ALLOWED_LOG_DIRS environment variable Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -212,11 +212,12 @@ A page to inspect and modify the fail2ban configuration without leaving the web
|
||||
|
||||
- Option to register additional log files that fail2ban should monitor.
|
||||
- For each new log, specify:
|
||||
- The path to the log file.
|
||||
- The path to the log file (must be within allowed directories to prevent unauthorized access to sensitive files).
|
||||
- One or more regex patterns that define what constitutes a failure.
|
||||
- The jail name and basic jail settings (ban time, retries, etc.).
|
||||
- Choose whether the file should be read from the beginning or only new lines (head vs. tail).
|
||||
- Preview matching lines from the log against the provided regex before saving, so the user can verify the pattern works.
|
||||
- **Log Path Security:** Added log paths must resolve to locations within a configured allowlist of safe directories (default: `/var/log` and `/config/log`). This prevents authenticated users from instructing fail2ban to monitor sensitive system files. Paths containing symlinks are resolved to their canonical targets before validation.
|
||||
|
||||
### Regex Tester
|
||||
|
||||
@@ -264,7 +265,7 @@ A page to inspect and modify the fail2ban configuration without leaving the web
|
||||
- Truncation notice when the total log file line count exceeds the requested tail limit.
|
||||
- Container automatically scrolls to the bottom after each data update.
|
||||
- When fail2ban is configured to log to a non-file target (STDOUT, STDERR, SYSLOG, SYSTEMD-JOURNAL), an informational banner explains that file-based log viewing is unavailable.
|
||||
- The log file path is validated against a safe prefix allowlist on the backend to prevent path-traversal reads.
|
||||
- Log file paths are validated against a configurable allowlist of safe directories on the backend to prevent unauthorized reads of sensitive system files.
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user