mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
fix: comprehensive security hardening from full codebase audit
Addresses 14 findings from the security audit across all severity levels: CRITICAL: - C-1: Add user blocking system (migration, DB queries, REST API, WS DM send check) to prevent harassment via unconsented DMs - C-2: Remove server version from unauthenticated /health and /info endpoints to prevent fingerprinting HIGH: - H-1: Remove dangerous-settings feature from tauri-plugin-http - H-3: Default allowSelfSigned to false in API client (was hardcoded true) - H-4: Cap invite expiration to 30 days (720 hours) - H-5: Add 256KB message size limit to LiveKit WS proxy (prevents OOM) - H-6: Cap concurrent sessions to 25 per user (evicts oldest on overflow) - H-8: Restrict /diagnostics/connectivity to ADMINISTRATOR role MEDIUM: - M-2: Deny access to legacy NULL-uploader unlinked attachments - M-4: Log warnings on TOTP plaintext decryption fallback paths - M-8: Remove acceptInvalidCerts from OG preview fetches - M-10: Expand file upload blocklist (Java .class, OLE2, WASM, .lnk) - M-12: Add LIMIT to ListInvites (200) and ListMembers (1000) - M-14: Add CHECK constraint trigger on channels.type (text/voice/dm) https://claude.ai/code/session_01KKo3RwjdmcNzkgXNfUkgNT
This commit is contained in:
@@ -104,13 +104,17 @@ func EncryptTOTPSecret(key []byte, plaintext string) (string, error) {
|
||||
// continue to work.
|
||||
func DecryptTOTPSecret(key []byte, ciphertext string) (string, error) {
|
||||
// Backwards compatibility: if it doesn't look encrypted, return as-is.
|
||||
// M-4: Log a warning so operators can detect unencrypted TOTP secrets
|
||||
// and migrate them (e.g. after key rotation or initial setup).
|
||||
if len(ciphertext) < minEncryptedHexLen {
|
||||
slog.Warn("TOTP secret returned as plaintext (too short for encrypted format) — consider encrypting legacy secrets")
|
||||
return ciphertext, nil
|
||||
}
|
||||
|
||||
data, err := hex.DecodeString(ciphertext)
|
||||
if err != nil {
|
||||
// Not valid hex -- treat as unencrypted plaintext (backwards compat).
|
||||
slog.Warn("TOTP secret returned as plaintext (not valid hex) — consider encrypting legacy secrets")
|
||||
return ciphertext, nil //nolint:nilerr
|
||||
}
|
||||
|
||||
@@ -127,14 +131,17 @@ func DecryptTOTPSecret(key []byte, ciphertext string) (string, error) {
|
||||
nonceSize := gcm.NonceSize()
|
||||
if len(data) < nonceSize+gcm.Overhead() {
|
||||
// Too short to be valid encrypted data -- return as plaintext.
|
||||
slog.Warn("TOTP secret returned as plaintext (data too short for nonce+tag)")
|
||||
return ciphertext, nil
|
||||
}
|
||||
|
||||
nonce, sealed := data[:nonceSize], data[nonceSize:]
|
||||
plaintext, err := gcm.Open(nil, nonce, sealed, nil)
|
||||
if err != nil {
|
||||
// Decryption failed -- likely an unencrypted legacy secret.
|
||||
// Decryption failed -- likely an unencrypted legacy secret or wrong key.
|
||||
// Return as-is for backwards compatibility.
|
||||
slog.Warn("TOTP secret decryption failed — returning as plaintext (check TOTP_ENCRYPTION_KEY)",
|
||||
"error", err)
|
||||
return ciphertext, nil //nolint:nilerr
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user