oficina / slides Public

Slides: scene review fixes: messages, preview limit, navigation

Task 3 review, fix round 1.

- Bundle and preview refusals carry a fixed code and a short English
  message for the developer; the editor maps codes to approved words.
- The preview's whole request is capped at 2 MiB + 64 KiB, it takes a
  multipart form as well, and a form with any field but one html is
  refused.
- The hostile scene also navigates its own frame: to another origin
  nothing leaves (the page allows frames from Slides only); to Slides
  the request carries no cookie. docs/scenes.md says so, and that
  navigating ends the scene.
- Fonts are data: URLs only in the docs; the outcome map is logged
  only on failure.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 7214de97e2e85504151404f49805fd4fd4dede63 parent f7deb81
4 files changed, +222 −51
  • docs/scenes.md +17 −6
  • internal/slides/scenes.go +77 −12
  • internal/slidestest/scenes_browser_test.go +59 −6
  • internal/slidestest/scenes_serving_test.go +69 −27
diff --git a/docs/scenes.md b/docs/scenes.md
index cc4fb7a..dee300c 100644
--- a/docs/scenes.md
+++ b/docs/scenes.md
@@ -18,15 +18,16 @@ A scene's code is one HTML document, called its bundle:
- UTF-8, opening with `<!doctype html>` or `<html>` (a byte-order mark
and white space before it are fine);
- at most 2 MiB;
-- every script, style, picture and font inline. Pictures and fonts can
- be `data:` URLs, or `blob:` URLs the script makes.
+- every script, style, picture and font inline. Pictures can be
+ `data:` URLs or `blob:` URLs the script makes; fonts can only be
+ `data:` URLs.
Upload it as you upload a picture ([api.md](api.md#getting-the-bytes-there)),
with `"type": "text/html"`. Registration reads it back, refuses anything
that isn't one HTML document (`not_html`) or is over 2 MiB
(`too_large`), and answers `{"kind": "scene", "ref": "…"}`. That `ref`
is the scene's `code` in `add_scene` or `set_scene`. A bundle refusal
-carries an `error` code and no `message`.
+carries a fixed `error` code and a short English `message` for you.
The bundle is served only to the deck whose scene names it, on the
same three surfaces as its pictures:
@@ -52,10 +53,18 @@ cannot:
- read or write cookies, `localStorage`, `sessionStorage`, IndexedDB or
the Cache API (each throws `SecurityError`);
- submit a form, open a window, or navigate the page it sits in;
+- load a document from another origin into its own frame: the page
+ around it allows frames from Slides only;
- reach the page around it: `parent.document` and `parent.location`
throw;
- use `eval`, `new Function`, workers or WebAssembly.
+Nothing a scene does reaches another origin or carries the reader's
+credentials. It can navigate its own frame to an address on Slides
+itself, and that request goes without the reader's cookies, so it
+reaches only what a stranger could. Navigating its frame ends the
+scene: Slides shows the state's still in its place.
+
What it can do is draw: HTML, CSS, SVG, canvas, WebGL, animations, and
`postMessage` to its parent.
@@ -174,9 +183,11 @@ shows a plain panel with the scene's name and the state's description.
The editor's code panel previews unsaved code by posting it to
`POST /d/{sqid}/scenes/preview`, which answers it under the same
-policy and stores nothing. It takes a `text/html` body or a form with an
-`html` field, at most 2 MiB, from a signed-in person who can open the
-deck.
+policy and stores nothing. It takes a `text/html` body, or a form
+(`multipart/form-data` or url-encoded) with one field, `html`, and no
+other. The text may be 2 MiB and the whole request 2 MiB plus 64 KiB,
+so post a large draft as multipart: url-encoding can triple its size.
+Only a signed-in person who can open the deck gets an answer.
## The example
diff --git a/internal/slides/scenes.go b/internal/slides/scenes.go
index a4b7661..130a85b 100644
--- a/internal/slides/scenes.go
+++ b/internal/slides/scenes.go
@@ -80,11 +80,26 @@ func sniffScene(raw []byte) bool {
return false
}
-// sceneFail is a refusal of a bundle: a fixed code and no words. The
-// editor that shows one (the code panel) brings its own from the
-// catalog; the pictures' messages all say "image".
+// sceneFail is a refusal of a bundle or a preview: a fixed code for a
+// program and a short English sentence for the developer reading the
+// answer, as the core's API diagnostics are. Not catalog words: the
+// editor's code panel will map the codes to its own approved ones; the
+// pictures' catalog messages all say "image".
func sceneFail(w http.ResponseWriter, status int, code string) {
- writeAssetJSON(w, status, map[string]string{"error": code})
+ writeAssetJSON(w, status, map[string]string{"error": code, "message": sceneFailures[code]})
+}
+
+// sceneFailures is the developer's sentence for each code sceneFail
+// answers.
+var sceneFailures = map[string]string{
+ "too_large": "A scene's code may be at most 2 MiB, and a preview request at most 2 MiB plus 64 KiB.",
+ "not_html": "A scene's code must be one UTF-8 HTML document opening with <!doctype html> or <html>.",
+ "not_found": "No upload staged by you for this deck has that ref, or its bytes never arrived.",
+ "hash_mismatch": "The bytes that arrived do not have the hash the upload declared.",
+ "already_verified": "That upload address is already in use.",
+ "unsupported_type": "A preview is text/html, or a form with one field, html.",
+ "invalid": "A preview form carries one field, html, and nothing else.",
+ "internal": "The scene's code could not be stored. Try again.",
}
// registerScene is registerAsset for a receipt staged as text/html: read
@@ -251,12 +266,20 @@ func sealedHeaders(w http.ResponseWriter) {
// --- POST /d/{sqid}/scenes/preview ---
+// maxPreviewRequest is the most a preview request's body may be, however
+// it is encoded: the 2 MiB of text, and 64 KiB for a form's field name,
+// boundaries and part headers. A form posted url-encoded grows with
+// every byte it escapes, so the editor posts its preview as
+// multipart/form-data, which carries the text as it is.
+const maxPreviewRequest = maxSceneBytes + 64<<10
+
// previewScene answers the code panel's unsaved text under the sealed
// policy, so a draft runs exactly as the saved bundle will and is never
// stored. The editor submits a form into a named frame, so the text
-// comes as a form's html field or, from a script, as a text/html body.
-// Signed-in people of the deck only; csrf.Protect has already turned
-// away anything not posted from this app's own pages.
+// comes as a form's one html field (multipart or url-encoded) or, from
+// a script, as a text/html body. Signed-in people of the deck only;
+// csrf.Protect has already turned away anything not posted from this
+// app's own pages.
func (a *app) previewScene(w http.ResponseWriter, r *http.Request) {
u, ok := a.viewer(w, r)
if !ok {
@@ -265,11 +288,11 @@ func (a *app) previewScene(w http.ResponseWriter, r *http.Request) {
if _, ok := a.deckFor(w, r, u); !ok {
return
}
+ r.Body = http.MaxBytesReader(w, r.Body, maxPreviewRequest)
media, _, _ := mime.ParseMediaType(r.Header.Get("Content-Type"))
var html []byte
switch media {
case sceneType:
- r.Body = http.MaxBytesReader(w, r.Body, maxSceneBytes)
body, err := io.ReadAll(r.Body)
if err != nil {
previewFail(w, err)
@@ -277,15 +300,22 @@ func (a *app) previewScene(w http.ResponseWriter, r *http.Request) {
}
html = body
case "application/x-www-form-urlencoded":
- // Percent-encoding at most triples a byte, so this is room for
- // 2 MiB of text however it was encoded; the text itself is held
- // to 2 MiB below.
- r.Body = http.MaxBytesReader(w, r.Body, 3*maxSceneBytes+4<<10)
if err := r.ParseForm(); err != nil {
previewFail(w, err)
return
}
+ if len(r.PostForm) != 1 || len(r.PostForm["html"]) != 1 {
+ sceneFail(w, http.StatusBadRequest, "invalid")
+ return
+ }
html = []byte(r.PostForm.Get("html"))
+ case "multipart/form-data":
+ field, err := previewField(r)
+ if err != nil {
+ previewFail(w, err)
+ return
+ }
+ html = field
default:
sceneFail(w, http.StatusUnsupportedMediaType, "unsupported_type")
return
@@ -309,3 +339,38 @@ func previewFail(w http.ResponseWriter, err error) {
}
sceneFail(w, http.StatusBadRequest, "invalid")
}
+
+// errPreviewFields is a multipart preview with any part but one html.
+var errPreviewFields = errors.New("slides: a preview form carries one field, html")
+
+// previewField reads a multipart preview's one html field, part by part
+// so nothing goes to disk, refusing a form with any other part or a
+// second html.
+func previewField(r *http.Request) ([]byte, error) {
+ parts, err := r.MultipartReader()
+ if err != nil {
+ return nil, err
+ }
+ var html []byte
+ seen := false
+ for {
+ part, err := parts.NextPart()
+ if errors.Is(err, io.EOF) {
+ break
+ }
+ if err != nil {
+ return nil, err
+ }
+ if part.FormName() != "html" || seen {
+ return nil, errPreviewFields
+ }
+ seen = true
+ if html, err = io.ReadAll(part); err != nil {
+ return nil, err
+ }
+ }
+ if !seen {
+ return nil, errPreviewFields
+ }
+ return html, nil
+}
diff --git a/internal/slidestest/scenes_browser_test.go b/internal/slidestest/scenes_browser_test.go
index 99f221a..7b62c85 100644
--- a/internal/slidestest/scenes_browser_test.go
+++ b/internal/slidestest/scenes_browser_test.go
@@ -11,6 +11,7 @@ import (
"context"
"fmt"
"net/http"
+ "net/http/httptest"
"os"
"sort"
"strings"
@@ -30,6 +31,10 @@ import (
// and "reached: ..." when it visibly worked; "tried" is a try whose
// failure only shows outside the frame (the page's URL, the server's
// log), which the test checks there.
+//
+// Framed with ?navigate=URL it tries nothing else: it navigates its own
+// frame to URL, which ends the scene, so each target gets a frame of
+// its own.
const hostileScene = `<!doctype html>
<html><head><meta charset="utf-8"><title>hostile</title></head>
<body><script>
@@ -38,7 +43,9 @@ const wait = (p, ms) => Promise.race([p, new Promise((r) => setTimeout(() => r('
const attempt = async (name, fn) => {
try { out[name] = String(await fn()); } catch (e) { out[name] = 'refused: ' + ((e && e.name) || e); }
};
-(async () => {
+const away = new URLSearchParams(location.search).get('navigate');
+if (away) location = away;
+else (async () => {
await attempt('fetch this app', async () => 'reached: ' + (await fetch('/?scene-probe=fetch')).status);
await attempt('fetch elsewhere', async () => 'reached: ' + (await fetch('https://example.com/?scene-probe=fetch')).status);
await attempt('XMLHttpRequest', () => wait(new Promise((res) => {
@@ -96,7 +103,8 @@ const attempt = async (name, fn) => {
</script></body></html>
`
-// requestLog is every request the server saw, as method and URI.
+// requestLog is every request a server saw, as method, URI and whether
+// it carried a Cookie header: "GET /x?y cookie=false".
type requestLog struct {
mu sync.Mutex
seen []string
@@ -105,7 +113,7 @@ type requestLog struct {
func (l *requestLog) wrap(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
l.mu.Lock()
- l.seen = append(l.seen, r.Method+" "+r.URL.RequestURI())
+ l.seen = append(l.seen, fmt.Sprintf("%s %s cookie=%t", r.Method, r.URL.RequestURI(), r.Header.Get("Cookie") != ""))
l.mu.Unlock()
h.ServeHTTP(w, r)
})
@@ -224,11 +232,13 @@ func TestASceneCannotReachAnything(t *testing.T) {
t.Errorf("%s: %s, want refused", name, got)
}
}
- t.Logf("outcomes: %v", out)
+ if t.Failed() {
+ t.Logf("outcomes: %v", out)
+ }
// The log saw the scene's own document arrive, so it was listening.
- if len(log.matching("/scenes/"+id+"/"+ref)) != 1 {
- t.Errorf("the request log saw the scene's document %d times, want once", len(log.matching("/scenes/"+id+"/"+ref)))
+ if hits := log.matching("/scenes/" + id + "/" + ref + " "); len(hits) != 1 {
+ t.Errorf("the request log saw the scene's document %d times, want once", len(hits))
}
if hits := log.matching("scene-probe"); len(hits) > 0 {
t.Errorf("the server saw requests from the scene: %v", hits)
@@ -245,6 +255,49 @@ func TestASceneCannotReachAnything(t *testing.T) {
if page.DOM != ran.Before.DOM {
t.Errorf("the page's document changed:\nbefore %s\nafter %s", ran.Before.DOM, page.DOM)
}
+
+ // Navigating its own frame ends the scene and reaches no other
+ // origin: the page's own policy (default-src 'self', so frame-src
+ // 'self') refuses the frame a document from elsewhere. Elsewhere is
+ // a server of our own on another origin, so "no request left" is
+ // something the test can see; example.com is tried too.
+ elsewhere := &requestLog{}
+ other := httptest.NewServer(elsewhere.wrap(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Write([]byte("<!doctype html><p>elsewhere</p>"))
+ })))
+ defer other.Close()
+ if strings.HasPrefix(other.URL, rig.Origin) {
+ t.Fatalf("elsewhere %s is the app's own origin", other.URL)
+ }
+ // Same-origin, it reaches Slides and nothing else, and without the
+ // reader's cookies: the scene's origin matches nothing.
+ targets := []string{other.URL + "/?scene-navigate=elsewhere", "https://example.com/?scene-navigate=example", "/?scene-navigate=self"}
+ for _, target := range targets {
+ rig.Run(evalValue(nil, fmt.Sprintf(`new Promise((resolve) => {
+ const f = document.createElement('iframe');
+ f.title = 'scene';
+ f.src = %q + '?navigate=' + encodeURIComponent(%q);
+ document.body.append(f);
+ setTimeout(resolve, 1500);
+ })`, "/d/"+sqid+"/scenes/"+id+"/"+ref, target), awaitPromise))
+ }
+ var url string
+ rig.Run(evalInto(&url, `location.href`), browserCookies(rig.Origin, &after))
+ if hits := elsewhere.matching(""); len(hits) > 0 {
+ t.Errorf("a scene navigating its frame reached another origin: %v", hits)
+ }
+ if hits := log.matching("scene-navigate=example"); len(hits) > 0 {
+ t.Errorf("navigating to example.com came back to the app: %v", hits)
+ }
+ if hits := log.matching("scene-navigate=self"); len(hits) != 1 || !strings.HasSuffix(hits[0], " cookie=false") {
+ t.Errorf("a same-origin self-navigation: the app saw %v, want one request with no Cookie header", hits)
+ }
+ if want := rig.Origin + "/d/" + sqid + "?slide=1"; url != want {
+ t.Errorf("after the navigations the page is at %q, want %q", url, want)
+ }
+ if strings.Join(before, "; ") != strings.Join(after, "; ") {
+ t.Errorf("after the navigations the cookies changed: %v, then %v", before, after)
+ }
}
// TestTheExampleSceneAnswersReady: docs/scenes/example.html, posted to
diff --git a/internal/slidestest/scenes_serving_test.go b/internal/slidestest/scenes_serving_test.go
index dd832ab..f6bf574 100644
--- a/internal/slidestest/scenes_serving_test.go
+++ b/internal/slidestest/scenes_serving_test.go
@@ -9,6 +9,7 @@ package slidestest
import (
"bytes"
"fmt"
+ "mime/multipart"
"net/http"
"net/http/httptest"
"net/url"
@@ -223,21 +224,13 @@ func TestTheBundleMustBeHTML(t *testing.T) {
// Signing refuses a size over the limit before any bytes move.
rec := postJSON(t, a, deck+"/uploads",
fmt.Sprintf(`{"name":"big.html","size":%d,"type":"text/html","hash":%q}`, 2<<20+1, hashOf(sceneBundle)), cookies)
- if rec.Code != http.StatusRequestEntityTooLarge || jsonBody(t, rec)["error"] != "too_large" {
- t.Errorf("signing a 2 MiB + 1 bundle: status %d %s, want 413 too_large", rec.Code, rec.Body)
- }
+ assertRefusal(t, "signing a 2 MiB + 1 bundle", rec, http.StatusRequestEntityTooLarge, "too_large")
refused := func(name string, body []byte) {
t.Helper()
key := stageUpload(t, a, deck, cookies, "x.html", "text/html", body)
reg := postJSON(t, a, deck+"/assets", fmt.Sprintf(`{"ref":%q}`, key), cookies)
- if reg.Code != http.StatusUnprocessableEntity {
- t.Errorf("%s: status %d, want 422\n%s", name, reg.Code, reg.Body)
- return
- }
- if out := jsonBody(t, reg); out["error"] != "not_html" {
- t.Errorf("%s: error = %v, want not_html", name, out["error"])
- }
+ assertRefusal(t, name, reg, http.StatusUnprocessableEntity, "not_html")
}
refused("a PNG", onePixelPNG)
refused("plain text", []byte("hello, world"))
@@ -266,9 +259,7 @@ func TestTheBundleMustBeHTML(t *testing.T) {
big := append([]byte("<!doctype html>"), bytes.Repeat([]byte(" "), 2<<20)...)
signed := jsonBody(t, postJSON(t, a, deck+"/uploads",
fmt.Sprintf(`{"name":"big.html","size":%d,"type":"text/html","hash":%q}`, 100, hashOf(big)), cookies))
- if put := putBytes(t, a, signed["url"].(string), "text/html", big, cookies); put.Code != http.StatusRequestEntityTooLarge {
- t.Errorf("PUT a bundle over 2 MiB: status %d, want 413", put.Code)
- }
+ assertRefusal(t, "PUT a bundle over 2 MiB", putBytes(t, a, signed["url"].(string), "text/html", big, cookies), http.StatusRequestEntityTooLarge, "too_large")
// ...and at registration on a bucket, where the PUT never came here.
store := &presigningStore{Store: dirStore(t)}
b := newAppWithStore(t, store)
@@ -277,9 +268,8 @@ func TestTheBundleMustBeHTML(t *testing.T) {
staged := jsonBody(t, postJSON(t, b, bDeck+"/uploads",
fmt.Sprintf(`{"name":"big.html","size":%d,"type":"text/html","hash":%q}`, 100, hashOf(big)), bCookies))["ref"].(string)
store.putDirect(staged, big)
- if reg := postJSON(t, b, bDeck+"/assets", fmt.Sprintf(`{"ref":%q}`, staged), bCookies); reg.Code != http.StatusRequestEntityTooLarge || jsonBody(t, reg)["error"] != "too_large" {
- t.Errorf("registering a landed bundle over 2 MiB: status %d %s, want 413 too_large", reg.Code, reg.Body)
- }
+ assertRefusal(t, "registering a landed bundle over 2 MiB",
+ postJSON(t, b, bDeck+"/assets", fmt.Sprintf(`{"ref":%q}`, staged), bCookies), http.StatusRequestEntityTooLarge, "too_large")
// And the other way round: an HTML document uploaded as a picture
// is not a picture, even with an <svg> in its head.
@@ -291,11 +281,48 @@ func TestTheBundleMustBeHTML(t *testing.T) {
}
}
+// assertRefusal checks a refusal of a bundle or a preview: the status,
+// a fixed code for a program, and a message for a developer. The
+// editor's words for one come later, from the catalog (Task 6).
+func assertRefusal(t *testing.T, what string, rec *httptest.ResponseRecorder, status int, code string) {
+ t.Helper()
+ if rec.Code != status {
+ t.Errorf("%s: status %d, want %d\n%s", what, rec.Code, status, rec.Body)
+ return
+ }
+ out := jsonBody(t, rec)
+ if out["error"] != code {
+ t.Errorf("%s: error = %v, want %s", what, out["error"], code)
+ }
+ if msg, _ := out["message"].(string); msg == "" || strings.HasPrefix(msg, "slides.") {
+ t.Errorf("%s: message = %q, want a sentence for a developer", what, msg)
+ }
+}
+
+// multipartForm is a form posted as multipart/form-data, as a browser
+// sends one with that enctype: its fields in order, and the
+// Content-Type with the boundary.
+func multipartForm(t *testing.T, fields ...[2]string) (string, []byte) {
+ t.Helper()
+ var buf bytes.Buffer
+ w := multipart.NewWriter(&buf)
+ for _, f := range fields {
+ if err := w.WriteField(f[0], f[1]); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if err := w.Close(); err != nil {
+ t.Fatal(err)
+ }
+ return w.FormDataContentType(), buf.Bytes()
+}
+
// TestThePreviewAnswersUnderTheSealedPolicy: the code panel's preview
-// posts unsaved text, as text/html or as a form's html field (the
+// posts unsaved text, as text/html or as a form's one html field (the
// editor submits a form into a named frame), and gets it back under
// the sealed policy, never cached. Signed-in people of the deck only,
-// same-origin only, 2 MiB at most.
+// same-origin only, the text at most 2 MiB and the whole request at
+// most 2 MiB + 64 KiB.
func TestThePreviewAnswersUnderTheSealedPolicy(t *testing.T) {
a := newSharedApp(t)
cookies := signedIn(t, a, allowedAddress)
@@ -320,12 +347,14 @@ func TestThePreviewAnswersUnderTheSealedPolicy(t *testing.T) {
return rec
}
+ multiType, multiBody := multipartForm(t, [2]string{"html", draft})
for _, c := range []struct {
name, contentType string
body []byte
}{
{"text/html", "text/html; charset=utf-8", []byte(draft)},
{"a form", "application/x-www-form-urlencoded", []byte(url.Values{"html": {draft}}.Encode())},
+ {"a multipart form", multiType, multiBody},
} {
rec := post(c.contentType, c.body, cookies, testOrigin)
if rec.Code != http.StatusOK {
@@ -352,15 +381,28 @@ func TestThePreviewAnswersUnderTheSealedPolicy(t *testing.T) {
t.Errorf("a preview on somebody else's deck: status %d, want 404", rec.Code)
}
big := append([]byte("<!doctype html>"), bytes.Repeat([]byte(" "), 2<<20)...)
- if rec := post("text/html", big, cookies, testOrigin); rec.Code != http.StatusRequestEntityTooLarge {
- t.Errorf("a preview over 2 MiB: status %d, want 413", rec.Code)
- }
- if rec := post("application/x-www-form-urlencoded", []byte(url.Values{"html": {string(big)}}.Encode()), cookies, testOrigin); rec.Code != http.StatusRequestEntityTooLarge {
- t.Errorf("a form preview over 2 MiB: status %d, want 413", rec.Code)
- }
- if rec := post("application/json", []byte(`{"html":"x"}`), cookies, testOrigin); rec.Code != http.StatusUnsupportedMediaType {
- t.Errorf("a JSON preview: status %d, want 415", rec.Code)
- }
+ assertRefusal(t, "a preview over 2 MiB", post("text/html", big, cookies, testOrigin), http.StatusRequestEntityTooLarge, "too_large")
+ assertRefusal(t, "a form preview over 2 MiB",
+ post("application/x-www-form-urlencoded", []byte(url.Values{"html": {string(big)}}.Encode()), cookies, testOrigin),
+ http.StatusRequestEntityTooLarge, "too_large")
+ bigType, bigBody := multipartForm(t, [2]string{"html", string(big)})
+ assertRefusal(t, "a multipart preview over 2 MiB", post(bigType, bigBody, cookies, testOrigin), http.StatusRequestEntityTooLarge, "too_large")
+ // The whole request is held to 2 MiB + 64 KiB, whatever it decodes
+ // to: a form of 1 MiB of text, percent-encoded to three times that,
+ // is refused before it is read.
+ wide := strings.Repeat("<", 1<<20)
+ assertRefusal(t, "a form whose encoding is over the request limit",
+ post("application/x-www-form-urlencoded", []byte(url.Values{"html": {wide}}.Encode()), cookies, testOrigin),
+ http.StatusRequestEntityTooLarge, "too_large")
+ // A form carries the html field and nothing else.
+ assertRefusal(t, "a form with another field",
+ post("application/x-www-form-urlencoded", []byte(url.Values{"html": {draft}, "other": {"x"}}.Encode()), cookies, testOrigin),
+ http.StatusBadRequest, "invalid")
+ otherType, otherBody := multipartForm(t, [2]string{"html", draft}, [2]string{"other", "x"})
+ assertRefusal(t, "a multipart form with another field", post(otherType, otherBody, cookies, testOrigin), http.StatusBadRequest, "invalid")
+ twiceType, twiceBody := multipartForm(t, [2]string{"html", draft}, [2]string{"html", draft})
+ assertRefusal(t, "a multipart form with html twice", post(twiceType, twiceBody, cookies, testOrigin), http.StatusBadRequest, "invalid")
+ assertRefusal(t, "a JSON preview", post("application/json", []byte(`{"html":"x"}`), cookies, testOrigin), http.StatusUnsupportedMediaType, "unsupported_type")
if !strings.Contains(sealedPolicy, "sandbox allow-scripts;") {
t.Fatal("the sealed policy lost its sandbox")
}