9.4 KiB
9.4 KiB
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
flowchart TB
subgraph "Authentication Layer"
TSID[TeamSpeak ID<br/>Implicit]
Pass[Password<br/>Admin/DJ]
Token[Session Token<br/>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
flowchart TB
subgraph "Authentication"
Req[Request] --> Method{Method}
Method -->|TS Chat| TSID[TeamSpeak ID<br/>+ 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
flowchart LR
User[TeamSpeak User] -->|Has groups| Check{Check Groups}
Check -->|In| Admin[Admin Groups<br/>Full Access]
Check -->|In| DJ[DJ Groups<br/>Queue Control]
Check -->|Not in banned| User2[Regular User<br/>Basic Commands]
Check -->|In| Banned[Banned Groups<br/>No Access]
Permission Matrix
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
flowchart TB
Request[Command Request] --> Banned{Is Banned?}
Banned -->|Yes| Deny1[Deny: Banned]
Banned -->|No| Admin{Admin<br/>Command?}
Admin -->|Yes| IsAdmin{Is Admin?}
IsAdmin -->|Yes| Allow1[Allow]
IsAdmin -->|No| Deny2[Deny: Admin Only]
Admin -->|No| Queue{Queue<br/>Command?}
Queue -->|Yes| IsDJ{Is Admin/DJ?}
IsDJ -->|Yes| Allow2[Allow]
IsDJ -->|No| Deny3[Deny: DJ Only]
Queue -->|No| Allow3[Allow: User]
Rate Limiting
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<br/>>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
flowchart TB
Login[Login Attempt] --> Locked{Account<br/>Locked?}
Locked -->|Yes| CheckTime{Lockout<br/>Expired?}
CheckTime -->|No| Deny[Deny: Locked]
CheckTime -->|Yes| Unlock[Unlock Account]
Locked -->|No| Verify{Credentials<br/>Valid?}
Unlock --> Verify
Verify -->|Yes| Success[Login Success]
Verify -->|No| Fail[Login Failed]
Fail --> Record[Record Attempt]
Record --> Count{Max Attempts<br/>Reached?}
Count -->|Yes| Lock[Lock Account<br/>5 minutes]
Count -->|No| Remaining[Return Attempts<br/>Remaining]
Success --> Clear[Clear Failed<br/>Attempts]
Success --> Token[Create Session<br/>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
flowchart LR
subgraph "Session Lifecycle"
Create[Create Session<br/>On login] --> Active[Active Session]
Active -->|Activity| Extend[Extend Timeout]
Active -->|Timeout| Expire[Expire Session]
Active -->|Logout| Destroy[Destroy Session]
end
Audit Logging
flowchart TB
Action[User Action] --> Log{Audit Log<br/>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
flowchart LR
Password[Plain Password] --> Salt[Add Salt]
Salt --> Hash[Hash<br/>bcrypt/scrypt]
Hash --> Store[Store Hash]
Verify[Verify Attempt] --> AddSalt[Add Same Salt]
AddSalt --> Hash2[Hash]
Hash2 --> Compare{Compare<br/>Hashes}
Compare -->|Match| Valid[Valid]
Compare -->|No Match| Invalid[Invalid]
Token Generation
flowchart LR
Random[CSPRNG] --> Bytes[32 Random Bytes]
Bytes --> Encode[Base64URL Encode]
Encode --> Token[Session Token]
Token --> Store[Store with<br/>Expiration]
Network Security
TLS Configuration
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
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
flowchart TB
subgraph "Deployment Security"
Default[Change Default<br/>Credentials]
Groups[Configure Server<br/>Groups]
Audit[Enable Audit<br/>Logging]
TLS[Use HTTPS/WSS]
Update[Keep yt-dlp<br/>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
flowchart TB
subgraph "Development Security"
Validate[Validate All<br/>Inputs]
SQL[Parameterized<br/>Queries]
Secrets[No Secrets in<br/>Logs]
Errors[Safe Error<br/>Messages]
Clear[Clear Sensitive<br/>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
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