oficina / meet Public

Clone
git clone https://amadan.net/oficina/meet

Plain git — no account needed to clone.

Download

Download this file

1package calls
2
3import (
4 "net/http"
5 "strings"
6
7 "amadan.net/rastrillo/rastrillo"
8
9 // The pack for rastrillo's one language here: from rastrillo v0.29.0
10 // a language with no pack linked is refused at start (Serve and
11 // Handler both), and the sign-in door's words come from it.
12 _ "amadan.net/rastrillo/rastrillo/locales/en"
13)
14
15// ServeOptions completes opts with what Calls serves: its mux, its error
16// page and its scheduled-wake function. main passes the result to
17// rastrillo.Serve, and the tests that need the production stack (the CSP
18// tests, the browser gate) pass it to rastrillo.Handler, so the headers
19// they check are the ones production sends.
20//
21// opts.CSP is deliberately left empty: Calls serves rastrillo's default
22// policy unchanged, the strict one since fb806a2 (style-src 'self' plus
23// pow's honeypot hash, no 'unsafe-inline'). Nothing Calls draws needs
24// more. Its templates, and the estilo and ui partials they call, carry
25// no style attribute; its scripts set geometry and the speaking rim
26// through CSSOM (element.style.setProperty, .translate, .display), which
27// CSP does not govern; and the web client's network is all same-origin
28// (fetch, the SSE stream), with media from getUserMedia on srcObject and
29// TURN/STUN reached by RTCPeerConnection, neither of which connect-src
30// or media-src covers. With Home configured, connect's middleware
31// replaces the policy on every page in the group; homeFormPolicy keeps
32// that one rastrillo's default too, with only the issuer added to
33// form-action. TestProductionServesRastrillosDefaultCSP,
34// TestHomeCSPPreservesPinnedFrameworkDirectives and the browser gate's
35// CSP check hold this.
36func ServeOptions(opts rastrillo.Options, mux *http.ServeMux, rt *Runtime) rastrillo.Options {
37 opts.Mux = mux
38 if rt != nil {
39 // NextDue answers the platform's scheduled-wake poll: a magic
40 // link or pending-join row can outlive an instance's
41 // hibernation, and without this the platform has no way to know
42 // it should wake the app to clear one (review C2-2).
43 opts.NextDue = rt.NextDue
44 // A panic outside the router gets the app's own error page, not
45 // rastrillo's plain "Something went wrong." (shared chrome §3.3).
46 opts.ErrorPage = rt.ErrorPage
47 }
48 return opts
49}
50
51// Runtime is the parts of Runtime a test harness can have: everything
52// but Close, which belongs to whoever built the app with App. Tests
53// only.
54func (h *TestHandle) Runtime() *Runtime {
55 return &Runtime{NextDue: h.a.nextDue, ErrorPage: h.a.ErrorPage}
56}
57
58// frameworkCSP is rastrillo's default Content-Security-Policy at the
59// pinned version (serve.go's defaultCSP, unexported), spelled out
60// because homeFormPolicy must start from it.
61// TestProductionServesRastrillosDefaultCSP fails the day a bump changes
62// the default, so this cannot quietly keep an older policy.
63const frameworkCSP = "default-src 'self'; " +
64 "style-src 'self' 'unsafe-hashes' 'sha256-yJxAE4rjdcckohdlnvecSporPcqS9xOaA4hJxi87LMc=' " +
65 "'sha256-81gZUb3tp60YCqhJ0dItBPh5hRQiGbfst4gpwCNPTfI='; " +
66 "img-src 'self' data:; frame-ancestors 'none'; base-uri 'self'; form-action 'self'"
67
68// homeFormPolicy is the policy connect's middleware sends in Home mode:
69// rastrillo's default with the issuer added to form-action, because the
70// Home exchange posts a form there. connect's own FormPolicy predates
71// rastrillo fb806a2 and still allows inline styles; Calls has none to
72// allow. The one style attribute connect's pages carry (home_link.html's
73// overflow-wrap on the linked address) is in calls-shell.css instead.
74func homeFormPolicy(issuer string) string {
75 return strings.Replace(frameworkCSP, "form-action 'self'", "form-action 'self' "+issuer, 1)
76}
77