fix: full security audit remediation — P0/P1/P2/P3 fixes + 1020 passing tests
P0 — Broken functionality: - Fix 12+ endpoints with wrong manager method signatures (email/calendar/file/routing) - Fix email_manager.delete_email_user() missing domain arg - Fix cell-link DNS forwarding wiped on every peer change (generate_corefile now accepts cell_links param; add/remove_cell_dns_forward no longer clobber the file) - Fix Flask SECRET_KEY regenerating on every restart (persisted to DATA_DIR) - Fix _next_peer_ip exhaustion returning 500 instead of 409 - Fix ConfigManager Caddyfile path (/app/config-caddy/) - Fix UI double-add and wrong-key peer bugs in Peers.jsx / WireGuard.jsx - Remove hardcoded credentials from Dashboard.jsx P1 — Security: - CSRF token validation on all POST/PUT/DELETE/PATCH to /api/* (double-submit pattern) - enforce_auth: 503 only when users file readable but empty; never bypass on IOError - WireGuard add_cell_peer: validate pubkey, name, endpoint against strict regexes - DNS add_cell_dns_forward: validate IP and domain; reject injection chars - DNS zone write: realpath containment + record content validation - iptables comment /32 suffix prevents substring match deleting wrong peer rules - is_local_request() trusts only loopback + 172.16.0.0/12 (Docker bridge) - POST /api/containers: volume allow-list prevents arbitrary host mounts - file_manager: bcrypt ($2b→$2y) for WebDAV; realpath containment in delete_user - email/calendar: stop persisting plaintext passwords in user records - routing_manager: validate IPs, networks, and interface names - peer_registry: write peers.json at mode 0o600 - vault_manager: Fernet key file at mode 0o600 - CORS: lock down to explicit origin list - domain/cell_name validation: reject newline, brace, semicolon injection chars P2 — Architecture: - Peer add: rollback registry entry if firewall rules fail post-add - restart_service(): base class now calls _restart_container(); email and calendar managers call cell-mail / cell-radicale respectively - email/calendar managers sync user list (no passwords) to cell_config.json - Pending-restart flag cleared only after helper subprocess exits with code 0 - docker-compose.yml: add config-caddy volume to API container P3 — Tests (854 → 1020): - Fill test_email_endpoints.py, test_calendar_endpoints.py, test_network_endpoints.py, test_routing_endpoints.py - New: test_peer_management_update.py, test_peer_management_edge_cases.py, test_input_validation.py, test_enforce_auth_configured.py, test_cell_link_dns.py, test_logs_endpoints.py, test_cells_endpoints.py, test_is_local_request_per_endpoint.py, test_caddy_routing.py - E2E conftest: skip WireGuard suite when wg-quick absent - Update existing tests to match fixed signatures and comment formats Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+20
-20
@@ -366,8 +366,8 @@ class TestAPIEndpoints(unittest.TestCase):
|
||||
def test_email_endpoints(self, mock_email):
|
||||
# Ensure all relevant mock methods return JSON-serializable values
|
||||
mock_email.get_users.return_value = [{'username': 'user1', 'domain': 'cell', 'email': 'user1@cell'}]
|
||||
mock_email.create_user.return_value = True
|
||||
mock_email.delete_user.return_value = True
|
||||
mock_email.create_email_user.return_value = True
|
||||
mock_email.delete_email_user.return_value = True
|
||||
mock_email.get_status.return_value = {'postfix_running': True, 'dovecot_running': True, 'total_users': 1, 'total_size_bytes': 0, 'total_size_mb': 0.0, 'users': [{'username': 'user1', 'domain': 'cell', 'email': 'user1@cell'}]}
|
||||
mock_email.test_connectivity.return_value = {'smtp': {'success': True, 'message': 'SMTP server responding'}}
|
||||
mock_email.send_email.return_value = True
|
||||
@@ -383,17 +383,17 @@ class TestAPIEndpoints(unittest.TestCase):
|
||||
# /api/email/users (POST)
|
||||
response = self.client.post('/api/email/users', data=json.dumps({'username': 'user1', 'domain': 'cell', 'password': 'pw'}), content_type='application/json')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
mock_email.create_user.side_effect = Exception('fail')
|
||||
mock_email.create_email_user.side_effect = Exception('fail')
|
||||
response = self.client.post('/api/email/users', data=json.dumps({'username': 'user1', 'domain': 'cell', 'password': 'pw'}), content_type='application/json')
|
||||
self.assertEqual(response.status_code, 500)
|
||||
mock_email.create_user.side_effect = None
|
||||
mock_email.create_email_user.side_effect = None
|
||||
# /api/email/users/<username> (DELETE)
|
||||
response = self.client.delete('/api/email/users/user1')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
mock_email.delete_user.side_effect = Exception('fail')
|
||||
mock_email.delete_email_user.side_effect = Exception('fail')
|
||||
response = self.client.delete('/api/email/users/user1')
|
||||
self.assertEqual(response.status_code, 500)
|
||||
mock_email.delete_user.side_effect = None
|
||||
mock_email.delete_email_user.side_effect = None
|
||||
# /api/email/status (GET)
|
||||
response = self.client.get('/api/email/status')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
@@ -427,8 +427,8 @@ class TestAPIEndpoints(unittest.TestCase):
|
||||
def test_calendar_endpoints(self, mock_calendar):
|
||||
# Mock return values for all relevant calendar_manager methods
|
||||
mock_calendar.get_users.return_value = [{'username': 'user1', 'collections': {'calendars': ['cal1'], 'contacts': ['c1']}}]
|
||||
mock_calendar.create_user.return_value = True
|
||||
mock_calendar.delete_user.return_value = True
|
||||
mock_calendar.create_calendar_user.return_value = True
|
||||
mock_calendar.delete_calendar_user.return_value = True
|
||||
mock_calendar.create_calendar.return_value = {'calendar': 'cal1'}
|
||||
mock_calendar.add_event.return_value = {'event': 'event1'}
|
||||
mock_calendar.get_events.return_value = [{'event': 'event1'}]
|
||||
@@ -445,17 +445,17 @@ class TestAPIEndpoints(unittest.TestCase):
|
||||
# /api/calendar/users (POST)
|
||||
response = self.client.post('/api/calendar/users', data=json.dumps({'username': 'user1', 'password': 'pw'}), content_type='application/json')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
mock_calendar.create_user.side_effect = Exception('fail')
|
||||
mock_calendar.create_calendar_user.side_effect = Exception('fail')
|
||||
response = self.client.post('/api/calendar/users', data=json.dumps({'username': 'user1', 'password': 'pw'}), content_type='application/json')
|
||||
self.assertEqual(response.status_code, 500)
|
||||
mock_calendar.create_user.side_effect = None
|
||||
mock_calendar.create_calendar_user.side_effect = None
|
||||
# /api/calendar/users/<username> (DELETE)
|
||||
response = self.client.delete('/api/calendar/users/user1')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
mock_calendar.delete_user.side_effect = Exception('fail')
|
||||
mock_calendar.delete_calendar_user.side_effect = Exception('fail')
|
||||
response = self.client.delete('/api/calendar/users/user1')
|
||||
self.assertEqual(response.status_code, 500)
|
||||
mock_calendar.delete_user.side_effect = None
|
||||
mock_calendar.delete_calendar_user.side_effect = None
|
||||
# /api/calendar/calendars (POST)
|
||||
response = self.client.post('/api/calendar/calendars', data=json.dumps({'username': 'user1', 'calendar_name': 'cal1'}), content_type='application/json')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
@@ -599,10 +599,10 @@ class TestAPIEndpoints(unittest.TestCase):
|
||||
self.assertEqual(response.status_code, 500)
|
||||
mock_routing.get_firewall_rules.side_effect = None
|
||||
# /api/routing/peers (POST)
|
||||
response = self.client.post('/api/routing/peers', data=json.dumps({'peer': 'peer1', 'route': '10.0.0.2'}), content_type='application/json')
|
||||
response = self.client.post('/api/routing/peers', data=json.dumps({'peer_name': 'peer1', 'peer_ip': '10.0.0.2'}), content_type='application/json')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
mock_routing.add_peer_route.side_effect = Exception('fail')
|
||||
response = self.client.post('/api/routing/peers', data=json.dumps({'peer': 'peer1', 'route': '10.0.0.2'}), content_type='application/json')
|
||||
response = self.client.post('/api/routing/peers', data=json.dumps({'peer_name': 'peer1', 'peer_ip': '10.0.0.2'}), content_type='application/json')
|
||||
self.assertEqual(response.status_code, 500)
|
||||
mock_routing.add_peer_route.side_effect = None
|
||||
# /api/routing/peers (GET)
|
||||
@@ -620,24 +620,24 @@ class TestAPIEndpoints(unittest.TestCase):
|
||||
self.assertEqual(response.status_code, 500)
|
||||
mock_routing.remove_peer_route.side_effect = None
|
||||
# /api/routing/exit-nodes (POST)
|
||||
response = self.client.post('/api/routing/exit-nodes', data=json.dumps({'node': 'exit1'}), content_type='application/json')
|
||||
response = self.client.post('/api/routing/exit-nodes', data=json.dumps({'peer_name': 'exit1', 'peer_ip': '10.0.0.5'}), content_type='application/json')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
mock_routing.add_exit_node.side_effect = Exception('fail')
|
||||
response = self.client.post('/api/routing/exit-nodes', data=json.dumps({'node': 'exit1'}), content_type='application/json')
|
||||
response = self.client.post('/api/routing/exit-nodes', data=json.dumps({'peer_name': 'exit1', 'peer_ip': '10.0.0.5'}), content_type='application/json')
|
||||
self.assertEqual(response.status_code, 500)
|
||||
mock_routing.add_exit_node.side_effect = None
|
||||
# /api/routing/bridge (POST)
|
||||
response = self.client.post('/api/routing/bridge', data=json.dumps({'bridge': 'br1'}), content_type='application/json')
|
||||
response = self.client.post('/api/routing/bridge', data=json.dumps({'source_peer': 'peer1', 'target_peer': 'peer2'}), content_type='application/json')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
mock_routing.add_bridge_route.side_effect = Exception('fail')
|
||||
response = self.client.post('/api/routing/bridge', data=json.dumps({'bridge': 'br1'}), content_type='application/json')
|
||||
response = self.client.post('/api/routing/bridge', data=json.dumps({'source_peer': 'peer1', 'target_peer': 'peer2'}), content_type='application/json')
|
||||
self.assertEqual(response.status_code, 500)
|
||||
mock_routing.add_bridge_route.side_effect = None
|
||||
# /api/routing/split (POST)
|
||||
response = self.client.post('/api/routing/split', data=json.dumps({'split': 'sp1'}), content_type='application/json')
|
||||
response = self.client.post('/api/routing/split', data=json.dumps({'network': '10.0.0.0/24', 'exit_peer': '10.0.0.5'}), content_type='application/json')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
mock_routing.add_split_route.side_effect = Exception('fail')
|
||||
response = self.client.post('/api/routing/split', data=json.dumps({'split': 'sp1'}), content_type='application/json')
|
||||
response = self.client.post('/api/routing/split', data=json.dumps({'network': '10.0.0.0/24', 'exit_peer': '10.0.0.5'}), content_type='application/json')
|
||||
self.assertEqual(response.status_code, 500)
|
||||
mock_routing.add_split_route.side_effect = None
|
||||
# /api/routing/connectivity (POST)
|
||||
|
||||
Reference in New Issue
Block a user