Skip to content

🔒 Security: Path Traversal Risk in Image Downloads #23

@dannycab

Description

@dannycab

Security Issue

Image paths not validated before saving - potential path traversal vulnerability.

Vulnerable Code

scraper.py:178 - Path(output_path).parent.mkdir(parents=True, exist_ok=True)

Risk Level

Medium - Malicious wiki content could write files outside output directory

Example Attack

{{../../etc/passwd.png}}

Could write to parent directories

Solution

def safe_path(base_dir: Path, filename: str) -> Path:
    # Normalize and resolve path
    full_path = (base_dir / filename).resolve()
    
    # Ensure it's within base_dir
    if not full_path.is_relative_to(base_dir):
        raise SecurityError('Path traversal attempt detected')
    
    return full_path

Tasks

  • Add path validation function
  • Sanitize image filenames
  • Add allowlist for file extensions
  • Add tests for path traversal attempts
  • Audit all file write operations

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/criticalCritical - Must be fixed immediatelytype/securitySecurity-related changes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions