# Security System ## Overview Echoion implements a multi-layered security system including role-based access control, authentication, session management, and audit logging to ensure safe operation. ## Security Architecture ```mermaid flowchart TB subgraph "Authentication Layer" TSID[TeamSpeak ID
Implicit] Pass[Password
Admin/DJ] Token[Session Token
Desktop] end subgraph "Authorization Layer" Perm[Permission Check] Groups[Server Groups] end subgraph "Protection Layer" Rate[Rate Limiting] Lock[Account Lockout] Audit[Audit Logging] end TSID --> Perm Pass --> Perm Token --> Perm Perm --> Groups Groups --> Admin[Admin Groups] Groups --> DJ[DJ Groups] Groups --> Banned[Banned Groups] Perm --> Rate Rate --> Lock Lock --> Audit ``` ## Authentication Methods ```mermaid flowchart TB subgraph "Authentication" Req[Request] --> Method{Method} Method -->|TS Chat| TSID[TeamSpeak ID
+ Server Groups] Method -->|Desktop| Pass[Username + Password] Method -->|WebSocket| Token[Session Token] end TSID --> VerifyTS{Verify Groups} Pass --> VerifyPass{Verify Credentials} Token --> VerifyToken{Verify Token} VerifyTS -->|Success| AuthTS[Authenticated] VerifyPass -->|Success| AuthPass[Authenticated] VerifyToken -->|Success| AuthToken[Authenticated] ``` ### TeamSpeak Server Groups ```mermaid flowchart LR User[TeamSpeak User] -->|Has groups| Check{Check Groups} Check -->|In| Admin[Admin Groups
Full Access] Check -->|In| DJ[DJ Groups
Queue Control] Check -->|Not in banned| User2[Regular User
Basic Commands] Check -->|In| Banned[Banned Groups
No Access] ``` ## Permission Matrix ```mermaid flowchart TB subgraph "Permission Levels" Admin[Admin] --> All[All Commands] DJ[DJ] --> Queue[Queue Commands] DJ --> Basic1[Basic Commands] User[User] --> Basic2[Basic Commands] Banned[Banned] --> None[No Access] end All --> Reload[reload, reloadconfig] Queue --> Shuffle[shuffle, clear, remove] Basic1 --> Play[play, pause, skip] Basic2 --> Play ``` | Command | Category | Admin | DJ | User | Banned | |---------|----------|-------|-----|------|--------| | play | Music | ✓ | ✓ | ✓ | ✗ | | pause | Playback | ✓ | ✓ | ✓ | ✗ | | skip | Playback | ✓ | ✓ | ✓ | ✗ | | queue | Queue | ✓ | ✓ | ✓ | ✗ | | shuffle | Queue | ✓ | ✓ | ✗ | ✗ | | clear | Queue | ✓ | ✓ | ✗ | ✗ | | reload | Admin | ✓ | ✗ | ✗ | ✗ | | reloadconfig | Admin | ✓ | ✗ | ✗ | ✗ | ## Permission Check Flow ```mermaid flowchart TB Request[Command Request] --> Banned{Is Banned?} Banned -->|Yes| Deny1[Deny: Banned] Banned -->|No| Admin{Admin
Command?} Admin -->|Yes| IsAdmin{Is Admin?} IsAdmin -->|Yes| Allow1[Allow] IsAdmin -->|No| Deny2[Deny: Admin Only] Admin -->|No| Queue{Queue
Command?} Queue -->|Yes| IsDJ{Is Admin/DJ?} IsDJ -->|Yes| Allow2[Allow] IsDJ -->|No| Deny3[Deny: DJ Only] Queue -->|No| Allow3[Allow: User] ``` ## Rate Limiting ```mermaid flowchart TB Request[Command Request] --> Check{Check Limit} Check -->|Under limit| Allow[Allow] Check -->|Over limit| Deny[Deny] Allow --> Record[Record Request] Record --> History[Command History] History --> Cleanup[Cleanup Old
>1 min] subgraph "Limits" Play["play: 10/min"] Search["search: 5/min"] Skip["skip: 3/min"] Vol["volume: 20/min"] end ``` | Command | Limit | Window | |---------|-------|--------| | play | 10 | 1 minute | | search | 5 | 1 minute | | skip | 3 | 1 minute | | volume | 20 | 1 minute | ## Login Protection ```mermaid flowchart TB Login[Login Attempt] --> Locked{Account
Locked?} Locked -->|Yes| CheckTime{Lockout
Expired?} CheckTime -->|No| Deny[Deny: Locked] CheckTime -->|Yes| Unlock[Unlock Account] Locked -->|No| Verify{Credentials
Valid?} Unlock --> Verify Verify -->|Yes| Success[Login Success] Verify -->|No| Fail[Login Failed] Fail --> Record[Record Attempt] Record --> Count{Max Attempts
Reached?} Count -->|Yes| Lock[Lock Account
5 minutes] Count -->|No| Remaining[Return Attempts
Remaining] Success --> Clear[Clear Failed
Attempts] Success --> Token[Create Session
Token] ``` ### Lockout Configuration | Setting | Default | Description | |---------|---------|-------------| | Max attempts | 5 | Failed logins before lockout | | Lockout duration | 5 min | Time before retry allowed | | Session timeout | 1 hour | Token expiration | ## Session Management ```mermaid flowchart LR subgraph "Session Lifecycle" Create[Create Session
On login] --> Active[Active Session] Active -->|Activity| Extend[Extend Timeout] Active -->|Timeout| Expire[Expire Session] Active -->|Logout| Destroy[Destroy Session] end ``` ## Audit Logging ```mermaid flowchart TB Action[User Action] --> Log{Audit Log
Enabled?} Log -->|Yes| Create[Create Audit Event] Log -->|No| Skip[Skip Logging] Create --> Types{Event Type} Types -->|Command| CmdLog[Log Command] Types -->|Config| CfgLog[Log Config Change] Types -->|Auth| AuthLog[Log Auth Event] Types -->|Admin| AdminLog[Log Admin Action] CmdLog --> Write[Write to Log] CfgLog --> Write AuthLog --> Write AdminLog --> Write Write --> File[Log File] Write --> DB[(Database)] ``` ### Audit Event Types | Type | Description | Example | |------|-------------|---------| | CommandExecuted | User ran command | `!play song` | | ConfigChanged | Setting modified | Volume changed | | UserAuthenticated | Login success | Desktop client | | UserLoginFailed | Login failed | Wrong password | | HotReloadPerformed | Core reloaded | Developer action | | TrackPlayed | Song started | YouTube track | | QueueModified | Queue changed | Track removed | ## Secure Configuration ### Password Storage ```mermaid flowchart LR Password[Plain Password] --> Salt[Add Salt] Salt --> Hash[Hash
bcrypt/scrypt] Hash --> Store[Store Hash] Verify[Verify Attempt] --> AddSalt[Add Same Salt] AddSalt --> Hash2[Hash] Hash2 --> Compare{Compare
Hashes} Compare -->|Match| Valid[Valid] Compare -->|No Match| Invalid[Invalid] ``` ### Token Generation ```mermaid flowchart LR Random[CSPRNG] --> Bytes[32 Random Bytes] Bytes --> Encode[Base64URL Encode] Encode --> Token[Session Token] Token --> Store[Store with
Expiration] ``` ## Network Security ### TLS Configuration ```mermaid flowchart TB subgraph "TLS Settings" Version[TLS 1.2+ Only] Ciphers[Strong Ciphers] Cert[Valid Certificate] end Client[Client] -->|WebSocket| TLS[TLS Connection] TLS --> Server[Server] Version --> TLS Ciphers --> TLS Cert --> TLS ``` ### Proxy Configuration ```mermaid flowchart LR Bot[Echoion Bot] --> Proxy{Proxy Type} Proxy -->|HTTP| HTTP[HTTP Proxy] Proxy -->|SOCKS5| SOCKS[SOCKS5 Proxy] Proxy -->|None| Direct[Direct] HTTP --> YouTube SOCKS --> YouTube Direct --> YouTube ``` ## Security Checklist ### Deployment ```mermaid flowchart TB subgraph "Deployment Security" Default[Change Default
Credentials] Groups[Configure Server
Groups] Audit[Enable Audit
Logging] TLS[Use HTTPS/WSS] Update[Keep yt-dlp
Updated] end Default --> Secure Groups --> Secure Audit --> Secure TLS --> Secure Update --> Secure Secure[Secure Deployment] ``` | Item | Status | Description | |------|--------|-------------| | Default credentials | Change | Set strong admin password | | Server groups | Configure | Set adminGroups, djGroups | | Audit logging | Enable | Track all admin actions | | Session timeout | Set | 1 hour recommended | | TLS/WSS | Use | For remote connections | | Dependencies | Update | Keep yt-dlp, FFmpeg current | ### Development ```mermaid flowchart TB subgraph "Development Security" Validate[Validate All
Inputs] SQL[Parameterized
Queries] Secrets[No Secrets in
Logs] Errors[Safe Error
Messages] Clear[Clear Sensitive
Memory] end ``` | Practice | Description | |----------|-------------| | Input validation | Validate all user inputs | | SQL injection | Use parameterized queries | | Logging | Don't log passwords/tokens | | Error handling | Don't leak sensitive info | | Memory | Clear secrets after use | ## Threat Model ```mermaid flowchart TB subgraph "Threats" Spoof[Identity Spoofing] Tamper[Tampering] Repudiation[Repudiation] InfoDisclosure[Info Disclosure] DoS[Denial of Service] Elevation[Elevation of Privilege] end subgraph "Mitigations" TSAuth[TS Auth] TokenAuth[Token Auth] Audit[Audit Logs] Encrypt[Encryption] RateLimit[Rate Limiting] Perms[Permissions] end Spoof --> TSAuth Spoof --> TokenAuth Tamper --> Encrypt Repudiation --> Audit InfoDisclosure --> Encrypt DoS --> RateLimit Elevation --> Perms ```