oficina / slides Public

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

Plain git — no account needed to clone.

Download

Download this file

1package slides
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// ContentSecurityPolicy is the policy Slides serves standalone. It is
15// rastrillo's default policy with one change: style-src keeps
16// 'unsafe-inline', which was rastrillo's own default until the bump to
17// fb806a2.
18//
19// The new default (style-src 'self' 'unsafe-hashes' plus pow's honeypot
20// hash) refuses every style attribute and every <style> element, and a
21// deck is drawn with them:
22//
23// - render.Slide, the one renderer behind the viewer, the projector,
24// the presenter, the share link, the editor's stage and the API's
25// .html twin, writes each slide's theme as custom properties on the
26// <section> (colours, faces, the background picture) and each canvas
27// block's box as left/top/width/height/z-index on the block, with
28// its phone overrides beside them. The values are the deck's own,
29// unbounded, so they cannot be hashed or moved into slides.css, and
30// a per-deck stylesheet would be a new route and cache on four
31// surfaces authenticated four different ways;
32// - the editor puts that same server HTML on its stage with innerHTML
33// (fixtures/stage.mjs), which is a style attribute parsed like any
34// other;
35// - the viewer, the projector, the presenter's notes and the remote
36// carry their page layout in a <style> element of their own. Those
37// could move to slides.css, but every one of those pages (bar the
38// remote and the notes, which show pictures) also renders a slide,
39// so moving them alone would buy nothing while the slide needs
40// 'unsafe-inline'.
41//
42// The editor's drag preview, the presence marks and ProseMirror write
43// element.style through the CSSOM, which CSP does not govern.
44//
45// Every other directive is unchanged, so scripts stay same-origin only
46// and framing, base and form targets stay locked. Home mode serves
47// connect.FormPolicy, which carries the same style-src.
48// TestProductionCSPIsTheDefaultBarStyles keeps every other directive in
49// step with rastrillo's default.
50const ContentSecurityPolicy = "default-src 'self'; style-src 'self' 'unsafe-inline'; " +
51 "img-src 'self' data:; frame-ancestors 'none'; base-uri 'self'; form-action 'self'"
52
53// SealedPolicy is the policy a scene's code runs under (scenes and
54// clips spec §3), and the one page policy that is not
55// ContentSecurityPolicy: the sealed routes (scenes.go) set it in place
56// of the app's, never beside it, because a second policy could only
57// narrow the first and Slides' own would refuse the inline scripts a
58// scene is made of. The sandbox without allow-same-origin gives the
59// document an opaque origin (no cookies, storage, forms, popups or top
60// navigation, nothing of the page around it); default-src 'none' with
61// inline script and style and data:/blob: pictures, fonts and media
62// leaves it no network; frame-ancestors 'self' lets this app's pages,
63// and only them, frame it. TestTheSealedPolicyIsTheOneFramingException
64// keeps the app at three policies with this the only one that frames.
65const SealedPolicy = "sandbox allow-scripts; default-src 'none'; script-src 'unsafe-inline'; " +
66 "style-src 'unsafe-inline'; img-src data: blob:; font-src data:; media-src data: blob:; frame-ancestors 'self'"
67
68// ServeOptions completes opts with what Slides serves: mux (New's), the
69// locales, its error page and its CSP. main passes the result to
70// rastrillo.Serve, and the CSP tests pass it to rastrillo.Handler, so
71// the policy they check is the one production runs under.
72func (a *app) ServeOptions(opts rastrillo.Options, mux *http.ServeMux) rastrillo.Options {
73 opts.Mux = mux
74 // Declaring locales is what installs the middleware rastrillo.T
75 // reads through; without these three every catalog lookup would
76 // return its own key onto the page.
77 opts.Locales = Locales
78 opts.DefaultLocale = DefaultLocale
79 opts.LocaleFS = LocaleFS
80 // The same page a handler's own error path renders (errors.go), so a
81 // panic and a handled failure look identical, with the viewer's own
82 // chrome.
83 opts.ErrorPage = a.ErrorPage
84 opts.CSP = ContentSecurityPolicy
85 return opts
86}
87