[relay] Join page: merge feature/join-page — GET /join hands an invite link to the app
ci / check (push) Has been cancelled
ci / check (push) Has been cancelled
Review: in the PR for feature/join-page (self-review and line comments in the PR).
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
# The join page — an invite link a messenger can open
|
||||
|
||||
## 1. Why and what
|
||||
Amicitia (the app this relay serves) makes connecting seamless: *Invite Petr* opens the phone's
|
||||
share sheet with a message holding the invite link, and Petr taps it (Amicitia's
|
||||
`.agents/features/seamless-invite.md`). Messengers make `https://` links tappable, not
|
||||
`amicitia://`. So the link is `https://<relay>/join#<invite id>.<secret>`, and the relay serves the
|
||||
page it opens: one button, **Open Amicitia**, that hands the invite to the app.
|
||||
|
||||
## 2. Design
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant B as Browser
|
||||
participant R as Relay
|
||||
participant A as App
|
||||
B->>R: GET /join (the fragment #id.secret is never sent)
|
||||
R-->>B: static page: CSP default-src 'none' + hashes, no-store, no-referrer
|
||||
B->>A: tap → amicitia://invite?relay=<origin>#id.secret
|
||||
```
|
||||
- `crates/relay/assets/join.html`, served by `crates/relay/src/join.rs`. The CSP names the page's
|
||||
only script and style by SHA-256, computed from the page itself at start-up, so an edit to the
|
||||
page cannot run without its hash.
|
||||
- The script checks the fragment's shape (22 + 43 base64url characters) and only then sets the
|
||||
button's target; anything else shows *This invite link is incomplete*.
|
||||
- No automatic redirect: Chrome refuses a custom scheme opened without a tap.
|
||||
|
||||
## 3. Risks
|
||||
- **Privacy:** the relay learns that an address opened `/join` — no more than any client tells it.
|
||||
It stores nothing and prints no request. The secret stays in the fragment. A messenger's link
|
||||
preview fetches `/join` only.
|
||||
- **The page as an attack surface:** static, no input read on the server, no cookie, framing
|
||||
refused, nothing loaded from elsewhere.
|
||||
|
||||
## 4. Verification
|
||||
| Case | How |
|
||||
|:--|:--|
|
||||
| Static, strict headers, nothing external, no cookie | `the_join_page_is_static_and_loads_nothing_from_elsewhere` |
|
||||
| The policy's hashes match the page's script and style | `the_join_page_policy_hashes_its_own_script_and_style` |
|
||||
| The script builds the app link from a good fragment and refuses a bad one | Node, by hand (in the PR); Amicitia's phone test end to end |
|
||||
Generated
+2
@@ -2276,11 +2276,13 @@ name = "tabellarius-relay"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"base64",
|
||||
"getrandom 0.3.4",
|
||||
"http-body-util",
|
||||
"rusqlite",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2 0.10.9",
|
||||
"subtle",
|
||||
"tabellarius-protocol",
|
||||
"tempfile",
|
||||
|
||||
@@ -15,6 +15,9 @@ rusqlite = { version = "0.41", features = ["bundled"] }
|
||||
serde = "1"
|
||||
serde_json = "1"
|
||||
subtle = "2"
|
||||
# The join page's Content-Security-Policy names its inline script and style by SHA-256 (base64).
|
||||
sha2 = "0.10"
|
||||
base64 = "0.22"
|
||||
|
||||
[dev-dependencies]
|
||||
getrandom = "0.3"
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="referrer" content="no-referrer">
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<title>An invite to a private chat</title>
|
||||
<style>
|
||||
:root { color-scheme: dark light; }
|
||||
body { margin: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center;
|
||||
background: #0d0a0c; color: #f2ece8; font: 17px/1.5 system-ui, sans-serif; }
|
||||
main { max-width: 420px; padding: 32px 24px; text-align: center; }
|
||||
h1 { font-weight: 600; font-size: 26px; line-height: 1.2; margin: 0 0 12px; }
|
||||
p { margin: 0 0 20px; color: #cfc4bf; }
|
||||
.button { display: block; padding: 14px 20px; margin: 8px 0 24px; border-radius: 12px;
|
||||
background: #b3223a; color: #fff; text-decoration: none; font-weight: 600; font-size: 18px; }
|
||||
.small { font-size: 14px; color: #a99d98; }
|
||||
[hidden] { display: none; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>You're invited to a private chat</h1>
|
||||
<p>Someone who knows you invited you to chat in Amicitia, end to end encrypted.</p>
|
||||
<a id="open" class="button" href="#">Open Amicitia</a>
|
||||
<p id="missing" class="small">Don't have Amicitia yet? Ask the person who invited you how to get it, then tap their message again.</p>
|
||||
<p id="bad" class="small" hidden>This invite link is incomplete. Ask for a new one.</p>
|
||||
</main>
|
||||
<script>
|
||||
(function () {
|
||||
// The invite is in the fragment, which the browser never sends to this server.
|
||||
var invite = location.hash.slice(1);
|
||||
var open = document.getElementById("open");
|
||||
if (!/^[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}$/.test(invite)) {
|
||||
open.hidden = true;
|
||||
document.getElementById("missing").hidden = true;
|
||||
document.getElementById("bad").hidden = false;
|
||||
return;
|
||||
}
|
||||
open.href = "amicitia://invite?relay=" + location.origin + "#" + invite;
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -38,6 +38,7 @@ pub fn router(state: AppState) -> Router {
|
||||
.route("/v0/invites", post(create_invite))
|
||||
.route("/v0/invites/{id}", get(claim_invite))
|
||||
.route("/version", get(version))
|
||||
.route("/join", get(crate::join::page))
|
||||
.layer(DefaultBodyLimit::max(MAX_JSON_BYTES))
|
||||
.merge(blob_routes)
|
||||
.with_state(state)
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
//! `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()
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
//! acknowledges it. Stores exactly `docs/PROTOCOL.md` §5 and logs no request.
|
||||
|
||||
pub mod http;
|
||||
pub mod join;
|
||||
pub mod store;
|
||||
|
||||
use std::net::SocketAddr;
|
||||
|
||||
@@ -741,3 +741,98 @@ async fn no_random_request_breaks_the_relay() {
|
||||
assert_eq!(status, StatusCode::NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
/// `GET /join` (PROTOCOL.md §8, 2026-11-18): a static page that hands the fragment to the app. It
|
||||
/// must load nothing from elsewhere, run nothing but its own script, and keep nothing.
|
||||
#[tokio::test]
|
||||
async fn the_join_page_is_static_and_loads_nothing_from_elsewhere() {
|
||||
use tower::ServiceExt;
|
||||
let relay = Relay::in_memory();
|
||||
let response = relay
|
||||
.app
|
||||
.clone()
|
||||
.oneshot(Request::get("/join").body(Body::empty()).expect("request"))
|
||||
.await
|
||||
.expect("response");
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
let h = response.headers().clone();
|
||||
let get = |name: &str| {
|
||||
h.get(name)
|
||||
.and_then(|v| v.to_str().ok())
|
||||
.unwrap_or("")
|
||||
.to_string()
|
||||
};
|
||||
assert_eq!(get("content-type"), "text/html; charset=utf-8");
|
||||
assert_eq!(get("cache-control"), "no-store");
|
||||
assert_eq!(get("referrer-policy"), "no-referrer");
|
||||
assert_eq!(get("x-content-type-options"), "nosniff");
|
||||
assert!(h.get("set-cookie").is_none());
|
||||
let csp = get("content-security-policy");
|
||||
assert!(
|
||||
csp.starts_with("default-src 'none'; script-src 'sha256-"),
|
||||
"{csp}"
|
||||
);
|
||||
for part in [
|
||||
"base-uri 'none'",
|
||||
"form-action 'none'",
|
||||
"frame-ancestors 'none'",
|
||||
] {
|
||||
assert!(csp.contains(part), "{csp} lacks {part}");
|
||||
}
|
||||
let body = String::from_utf8(
|
||||
response
|
||||
.into_body()
|
||||
.collect()
|
||||
.await
|
||||
.expect("body")
|
||||
.to_bytes()
|
||||
.to_vec(),
|
||||
)
|
||||
.expect("utf-8");
|
||||
// Nothing loaded from anywhere, and nothing the script could send the fragment with or leave
|
||||
// the page by on its own (a custom scheme must wait for the person's tap).
|
||||
for banned in [
|
||||
"http://",
|
||||
"https://",
|
||||
" src=",
|
||||
"<link",
|
||||
"<img",
|
||||
"<iframe",
|
||||
"@import",
|
||||
"url(",
|
||||
"fetch(",
|
||||
"XMLHttpRequest",
|
||||
"sendBeacon",
|
||||
"WebSocket",
|
||||
"location.href",
|
||||
"location.assign",
|
||||
"location.replace",
|
||||
"window.open",
|
||||
] {
|
||||
assert!(!body.contains(banned), "the page contains {banned:?}");
|
||||
}
|
||||
// One script and one style, both named by the policy's hashes; the invite goes to the app.
|
||||
assert_eq!(body.matches("<script>").count(), 1);
|
||||
assert_eq!(body.matches("<style>").count(), 1);
|
||||
assert!(body.contains("\"amicitia://invite?relay=\" + location.origin + \"#\" + invite"));
|
||||
assert!(body.contains("location.hash"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_join_page_policy_hashes_its_own_script_and_style() {
|
||||
use base64::Engine;
|
||||
use sha2::{Digest, Sha256};
|
||||
let page = tabellarius_relay::join::PAGE;
|
||||
let between = |open: &str, close: &str| {
|
||||
let s = page.find(open).expect("the tag opens") + open.len();
|
||||
&page[s..page[s..].find(close).expect("the tag closes") + s]
|
||||
};
|
||||
let csp = tabellarius_relay::join::CONTENT_SECURITY_POLICY.as_str();
|
||||
for text in [
|
||||
between("<script>", "</script>"),
|
||||
between("<style>", "</style>"),
|
||||
] {
|
||||
let b64 = base64::engine::general_purpose::STANDARD.encode(Sha256::digest(text.as_bytes()));
|
||||
assert!(csp.contains(&format!("'sha256-{b64}'")), "{csp}");
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -89,7 +89,7 @@ The platform facts above are Claude's understanding, to be verified in `.agents/
|
||||
- Parsers are fuzzed (`cargo fuzz`) for every message type.
|
||||
- Every check in `VERIFY.md` §1 has a CI job or a documented manual procedure.
|
||||
|
||||
## 8. The wire (v0) — approved 2026-11-08, routes added 2026-11-14, quotas 2026-11-16
|
||||
## 8. The wire (v0) — approved 2026-11-08, routes added 2026-11-14, quotas 2026-11-16, join page 2026-11-18
|
||||
HTTP/1.1 behind TLS (the reverse proxy, F23). Ids and tokens are unpadded base64url of a fixed length
|
||||
with one canonical spelling: ids are 16 bytes, and tokens and hashes are 32. JSON bodies refuse
|
||||
unknown fields. A blob is at most 256 KiB, and a KeyPackage at most 16 KiB.
|
||||
@@ -104,6 +104,7 @@ unknown fields. A blob is at most 256 KiB, and a KeyPackage at most 16 KiB.
|
||||
| `POST /v0/invites` `{id, secretHash, keyPackage}` | none | stores an invite. It expires after 7 days, rounded up to the hour |
|
||||
| `GET /v0/invites/{id}` | invite secret | returns the KeyPackage once, then deletes the invite |
|
||||
| `GET /version` | none | the protocol and relay versions |
|
||||
| `GET /join` | none | a static page for an invite link opened in a browser *(added 2026-11-18)* |
|
||||
|
||||
- A wrong token, an unknown id and a malformed id all give the same bare **404**, so nobody can probe
|
||||
what exists.
|
||||
@@ -113,6 +114,13 @@ unknown fields. A blob is at most 256 KiB, and a KeyPackage at most 16 KiB.
|
||||
limit the answer is a bare **507**. The per-mailbox caps are checked only after the post token,
|
||||
so a 507 tells a stranger nothing about a mailbox. Nothing new is stored to count: the counts
|
||||
come from §5's own rows and `size`. A client treats 507 like any failure and tries again later.
|
||||
- **The join page** *(added 2026-11-18; `.agents/features/join-page.md`)*: an invite can travel as
|
||||
`https://<relay>/join#<invite id>.<secret>`, which messengers make tappable. The browser sends
|
||||
only `GET /join`: the fragment, and so the secret, never reaches the relay, a link preview or a
|
||||
proxy. The page is static (one inline script and style, named by hash in a
|
||||
`Content-Security-Policy` of `default-src 'none'`; `no-store`; `no-referrer`; no cookie) and
|
||||
points its one button at `amicitia://invite?relay=<its origin>#<id>.<secret>`. The relay stores
|
||||
nothing for it and learns only that some address opened the page.
|
||||
- A refusal has no body.
|
||||
- The relay prints no request.
|
||||
- Tests: `crates/relay/tests/relay.rs`, `crates/protocol/tests/wire.rs`.
|
||||
|
||||
Reference in New Issue
Block a user