feat: add account avatars and a deployable image

Accounts get a profile page with an uploaded picture, shown in the
sidebar, the room bar, and every human message. Pictures live in the
SQLite database and are served through an authenticated route.

Hardening from the security audit: preview hosts expire after 24 hours
and carry no-referrer; removing a member or archiving a room ends their
event feed, presence socket, and terminal within seconds; previews and
the terminal pin the SSH host key; invites are claimed atomically;
missing accounts spend the same argon2 time as wrong passwords;
registration is closed by default; WebSockets check the origin; and the
master key is created with mode 0600.

The Dockerfile builds one image with the static client and the server.
The Helm chart runs a single replica with a SQLite volume, a wildcard
preview ingress, and the proxy settings the event feed and uploads
need. It refuses more than one replica because state is in process.
This commit is contained in:
vhaudiquet committed 2026-11-28 02:07:26 +01:00
1 parent 7e7a1d2bb6
commit 3b82719d56
38 files changed
+1307 -106

No files matched your search

+20 -4
View File
@@ -88,8 +88,10 @@ fn load_members(state: &Shared, room: &str) -> AppResult<Vec<Member>> {
let online = state.presence.online(room);
let conn = state.db.conn();
let mut stmt = conn.prepare(
"SELECT id, account_id, display_name, role, color FROM members
WHERE room_id = ?1 ORDER BY created_at ASC",
"SELECT m.id, m.account_id, m.display_name, m.role, m.color,
(SELECT updated_at FROM avatars WHERE account_id = m.account_id)
FROM members m
WHERE m.room_id = ?1 ORDER BY m.created_at ASC",
)?;
let rows = stmt.query_map(rusqlite::params![room], |row| {
Ok(Member {
@@ -98,6 +100,7 @@ fn load_members(state: &Shared, room: &str) -> AppResult<Vec<Member>> {
display_name: row.get(2)?,
role: row.get(3)?,
color: row.get(4)?,
avatar_updated_at: row.get(5)?,
online: false,
})
})?;
@@ -504,6 +507,18 @@ pub async fn join(
return Err(AppError::gone("this invite has expired"));
}
let display_name = clean_display_name(&body.display_name)?;
// Claim the invite before creating an account or a member. The
// conditional update is atomic, so two requests racing with the
// same link cannot both redeem it.
let token_hash = sha256_hex(token.as_bytes());
let claimed = state.db.conn().execute(
"UPDATE invites SET used_at = ?1
WHERE token_hash = ?2 AND used_at IS NULL AND expires_at >= ?1",
rusqlite::params![now_ms(), &token_hash],
)?;
if claimed == 0 {
return Err(AppError::gone("this invite was already used"));
}
let existing = auth::user_from_headers(&state, &headers);
let mut new_session = false;
let account = match existing {
@@ -522,6 +537,7 @@ pub async fn join(
handle,
display_name,
kind: "guest".into(),
avatar_updated_at: None,
}
}
};
@@ -559,8 +575,8 @@ pub async fn join(
}
};
state.db.conn().execute(
"UPDATE invites SET used_at = ?1, used_by = ?2 WHERE token_hash = ?3",
rusqlite::params![now_ms(), account.id, sha256_hex(token.as_bytes())],
"UPDATE invites SET used_by = ?1 WHERE token_hash = ?2",
rusqlite::params![account.id, token_hash],
)?;
let cookies = if new_session {
let raw = auth::create_session(&state, &account.id)?;