diff --git a/docs/SECURITY.md b/docs/SECURITY.md new file mode 100644 index 0000000..23ce941 --- /dev/null +++ b/docs/SECURITY.md @@ -0,0 +1,291 @@ +# Security Architecture and Guidelines + +Date: 2026-10-07 +Status: Active security documentation for Berry AI Studio +Related: Issue #144, ARCHITECTURE.md, AGENTS.md + +## Overview + +Berry AI Studio implements a layered security model that balances native desktop capabilities with web content security. The application consists of a Rust/Tauri native shell that hosts a React/TypeScript frontend communicating with a FastAPI Python backend. + +## Security Principles + +1. **Least Privilege**: Native capabilities are granted only to trusted local origins +2. **Defense in Depth**: Multiple security layers (CSP, capability scoping, origin validation) +3. **Isolation**: Local engines run in sandboxed environments with no global host pollution +4. **Content Security**: External content (generated images, API responses) is isolated from native privileges + +## Architecture Components + +``` +┌─────────────────────────────────────────────────────────┐ +│ Tauri Native Shell (Rust) │ +│ - Window management (minimize, maximize, close) │ +│ - Backend process supervision │ +│ - Capability enforcement │ +└─────────────────────────────────────────────────────────┘ + │ + ↓ IPC (scoped to localhost) +┌─────────────────────────────────────────────────────────┐ +│ Frontend (React + Vite) │ +│ Origin: http://127.0.0.1:8000 │ +│ - Canvas UI, creation controls │ +│ - CSP-enforced content policy │ +└─────────────────────────────────────────────────────────┘ + │ + ↓ HTTP/WebSocket +┌─────────────────────────────────────────────────────────┐ +│ Backend (FastAPI + Python) │ +│ Bound to: 127.0.0.1:8000 │ +│ - Workflow execution, model management │ +│ - ComfyUI/WebUI engine coordination │ +└─────────────────────────────────────────────────────────┘ +``` + +## Native Capabilities + +### Capability Scoping + +The Tauri capability system grants native window control permissions exclusively to local origins: + +**File**: `frontend/src-tauri/capabilities/default.json` + +```json +{ + "identifier": "default", + "description": "Grants window control permissions to the local backend origin", + "windows": ["main"], + "permissions": [ + "core:window:allow-minimize", + "core:window:allow-maximize", + "core:window:allow-unmaximize", + "core:window:allow-toggle-maximize", + "core:window:allow-close", + "core:window:allow-start-dragging", + "core:window:allow-is-maximized", + "core:window:allow-set-focus" + ], + "remote": { + "urls": [ + "http://127.0.0.1:*", + "http://localhost:*" + ] + } +} +``` + +**Security Properties**: +- Only content served from `127.0.0.1` or `localhost` receives native window control permissions +- External content loaded via `