Skip to content

Security Model

Arthu Santiago edited this page Nov 30, 2026 · 2 revisions

Security Model

This page describes how KeyAnyWhere protects the data it stores and the people who use it: what is encrypted and with which key, how logins work, which protections each request gets, and what is recorded. It also states the limits, the things KeyAnyWhere does not protect against, so you can decide what else your installation needs.

The guiding principle of the project is security before convenience: some features are deliberately less practical than they could be (mandatory 2FA, no "remember me", generic login errors).

Data at rest

KeyAnyWhere doesn't hash the secrets it stores, because it must show them back to you. It encrypts them instead.

Data Protection
Entry title, username, password, link and notes; category name; each user's 2FA secret Encrypted with libsodium crypto_secretbox (XSalsa20-Poly1305), key KEY_CRIPTOGRAFIC. Each value gets a fresh random nonce, so the same text encrypted twice gives different results.
User passwords Hashed with bcrypt. They can't be read back, not even by the administrator.
Connection to the database TLS required (sslmode=require, since 2.4.1). The server certificate is not checked; to check it, set ssl_mode to verify-full and ssl_ca in config/app_local.php.
Sessions Stored in the database (sessions table), with user agent and last activity, so a user can see and end each one. Sessions idle for more than a day are purged.

The key is outside the database (an environment variable), so a stolen database dump alone reveals no secret. Whoever has both the dump and the key can read everything: keep them apart (Backup and Restore).

Authentication

  • Second factor is mandatory for every account (TOTP, RFC 6238). There is no way to turn it off in production. A development-only switch exists for local testing, and it requires both a development environment and an explicit variable (Development Environment).
  • Generic login errors: a wrong e-mail, password or code all give the same message, so an attacker can't tell which one was right.
  • First-run token: the screen that creates the first administrator only opens with CONFIG_INICIAL_TOKEN (First-Run Setup).
  • Server-side authorization: every administrator screen checks the user's role on the server, not only by hiding menu entries. Users can end only their own sessions; administrators can end anyone's.

Every request

These protections are applied by middleware to every response.

Protection Detail
HTTPS only With debug off, HTTP is refused and HSTS is sent (one year).
Session cookie __Secure- prefix, Secure, HttpOnly, SameSite=Strict.
CSRF Every form post carries a token checked against a signed cookie. API routes added by plugins authenticate by token instead.
Security headers Content-Security-Policy and X-Frame-Options: DENY in production; Referrer-Policy: strict-origin-when-cross-origin, X-Content-Type-Options: nosniff, X-Download-Options: noopen, X-Permitted-Cross-Domain-Policies: none everywhere.
Out of search engines X-Robots-Tag: noindex, nofollow on every response.
Input filtering Every form field goes through an XSS filter (voku/anti-xss); a match is refused and recorded as a security event. Output is escaped in the templates.

Records

  • Security events (failed logins, attempts on administrator screens, blocked content) go to a log file and to a screen every user can see (Logs and Security Events).
  • Audit trail: an insert-only record of who created, changed or deleted each entry, category and user. It keeps the names of the changed fields, never their values.
  • Logs never carry secrets: request logs record the route, not the query string, and security events never record the content that was blocked.

Limits

What KeyAnyWhere does not do, and what you should do about it:

  • No end-to-end encryption. Secrets are decrypted on the server to be shown in the browser. Whoever controls the server (or its root account) can read them. Protect the server like the most sensitive thing you own.
  • Shared vault. Every user of an installation sees every entry (User Guide). Separate installations are the way to separate people.
  • No key rotation. KEY_CRIPTOGRAFIC can't be changed on an existing database.
  • Proxies that end HTTPS are not supported: HTTPS must reach Apache.

OWASP and further reading

The project follows the OWASP Top Ten recommendations. The assessment report is in the repository: relatorio-aplicacao-OWASP-Top-10.pdf (in Portuguese). The undergraduate thesis that gave rise to KeyAnyWhere, with the reasoning behind its design, is also there: Arthu-Santiago-TCC.pdf (in Portuguese).

Found a weakness? See Reporting a Vulnerability.

Clone this wiki locally