oficina / memoria Public

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

Plain git — no account needed to clone.

Download

Download this file

1package memoria
2
3import (
4 "net/http"
5
6 "amadan.net/rastrillo/rastrillo"
7
8 // The pack for rastrillo's one language here: from rastrillo v0.29.0
9 // a language with no pack linked is refused at start (Serve and
10 // Handler both), and the sign-in door's words come from it.
11 _ "amadan.net/rastrillo/rastrillo/locales/en"
12)
13
14// ServeOptions completes opts with what Memoria serves: mux (App's, with
15// MountAuth's routes on it) and the error page. main passes the result to
16// rastrillo.Serve, and the CSP tests pass it to rastrillo.Handler, so the
17// stack they check is the one production runs.
18//
19// It sets no CSP, deliberately. rastrillo fb806a2's default refuses every
20// inline style attribute (style-src 'self' 'unsafe-hashes' plus pow's
21// honeypot hash), and nothing Memoria serves standalone carries one: its
22// templates, the estilo and rastrillo partials they draw, and the scripts
23// it ships (rastrillo.js, busy.js, chrome.js, drop.js, search.js) write no
24// style attribute — drop.js and search.js set attributes, hidden and a
25// <progress> value, never style. So the default holds as shipped and there was nothing to
26// migrate. TestNoPageCarriesAStyleAttribute and
27// TestStandaloneServesRastrillosDefaultCSP keep it that way, and the
28// browser check TestPagesRenderUnderTheProductionCSP watches for
29// violations in Chromium.
30//
31// One page is not ours: rastrillo/native's approval page
32// (/native/authorize) draws itself with one inline <style>, admitted by
33// its hash on that route alone (nativeApprovalCSP, native.go). Every other
34// route serves the default exactly.
35//
36// With Home configured, connect's middleware replaces the policy with
37// connect.FormPolicy, whose style-src keeps 'unsafe-inline': estilo's
38// account-link page (homeconnect home_link.html) draws the address with
39// style="overflow-wrap: anywhere". That page exists only in Home mode.
40func (a *app) ServeOptions(opts rastrillo.Options, mux *http.ServeMux) rastrillo.Options {
41 opts.Mux = mux
42 // rastrillo.Serve's own panic recovery, for a panic outside the
43 // router: the same 500 page, with the viewer's chrome, as the
44 // router's recoverToErrorPage renders (shared chrome §3.3).
45 opts.ErrorPage = a.ErrorPage
46 return opts
47}
48