mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-05-26 05:53:33 +00:00
Fix 15 remaining CodeQL path-injection and stack-trace-exposure alerts
Switch from resolve()+relative_to() to os.path.basename() reassignment, which CodeQL recognizes as a path sanitizer that breaks the taint chain. Also remove exception objects from backup_manager validate_backup return strings to eliminate the stack-trace-exposure taint source. Fixes alerts #227, #233, #234, #235, #237, #238, #239, #240, #241, #242, #243, #244, #245, #246, #247. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6939,6 +6939,8 @@ _BACKUP_EXPORT_DIR = PROJECT_ROOT / "config" / "backups" / "exports"
|
||||
def _safe_backup_path(filename: str) -> Path:
|
||||
"""Resolve a filename to an absolute path inside the export dir,
|
||||
rejecting any traversal attempts. Returns None if unsafe."""
|
||||
# Use basename first (CodeQL-recognized sanitizer) then validate format
|
||||
filename = os.path.basename(filename or '')
|
||||
if not filename or not re.match(r'^[a-zA-Z0-9][a-zA-Z0-9._-]{0,200}\.zip$', filename):
|
||||
return None
|
||||
path = (_BACKUP_EXPORT_DIR / filename).resolve()
|
||||
|
||||
Reference in New Issue
Block a user