Skip to content

Commit ba1bb6b

Browse files
author
TTLequals0
committed
Version 2.0.55: Major security enhancements and comprehensive documentation
Security Enhancements: - Fixed path traversal vulnerability with comprehensive path validation - Replaced unsafe subprocess calls with validated safe_subprocess_run wrapper - Added JSON schema validation to all API endpoints - Implemented rate limiting (default: 200/day, 50/hour) - Added Flask-WTF CSRF protection - Comprehensive security audit logging Documentation: - Complete API documentation with OpenAPI 3.0 specification - Developer guide with setup and contribution instructions - Architecture overview and system design documentation - API client examples in Python, Node.js, and Bash - Integration guide with real-world examples Architecture: - Maintained modular structure from previous refactoring - Added security utilities module - Enhanced input validation throughout Dependencies: - Added Flask-Limiter 3.5.0 for rate limiting - Added Flask-WTF 1.2.1 for CSRF protection
1 parent 5b06eaf commit ba1bb6b

50 files changed

Lines changed: 9972 additions & 3653 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.dockerignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ Thumbs.db
2727
.vscode
2828
*.swp
2929
*.swo
30-
*~
30+
*~
31+
app_old.py
32+
REFACTORING_SUMMARY.md
33+
*.backup

.github/workflows/test.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ '**' ] # Run on all branches (version numbers)
6+
pull_request:
7+
branches: [ '**' ] # Run on all pull requests
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ["3.9", "3.10", "3.11"]
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
24+
- name: Install system dependencies
25+
run: |
26+
sudo apt-get update
27+
sudo apt-get install -y ffmpeg imagemagick libmagic1
28+
29+
- name: Install Python dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install -r requirements-test.txt
33+
34+
- name: Run tests with pytest
35+
run: |
36+
pytest --cov=pixelprobe --cov-report=xml --cov-report=term
37+
38+
- name: Upload coverage to Codecov
39+
uses: codecov/codecov-action@v3
40+
with:
41+
file: ./coverage.xml
42+
flags: unittests
43+
name: codecov-umbrella
44+
fail_ci_if_error: false

CHANGELOG.MD

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,62 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
## [2.0.55] - 2025-01-20
1111

12+
### Security Enhancements
13+
- **Fixed Critical Security Vulnerabilities**:
14+
- **Path Traversal Protection**: Added comprehensive path validation to prevent directory traversal attacks in file scanning endpoints
15+
- **Command Injection Prevention**: Replaced all unsafe subprocess calls with validated safe_subprocess_run wrapper
16+
- **Input Validation**: Added JSON schema validation to all API endpoints with type checking and length limits
17+
- **Rate Limiting**: Implemented rate limiting on all API endpoints (default: 200/day, 50/hour) with stricter limits on sensitive operations
18+
- **CSRF Protection**: Added Flask-WTF CSRF protection (currently exempted for API endpoints pending token-based auth)
19+
- **Audit Logging**: Added comprehensive security audit logging for all sensitive operations
20+
21+
- **New Security Module** (`pixelprobe/utils/security.py`):
22+
- `validate_file_path()`: Validates file paths against allowed directories
23+
- `validate_directory_path()`: Validates directory paths for safety
24+
- `sanitize_filename()`: Removes dangerous characters from filenames
25+
- `validate_command_args()`: Prevents command injection in subprocess calls
26+
- `safe_subprocess_run()`: Secure wrapper for subprocess execution
27+
- `AuditLogger`: Security event and action logging
28+
- `validate_json_input()`: Decorator for input validation
29+
30+
- **Updated Dependencies**:
31+
- Added Flask-Limiter==3.5.0 for rate limiting
32+
- Added Flask-WTF==1.2.1 for CSRF protection
33+
34+
### Major Architecture Overhaul
35+
- **Separation of Concerns**:
36+
- Broke down monolithic 2,500+ line app.py into modular components
37+
- Created layered architecture with clear separation between API routes, business logic, and data access
38+
39+
- **New Directory Structure**:
40+
- `api/` - Contains route modules organized by functionality:
41+
- `scan_routes.py` - Scan-related endpoints
42+
- `stats_routes.py` - Statistics endpoints
43+
- `admin_routes.py` - Admin/configuration endpoints
44+
- `export_routes.py` - Export functionality endpoints
45+
- `maintenance_routes.py` - Cleanup and file-changes operations
46+
- `services/` - Business logic layer:
47+
- `scan_service.py` - Scanning business logic
48+
- `stats_service.py` - Statistics calculations
49+
- `export_service.py` - Export functionality
50+
- `monitor_service.py` - Monitoring and alerting
51+
- `repositories/` - Data access layer:
52+
- `base_repository.py` - Base repository pattern
53+
- `scan_repository.py` - Database access for scans
54+
- `models/` - Data models:
55+
- `scan_models.py` - Scan-related models
56+
- `stats_models.py` - Statistics models
57+
- `utils/` - Shared utilities:
58+
- `validators.py` - Input validation
59+
- `decorators.py` - Common decorators
60+
61+
- **Benefits**:
62+
- Improved testability with isolated components
63+
- Clear separation of concerns following SOLID principles
64+
- Easier parallel development without conflicts
65+
- Simplified app.py focused only on initialization
66+
- Better code organization and maintainability
67+
1268
### Refactoring
1369
- **Eliminated Code Redundancy**:
1470
- Created `utils.py` module with shared utilities:

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ RUN pip install --no-cache-dir -r requirements.txt
1414

