SSRF prevention
Server-Side Request Forgery (SSRF) is prevented through strict hostname validation in the handler routing system.The vulnerability
Without proper validation, an attacker could craft URLs like:domain in url check would pass this URL to the TMO handler, causing the server to make requests to internal endpoints.
The protection
The router validates that supported domains exist within the parsed hostname, not the full URL:core/handler.py
By extracting and validating only the
netloc component (hostname), the router ensures that HTTP requests target legitimate manga sites, not internal services or arbitrary hosts.Why this matters
SSRF attacks could allow malicious users to:- Access internal admin panels
- Scan internal network infrastructure
- Exploit services not exposed to the internet
- Bypass firewall rules
Path traversal protection
Local File Inclusion (LFI) and path traversal attacks are prevented when serving PDF files to web clients.The vulnerability
Without validation, an attacker could request:The protection
The web server validates that resolved paths remain within the PDF directory:web_server.py
How it works
- URL decode the filename to handle encoded characters
- Resolve absolute path by joining
pdf_dir+filename - Verify containment - ensure resolved path starts with
pdf_dir - Reject if outside the PDF directory
Example validation
CORS enforcement
Cross-Origin Resource Sharing (CORS) is configured to prevent unauthorized web pages from accessing the local server.The vulnerability
Usingallow_origins=["*"] with allow_credentials=True would allow any malicious website to:
- Connect to the user’s local server
- Submit download requests
- Access generated PDFs
- Potentially exploit other endpoints
The protection
CORS middleware restricts access to known development origins:web_server.py
The origins listed correspond to common development server ports:
3000- Create React App, Next.js5173- Vite
Production considerations
For production deployments:DoS protection
Denial of Service (DoS) protection prevents resource exhaustion through rate limiting.The vulnerability
Without limits, a malicious user could:- Submit hundreds of simultaneous downloads
- Exhaust server memory and CPU
- Make the service unavailable to legitimate users
- Fill disk space with temporary files
The protection
The web server limits concurrent downloads globally:web_server.py
Configuration
You can adjust the concurrency limit based on your server’s resources:Why limit to 3 concurrent downloads?
Why limit to 3 concurrent downloads?
The default limit of 3 concurrent downloads balances:
- User experience - Multiple users can download simultaneously
- Resource usage - Each download consumes memory, CPU, and network bandwidth
- Stability - Prevents server crashes under load
Information leakage prevention
Internal error details are logged server-side but never exposed to clients.The vulnerability
Detailed error messages could reveal:- File system paths
- Database structure
- Internal library versions
- Stack traces with code snippets
The protection
Errors are sanitized before sending to clients:web_server.py
Security checklist
When adding new features or handlers, verify:- URLs are parsed and validated using
urlparse() - Hostnames are checked against allowlists, not the full URL
- File paths are resolved with
os.path.abspath()before validation - Resolved paths are verified to be within allowed directories
- CORS origins are explicitly listed (never use
["*"]) - Rate limiting protects resource-intensive operations
- Exception details are logged but not exposed to clients
- User input is sanitized before use in file operations
Security comments in source
The codebase includes detailed Spanish security comments at critical points. These explain:- What vulnerability is being prevented
- Why the protection is necessary
- How the attack would work without the protection
These comments serve as documentation for security audits and help future maintainers understand the threat model.
Reporting security issues
If you discover a security vulnerability:- Do not open a public GitHub issue
- Email the maintainer directly with details
- Include steps to reproduce the vulnerability
- Allow time for a patch before public disclosure
Next steps
Async downloads
Learn how concurrent downloads are implemented safely
Architecture
Understand the overall system design