Security & Secrets¶
This page covers the server-side security controls an administrator manages: the encryption master secret (and how to rotate it safely) and API and WebSocket access.
For login methods, password policy, and two-factor authentication see Authentication & Login. For TLS see HTTPS & TLS Certificates.
The encryption master secret¶
CosMO derives all of its internal secrets from a single configured value, cosmo.master-secret. From it CosMO derives:
- the AES-256 key that encrypts data at rest — user TOTP secrets and each user's saved AI provider key;
- the hashing pepper for API keys and mobile device keys;
- the "remember me" signing key.
Because everything derives from this one value, setting a single strong secret protects all of the above.
Setting or rotating it¶
Use the configuration tool's Authentication tab → Encryption → Set / Rotate…. You can either let CosMO generate a strong random secret or paste your own. The current value is never displayed.
A fresh installation generates a random master secret automatically, so a new deployment never runs on the built-in placeholder.
Don't ship the placeholder to production
CosMO ships with a built-in placeholder secret that is publicly known. It will still start on that placeholder, but logs a loud warning, and any encrypted data would then be protected by a known key. Set a strong value — via the configuration tool, or the cosmo.master-secret property / the COSMO_MASTER_SECRET environment variable — before going live.
Rotating is safe¶
Rotation keeps working keys and data
When you rotate the secret, CosMO keeps the previous value(s) in cosmo.master-secret-previous (written for you) and uses them as a verification/decryption fallback. So after a rotation:
- already-issued API keys and mobile device keys keep authenticating,
- existing encrypted data (TOTP secrets, saved AI provider keys) is still readable,
- users do not have to re-enter their AI provider keys.
New secrets are always used going forward; the old ones are only tried as a fallback.
cosmo:
master-secret: "a-strong-random-value"
# Written automatically by the config tool when you rotate; newest first.
master-secret-previous:
- "the-previous-secret"
API & WebSocket access¶
- REST API (
/api/**) and the AI tool endpoint (/mcp/**) authenticate with anX-API-KEYheader. A user generates their key from their profile; it is stored hashed. - Mobile clients register a device and authenticate with a device key.
- WebSocket / live updates (the
/stomp-endpointused for AI chat streaming and in-app notifications) now require an authenticated session. Anonymous clients can no longer open the connection or subscribe to messages.
Rotating the master secret does not invalidate API keys
See the rotation note above — existing API and device keys continue to work after a rotation.
Common problems¶
| Symptom | Likely cause |
|---|---|
| Startup log warns about the master secret | It is still the placeholder — set a strong cosmo.master-secret. |
| API keys / device keys stopped working after a config change | The master secret was replaced without the config tool's rotate action, so the previous value wasn't retained — restore it into cosmo.master-secret-previous, or reissue the keys. |
| Encrypted data can't be decrypted after a change | Same cause — the old secret must be present (current or in master-secret-previous) to decrypt data written under it. |
| A WebSocket / live-update client can't connect | It isn't authenticated — the STOMP endpoint now requires a logged-in session. |