forked from vhaudiquet/rhema-together
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:
1 parent
7e7a1d2bb6
commit
3b82719d56
38 files changed
+1307
-106
No files matched your search
+37
-2
@@ -4,13 +4,14 @@
|
||||
pub mod auth;
|
||||
pub mod files;
|
||||
pub mod messages;
|
||||
pub mod profile;
|
||||
pub mod rooms;
|
||||
pub mod settings;
|
||||
|
||||
use axum::Router;
|
||||
use axum::body::Body;
|
||||
use axum::extract::{Request, State};
|
||||
use axum::http::{HeaderValue, StatusCode, Uri, header};
|
||||
use axum::extract::{DefaultBodyLimit, Request, State};
|
||||
use axum::http::{HeaderMap, HeaderValue, StatusCode, Uri, header};
|
||||
use axum::middleware::{self, Next};
|
||||
use axum::response::{Html, IntoResponse, Response};
|
||||
use axum::routing::{delete, get, post};
|
||||
@@ -28,6 +29,13 @@ pub fn router(state: Shared) -> Router {
|
||||
.route("/register", post(auth::register))
|
||||
.route("/login", post(auth::login))
|
||||
.route("/logout", post(auth::logout))
|
||||
.route(
|
||||
"/profile/avatar",
|
||||
post(profile::upload_avatar)
|
||||
.delete(profile::delete_avatar)
|
||||
.layer(DefaultBodyLimit::max(profile::MAX_AVATAR_BYTES + 64 * 1024)),
|
||||
)
|
||||
.route("/avatars/{account}", get(profile::get_avatar))
|
||||
.route(
|
||||
"/provider-configs",
|
||||
get(settings::list_providers).post(settings::create_provider),
|
||||
@@ -72,6 +80,27 @@ pub fn router(state: Shared) -> Router {
|
||||
.with_state(state)
|
||||
}
|
||||
|
||||
/// Whether a browser WebSocket handshake came from the app's origin.
|
||||
/// A client that sends no `Origin` is not a browser page and is left to
|
||||
/// the cookie check.
|
||||
pub(crate) fn websocket_origin_ok(config: &crate::config::Config, headers: &HeaderMap) -> bool {
|
||||
let Some(origin) = headers
|
||||
.get(header::ORIGIN)
|
||||
.and_then(|value| value.to_str().ok())
|
||||
else {
|
||||
return true;
|
||||
};
|
||||
let origin = origin.trim_end_matches('/');
|
||||
let public = config.public_url.trim_end_matches('/');
|
||||
if origin == public {
|
||||
return true;
|
||||
}
|
||||
// The Nuxt dev server proxies the sockets from port 3000 while the
|
||||
// API keeps its own port. Both are loopback, so accept that pair.
|
||||
let loopback = public.starts_with("http://localhost") || public.starts_with("http://127.0.0.1");
|
||||
loopback && (origin.starts_with("http://localhost:") || origin.starts_with("http://127.0.0.1:"))
|
||||
}
|
||||
|
||||
/// Rejects a mutating API request without the matching CSRF header.
|
||||
/// Setup, login, registration, and joining with an invite happen before
|
||||
/// the client has a CSRF cookie.
|
||||
@@ -122,6 +151,12 @@ async fn headers(State(state): State<Shared>, request: Request, next: Next) -> R
|
||||
HeaderValue::from_static("strict-origin-when-cross-origin"),
|
||||
);
|
||||
h.insert(header::X_FRAME_OPTIONS, HeaderValue::from_static("DENY"));
|
||||
if state.config.secure_cookies() {
|
||||
h.insert(
|
||||
header::STRICT_TRANSPORT_SECURITY,
|
||||
HeaderValue::from_static("max-age=31536000"),
|
||||
);
|
||||
}
|
||||
let frame_src = match state.config.preview_frame_source() {
|
||||
Some(source) => format!("'self' {source}"),
|
||||
None => "'self'".to_owned(),
|
||||
|
||||
Reference in new issue
Block a user