stashly

Running a server: logs, metrics and security

For the person who runs Stashly. See the README for the short version.

Operating Stashly: logs and metrics

Three things help you run a server. All are off by default, and none of them ever carries a stash name, password, token, cookie, note text, file name or query string: a stash name is the only secret of a stash without a password, so the logs name a stash by a short keyed hash instead (see below).

Variable Default Meaning
LOG_FORMAT off json writes one JSON line to stdout for each finished request
AUDIT_LOG off stdout writes one JSON line for each change of who can reach what
METRICS_TOKEN empty Turns on GET /metrics (Prometheus text format); callers must send Authorization: Bearer <token>. Use a long random value

Access log (LOG_FORMAT=json): {"time","level":"info","msg":"request","method","route","status","ms","ip","stash","role","bytes"}. route is the route pattern (/api/stashes/:slug/notes), never the real path; a request no route answered is unmatched, and the page’s own files are static. stash is the first 10 hex characters of an HMAC-SHA-256 of the name keyed with the server’s secret, so lines about one stash can be matched with each other, but the name cannot be read from them (the secret is kept in the database or set with SESSION_SECRET, so tags stay the same across restarts). role is full, view, drop or none when a stash was involved. bytes is the response’s Content-Length when it has one. A live stream is logged when it ends. /health and /metrics are not logged.

Audit log (AUDIT_LOG=stdout): {"time","level":"audit","event","ip","stash","actor","detail"} with actor visitor, admin or system (expiry). Events: stash.created, stash.deleted (detail.reason: visitor, admin or expired), stash.renamed (hashes of the old and new name), stash.password_changed, stash.password_reset_by_admin, stash.sessions_signed_out, stash.share_link_created / stash.share_link_revoked (the kind only), stash.tags_changed (detail.action rename or delete, detail.clips), items.moved / items.copied (the count), stash.extended (detail.by owner or visitor, detail.ttl) / stash.extended_by_admin, stash.owner_set_by_admin / stash.ownership_transferred (detail.user / detail.to: the new owner’s number), stash.unlock_failed (every wrong password, with the address), stash.locked_out (when the lockout trips), item.deleted / item.restored (the kind only), item.share_created (detail.expires) / item.share_revoked (a link to one clip), admin.mcp_token_created / admin.mcp_token_revoked, mcp.tool_called (actor mcp; detail.tool and detail.failed, never the arguments), stash.exported, admin.login_succeeded, admin.login_failed, admin.logout, admin.settings_changed (the settings that changed and their new values; none is a secret) and admin.backup_downloaded. Accounts add user.login_succeeded, user.login_failed (also a wrong current password when changing it), user.locked_out, user.logout, user.password_changed, user.followed (with the stash’s hash; detail.via is create when it came from creating the stash) and user.unfollowed, with actor user or visitor, and user.created, user.updated (only the names of the changed fields), user.password_reset, user.signed_out and user.deleted, done by an admin. A user is identified by number in detail.user; no line carries a username, display name, password or session token, and an unknown name in a failed sign-in is not recorded at all. Send stdout to your log collector; Docker keeps it for docker logs.

Metrics (METRICS_TOKEN set): stashly_http_requests_total{method,route,status_class}, stashly_http_request_duration_seconds (histogram by route), stashly_stashes, stashly_items{kind}, stashly_stored_bytes, stashly_trashed_items, stashly_sse_connections, stashly_unlock_failures_total, stashly_uploads_total, stashly_uploaded_bytes_total, stashly_exports_total, stashly_admin_logins_total{result}, stashly_user_logins_total{result}, stashly_users{role}, stashly_build_info{version}, stashly_process_start_time_seconds and the process memory. Labels are route patterns and fixed words only, so a new stash never adds a series. Counters start from zero at every restart. A Prometheus job:

scrape_configs:
  - job_name: stashly
    authorization: { type: Bearer, credentials: "<METRICS_TOKEN>" }
    static_configs: [{ targets: ["stashly:3000"] }]

Without METRICS_TOKEN the address answers 404. Keep /metrics and the logs off the public internet where you can: the numbers say how much is stored and how busy the server is.

Security notes