Date: 2026-04-07
Status: Core hardening in place; additional operational hardening recommended
This document summarizes a focused security review of Canopy's current public release line. It identifies important hardening work already completed, documents key tradeoffs, and highlights additional operational work that maintainers or deployers may still want to complete.
The assessment focused on vulnerabilities that would materially affect a public-facing or production-style deployment:
- Authentication and authorization
- Input validation and injection attacks
- Rate limiting and DoS prevention
- P2P network attack vectors
- File handling security
- Cryptographic implementations
Issue: Passwords were hashed using SHA256 with a global salt, vulnerable to:
- Rainbow table attacks
- GPU-accelerated cracking
- Lack of computational cost for attackers
Fix Implemented:
- Replaced SHA256 with bcrypt (12 rounds = 4096 iterations)
- Per-password salt generation (automatic in bcrypt)
- Backward compatibility: Legacy SHA256 hashes automatically migrated on login
- Added password strength validation:
- Minimum 8 characters
- Must contain uppercase, lowercase, digit, and special character
- Rejects common weak passwords
Files Changed:
canopy/security/password.py(new file)canopy/api/routes.py(registration endpoint)canopy/ui/routes.py(login, registration, password change)
Impact: Prevents credential compromise even if database is stolen.
Issue: File uploads had minimal validation:
- No MIME type whitelist
- No magic bytes verification
- No extension matching
- Vulnerable to: malicious file uploads, ZIP bombs, polyglot attacks
Fix Implemented:
- MIME type whitelist with 20+ safe types (images, audio, video, documents, archives)
- Magic bytes verification for all file types
- Extension matching validation
- ZIP bomb detection for compressed files (max 100x compression ratio, 1GB uncompressed)
- Dangerous content filtering in SVG files (no
<script>,javascript:, etc.) - Strict base64 validation with
validate=True
Files Changed:
canopy/security/file_validation.py(new file)canopy/api/routes.py(upload endpoint)
Impact: Prevents execution of malicious files, DoS via ZIP bombs, XSS via SVG.
Issue: Rate limits were too permissive for sustained public or high-traffic use:
- API: 10 req/s, burst 30
- Upload: 2 req/s, burst 5
- Registration: No dedicated limit
- P2P: 50 req/s, burst 200 (extremely loose)
- P2P messages: 100 per 60s per peer
Fix Implemented:
HTTP Rate Limits (stricter):
- API: 5 req/s, burst 15 (was 10/30)
- Upload: 1 req/s, burst 3 (was 2/5)
- Registration: 1 per 10s, burst 3 (dedicated, IP-based)
- P2P endpoints: 20 req/s, burst 60 (was 50/200)
P2P Message Limits:
- Sustained: 50 messages per 60s per peer (was 100)
- Burst: 10 messages in 5s window (new)
Files Changed:
canopy/core/app.py(HTTP rate limiters)canopy/network/routing.py(P2P message rate limiters)
Impact: Prevents automated account creation, upload flooding, P2P message storms.
Issue: Filenames used directly in path construction without sanitization.
Fix Implemented:
- Filename sanitization: Remove
..,~,|, and other dangerous characters - Path resolution verification: Ensure final path is within storage directory using
Path.resolve() - Length limits: Filenames capped at 255 characters
Files Changed:
canopy/core/files.py(save_file method, new _sanitize_filename)
Impact: Prevents file system escape, arbitrary file read/write.
Issue: No peer reputation system; attacker could spawn unlimited fake peers to flood network.
Fix Implemented:
- Peer reputation system with metrics tracking:
- Longevity bonus (up to 20 points after 24 hours)
- Balance bonus (reward for bidirectional communication)
- Penalties for rate limit violations (-5 per violation)
- Penalties for malformed messages (-2 per message)
- Penalties for connection failures
- Peer validation before connection:
- Minimum reputation threshold (default: 20/100)
- Max peers limit enforcement (default: 50)
- Subnet-based rate limiting (max 10 new peers per subnet per hour)
- Automatic disconnection for peers with reputation < 10
Files Changed:
canopy/network/peer_validation.py(new file)
Impact: Prevents Sybil attacks, limits network spam from new/untrusted peers.
Issue: TLS certificate verification disabled (verify_mode = ssl.CERT_NONE) to support self-signed certificates in P2P mesh.
Why Not Fixed:
- P2P mesh inherently uses self-signed certificates
- Certificate pinning would require out-of-band certificate exchange
- E2E encryption (ChaCha20-Poly1305) provides primary security
Mitigation:
- Documented limitation in code comments
- Recommended certificate pinning for production deployments
- Rely on E2E encryption and Ed25519 signature verification as primary trust mechanism
Files Changed:
canopy/network/connection.py(added documentation)
These require more complex architectural changes:
Recommendation: Use SQLCipher to encrypt SQLite database.
- Protects data if disk/database is stolen
- Requires key management strategy
- May impact performance
Recommendation:
- Force HTTPS redirects for web UI
- Add HSTS headers
- Provide TLS certificate generation/renewal guidance
Recommendation:
- Log all security-relevant events:
- Authentication attempts (success/failure)
- API key creation/revocation
- File uploads/downloads
- P2P peer connections/disconnections
- Rate limit violations
- Store logs in immutable append-only format
- Implement log rotation and retention policies
Recommendation:
- Limit image dimensions before thumbnail generation (e.g., 10000x10000 max)
- Prevents CPU exhaustion from extremely large images
- Async thumbnail generation for better responsiveness
Recommendation:
- Add CAPTCHA (e.g., hCaptcha, reCAPTCHA) to registration form
- Or implement lightweight proof-of-work (e.g., hashcash)
- Prevents automated mass account creation
Recommendation:
- Track bandwidth per peer through relay
- Implement quotas (e.g., 10MB/min per peer)
- Prevents relay amplification attacks
- Add relay cost accounting in trust system
- Test bcrypt password hashing with weak and strong passwords
- Verify legacy SHA256 passwords migrate on login
- Test file upload validation with various file types
- Attempt ZIP bomb upload (should be rejected)
- Test rate limiting on /register endpoint
- Verify P2P message rate limiting with burst and sustained traffic
- Test filename sanitization with path traversal attempts
- Verify peer reputation scoring under various scenarios
Recommended Tools:
- OWASP ZAP - Web application security scanner
- sqlmap - SQL injection testing (should find nothing if using parameterized queries)
- Burp Suite - Intercept and modify HTTP requests
- Artillery - Load testing for rate limit validation
Test Scenarios:
- Brute force registration endpoint (should hit rate limit after 3 attempts)
- Upload 100 files in rapid succession (should be rate limited)
- Send 1000 P2P messages in 10 seconds (should be rate limited)
- Attempt path traversal with
../../etc/passwdin filename
Before broader production use, ensure:
- Bcrypt password hashing enabled
- File upload validation active
- Rate limiting configured and tested
- Path traversal protection verified
- Peer validation system active
- Database backups configured
- HTTPS enabled with valid certificate
- Monitoring and alerting configured
- Audit logging enabled (recommended)
- Rate limit thresholds tuned for expected load
- P2P peer limits adjusted based on server capacity
If a security incident occurs:
-
Immediate Actions:
- Identify affected systems/users
- Isolate compromised peers (ban by peer_id)
- Review audit logs for scope of breach
-
Investigation:
- Check rate limiter logs for abuse patterns
- Review P2P peer reputation scores
- Examine file upload logs for malicious files
- Check authentication logs for credential stuffing
-
Remediation:
- Force password reset for affected users
- Revoke compromised API keys
- Update rate limits if needed
- Deploy fixes and restart services
-
Post-Incident:
- Document timeline and root cause
- Update security policies
- Add additional monitoring/alerting
Critical metrics to monitor:
-
Authentication:
- Failed login attempts per minute
- Password reset requests per hour
- New user registrations per hour
-
Rate Limiting:
- Number of 429 (rate limit) responses per minute
- Top IPs hitting rate limits
- API keys hitting rate limits
-
P2P Network:
- Peers with reputation < 20
- Rate limit violations per peer
- Number of disconnections due to bad behavior
- Average messages per peer per minute
-
File Uploads:
- Upload rejections per hour (by reason)
- File types being uploaded
- Total storage used
- Credential Compromise - Bcrypt hashing
- Malicious File Uploads - Validation, magic bytes checking
- DoS via Rate Limits - Stricter limits, burst protection
- Path Traversal - Filename sanitization
- Sybil Attacks - Peer reputation, connection limits
- P2P Message Flooding - Dual-window rate limiting
- Private Channel Eavesdropping - E2E encrypted channels with per-recipient key wrapping, targeted delivery, and relay transit privacy
- MITM on P2P - E2E encryption present on both transport layer (ChaCha20-Poly1305) and private channels; TLS verification disabled
- Relay Amplification - Rate limited but no bandwidth quotas
- Automated Account Creation - Rate limited but no CAPTCHA
- Database Theft - Not encrypted at rest
- Social Engineering - Human factor, out of scope
- Physical Access - Out of scope
- Supply Chain - Dependency security (separate concern)
The implemented fixes address the highest-priority vulnerabilities identified in this review:
- Weak password hashing → Now using industry-standard bcrypt
- File upload attacks → Comprehensive validation and sanitization
- DoS via rate limits → 5-10x stricter limits with burst protection
- Path traversal → Filename sanitization and path verification
- Sybil attacks → Reputation system with connection limits
Remaining Work:
- Database encryption (recommended for sensitive deployments)
- HTTPS enforcement (operational requirement)
- CAPTCHA/PoW (if spam becomes issue)
- Audit logging (operational visibility)
Risk Assessment:
- Before fixes: HIGH - Multiple critical vulnerabilities
- After fixes: MEDIUM - Core vulnerabilities addressed, operational hardening recommended
The system is now significantly more resistant to attack at scale, but ongoing monitoring and iterative improvements are essential.
Maintained by: Canopy maintainers
Last Updated: 2026-04-07
Next Review: Revisit for the next significant public release or within 3 months, whichever comes first