1515
COPY . .
1616

17+
# Ensure the pixelprobe package is properly installed
1718
RUN mkdir -p /app/instance
1819

20+
# Set Python path to include the app directory
21+
ENV PYTHONPATH=/app:$PYTHONPATH
22+
1923
EXPOSE 5000
2024

2125
ENV FLASK_APP=app.py

README.md

Lines changed: 156 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
<img src="static/images/pixelprobe-logo.png" alt="PixelProbe Logo" width="200" height="200">
55
</div>
66

7-
PixelProbe is a comprehensive media file corruption detection tool with a modern web interface. It helps you identify and manage corrupted video and image files across your media libraries.
7+
PixelProbe is a comprehensive media file corruption detection tool with a modern web interface. It helps you identify and manage corrupted video, image, and audio files across your media libraries.
88

9-
**Version 2.0.53** fixes file-changes scanning progress tracking with smooth per-file updates and proper async database writes.
9+
**Version 2.0.55** introduces a major architectural refactoring with modular components, comprehensive test suite, and improved maintainability while maintaining full API compatibility.
1010

1111
## ✨ Features
1212

@@ -404,36 +404,56 @@ PixelProbe uses multiple methods to detect file corruption:
404404

405405
## Architecture
406406

407+
### Modular Architecture (v2.0.55+)
408+
409+
PixelProbe now features a clean, modular architecture following SOLID principles:
410+
407411
```
408412
PixelProbe/
409-
├── app.py # Flask web application
410-
├── media_checker.py # Core corruption detection logic
411-
├── models.py # SQLAlchemy database models
412-
├── version.py # Version information
413-
├── templates/
414-
│ ├── index.html # Legacy web interface
415-
│ ├── index_modern.html # Modern responsive UI
416-
│ └── api_docs.html # API documentation
417-
├── static/
418-
│ ├── css/ # Stylesheets
419-
│ │ ├── desktop.css # Desktop responsive styles
420-
│ │ ├── mobile.css # Mobile responsive styles
421-
│ │ └── logo-styles.css # Logo styling
422-
│ ├── js/ # JavaScript
423-
│ │ └── app.js # Main application logic
424-
│ └── images/ # Images and icons
425-
├── tools/ # Utility scripts for maintenance
426-
│ ├── README.md # Documentation for tools
427-
│ └── *.py # Various fix and migration scripts
428-
├── docs/ # Documentation
429-
│ └── screenshots/ # UI screenshots
430-
├── scripts/ # Development and deployment scripts
431-
├── requirements.txt # Python dependencies
432-
├── Dockerfile # Docker container configuration
433-
├── docker-compose.yml # Docker Compose setup
434-
└── README.md # This file
413+
├── app.py # Application initialization (250 lines vs 2,500+)
414+
├── pixelprobe/ # Main package
415+
│ ├── api/ # API Route Blueprints
416+
│ │ ├── scan_routes.py # Scan endpoints (/api/scan-*)
417+
│ │ ├── stats_routes.py # Statistics endpoints (/api/stats, /api/system-info)
418+
│ │ ├── admin_routes.py # Admin endpoints (configurations, schedules)
419+
│ │ ├── export_routes.py # Export endpoints (CSV, view, download)
420+
│ │ └── maintenance_routes.py # Cleanup and file-changes operations
421+
│ ├── services/ # Business Logic Layer
422+
│ │ ├── scan_service.py # Scanning operations and orchestration
423+
│ │ ├── stats_service.py # Statistics calculations
424+
│ │ ├── export_service.py # Export functionality
425+
│ │ └── maintenance_service.py # Cleanup and monitoring
426+
│ ├── repositories/ # Data Access Layer
427+
│ │ ├── base_repository.py # Generic repository pattern
428+
│ │ ├── scan_repository.py # Scan result data operations
429+
│ │ └── config_repository.py # Configuration data operations
430+
│ └── utils/ # Shared Utilities
431+
│ ├── helpers.py # Common helper functions
432+
│ ├── decorators.py # Route decorators
433+
│ └── validators.py # Input validation
434+
├── tests/ # Comprehensive Test Suite
435+
│ ├── conftest.py # Pytest configuration and fixtures
436+
│ ├── test_media_checker.py # Core functionality tests
437+
│ ├── unit/ # Unit tests for each component
438+
│ │ ├── test_scan_service.py
439+
│ │ ├── test_stats_service.py
440+
│ │ └── test_repositories.py
441+
│ └── integration/ # API integration tests
442+
├── media_checker.py # Core corruption detection engine
443+
├── models.py # SQLAlchemy database models
444+
├── static/ # Frontend assets
445+
├── templates/ # HTML templates
446+
└── requirements.txt # Python dependencies
435447
```
436448

