1ccae752d7
ci / check (pull_request) Has been cancelled
A static page for https://<relay>/join#<invite id>.<secret>, the link messengers make tappable. The fragment never reaches the relay. One button opens amicitia://invite?relay=<origin>#…; its only script and style are named by SHA-256 in a Content-Security-Policy of default-src 'none'; no-store, no-referrer, no cookie, framing refused. PROTOCOL.md §8 lists the route.
58 lines
2.0 KiB
Rust
58 lines
2.0 KiB
Rust
//! `GET /join` (PROTOCOL.md §8, added 2026-11-18): the page an invite link opens in a browser. It
|
|
//! hands the invite, which sits in the URL's fragment and so never reaches this server, to the app
|
|
//! as `amicitia://invite?relay=<this origin>#<id>.<secret>`. Static: it reads nothing, stores
|
|
//! nothing, sets no cookie and loads nothing from anywhere else.
|
|
|
|
use std::sync::LazyLock;
|
|
|
|
use axum::http::header;
|
|
use axum::response::{IntoResponse, Response};
|
|
use base64::Engine;
|
|
use sha2::{Digest, Sha256};
|
|
|
|
pub const PAGE: &str = include_str!("../assets/join.html");
|
|
|
|
/// The text between `<tag>` and `</tag>` in the page (one of each), exactly as the browser hashes it.
|
|
fn inline(tag: &str) -> &'static str {
|
|
let open = format!("<{tag}>");
|
|
let close = format!("</{tag}>");
|
|
let start = PAGE.find(&open).expect("the page has the tag") + open.len();
|
|
let end = PAGE[start..].find(&close).expect("the tag is closed") + start;
|
|
&PAGE[start..end]
|
|
}
|
|
|
|
fn hash(text: &str) -> String {
|
|
let digest = Sha256::digest(text.as_bytes());
|
|
format!(
|
|
"'sha256-{}'",
|
|
base64::engine::general_purpose::STANDARD.encode(digest)
|
|
)
|
|
}
|
|
|
|
/// Nothing but the page's own script and style, each by its hash: no other script, no image, no
|
|
/// font, no connection, no frame, no form.
|
|
pub static CONTENT_SECURITY_POLICY: LazyLock<String> = LazyLock::new(|| {
|
|
format!(
|
|
"default-src 'none'; script-src {}; style-src {}; base-uri 'none'; form-action 'none'; frame-ancestors 'none'",
|
|
hash(inline("script")),
|
|
hash(inline("style"))
|
|
)
|
|
});
|
|
|
|
pub async fn page() -> Response {
|
|
(
|
|
[
|
|
(header::CONTENT_TYPE, "text/html; charset=utf-8"),
|
|
(
|
|
header::CONTENT_SECURITY_POLICY,
|
|
CONTENT_SECURITY_POLICY.as_str(),
|
|
),
|
|
(header::CACHE_CONTROL, "no-store"),
|
|
(header::REFERRER_POLICY, "no-referrer"),
|
|
(header::X_CONTENT_TYPE_OPTIONS, "nosniff"),
|
|
],
|
|
PAGE,
|
|
)
|
|
.into_response()
|
|
}
|