//! `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=#.`. 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 `` and `` 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!(""); 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 = 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() }