449+
### Key Architectural Benefits
450+
451+
- **Separation of Concerns**: Each module has a single, well-defined responsibility
452+
- **Testability**: Components can be tested in isolation with comprehensive test coverage
453+
- **Maintainability**: Changes to one feature don't affect others
454+
- **Scalability**: Easy to add new features without modifying existing code
455+
- **API Compatibility**: All endpoints remain unchanged, ensuring backward compatibility
456+
437457
## 🛠️ Utility Tools
438458

439459
The `tools/` directory contains utility scripts for database maintenance and migration tasks. These are useful for:
@@ -444,6 +464,58 @@ The `tools/` directory contains utility scripts for database maintenance and mig
444464

445465
See [tools/README.md](tools/README.md) for detailed documentation on each tool.
446466

467+
## Documentation
468+
469+
### API Documentation
470+
- **[API Reference](docs/api/README.md)** - Complete API documentation with endpoints, request/response examples
471+
- **[OpenAPI Specification](docs/api/openapi.yaml)** - OpenAPI 3.0 specification for API integration
472+
- **[Integration Guide](docs/examples/integration-guide.md)** - Examples for integrating PixelProbe into your workflows
473+
474+
### Developer Documentation
475+
- **[Developer Guide](docs/developer/README.md)** - Setup, architecture, and contribution guidelines
476+
- **[Architecture Overview](docs/ARCHITECTURE.md)** - System design and component architecture
477+
- **[Project Structure](docs/PROJECT_STRUCTURE.md)** - Detailed code organization and module descriptions
478+
- **[Performance Tuning](docs/PERFORMANCE_TUNING.md)** - Optimization guide for large-scale deployments
479+
480+
### API Client Examples
481+
- **[Python Client](docs/examples/python-client.py)** - Full-featured Python client with CLI
482+
- **[Node.js Client](docs/examples/nodejs-client.js)** - JavaScript/Node.js client implementation
483+
- **[Bash Client](docs/examples/bash-client.sh)** - Shell script client using curl and jq
484+
485+
### Quick Start Examples
486+
487+
#### Python
488+
```python
489+
from pixelprobe_client import PixelProbeClient
490+
491+
client = PixelProbeClient("http://localhost:5000")
492+
client.scan_directory(["/media/photos"])
493+
stats = client.get_statistics()
494+
print(f"Corruption rate: {stats['corruption_rate']}%")
495+
```
496+
497+
#### JavaScript
498+
```javascript
499+
const PixelProbeClient = require('./pixelprobe-client');
500+
501+
const client = new PixelProbeClient('http://localhost:5000');
502+
await client.scanDirectory(['/media/photos']);
503+
const stats = await client.getStatistics();
504+
console.log(`Corruption rate: ${stats.corruption_rate}%`);
505+
```
506+
507+
#### Bash
508+
```bash
509+
# Scan directories
510+
./pixelprobe-client.sh scan /media/photos /media/videos
511+
512+
# Get statistics
513+
./pixelprobe-client.sh stats
514+
515+
# Export results
516+
./pixelprobe-client.sh export results.csv
517+
```
518+
447519
## Development
448520

449521
### Running in Development Mode
@@ -453,6 +525,62 @@ export FLASK_ENV=development
453525
python app.py
454526
```
455527

528+
### Testing
529+
530+
PixelProbe includes a comprehensive test suite covering core functionality, services, repositories, and API endpoints.
531+
532+
#### Running Tests
533+
534+
```bash
535+
# Install test dependencies
536+
pip install -r requirements-test.txt
537+
538+
# Run all tests
539+
pytest
540+
541+
# Run with coverage report
542+
pytest --cov=pixelprobe --cov-report=html
543+
544+
# Run specific test categories
545+
pytest tests/unit/ # Unit tests only
546+
pytest tests/integration/ # Integration tests only
547+
pytest tests/test_media_checker.py # Core functionality tests
548+
549+
# Run with verbose output
550+
pytest -v
551+
552+
# Run with benchmark tests
553+
pytest --benchmark-only
554+
```
555+
556+
#### Test Categories
557+
558+
- **Unit Tests**: Test individual components in isolation
559+
- Service layer tests (scan, stats, export, maintenance)
560+
- Repository layer tests (data access patterns)
561+
- Utility function tests
562+
563+
- **Integration Tests**: Test API endpoints and full workflows
564+
- API endpoint tests with mock data
565+
- Database integration tests
566+
- File system operation tests
567+
568+
- **Performance Tests**: Benchmark critical operations
569+
- File scanning performance
570+
- Database query optimization
571+
- Memory usage monitoring
572+
573+
#### Writing Tests
574+
575+
When contributing, please include tests for new functionality:
576+
577+
```python
578+
# Example test for new feature
579+
def test_new_feature(scan_service, mock_scan_result):
580+
result = scan_service.new_feature(mock_scan_result)
581+
assert result.status == 'success'
582+
```
583+
456584
### Adding New File Formats
457585

458586
To add support for new file formats:

0 commit comments

Comments
 (0)