oficina / docs Public

Share panel: only Sec-Fetch-Dest: empty gets the fragment

An allow-list rather than a deny-list of document: a framed or embedded
?panel=1 gets the page. TestSharePanelOnlyForAScriptsRequest adds
iframe, frame, embed and object, seen to fail on the old check (review
on #106).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev a5191f2f6aa7bb5b1f5aa2aadda30d6cc7476cb7 parent 943babe
2 files changed, +14 −6
  • internal/docs/share_panel.go +7 −5
  • internal/docs/share_panel_test.go +7 −1

CI cancelled — superseded by a newer push — run details

diff --git a/internal/docs/share_panel.go b/internal/docs/share_panel.go
index cfe7677..00cb9c6 100644
--- a/internal/docs/share_panel.go
+++ b/internal/docs/share_panel.go
@@ -26,15 +26,17 @@ import (
// sharePanelRequest reports whether r asks for the panel rather than
// the page: panel=1, in the query or a POST body, and a request a
-// script made. A navigation (Sec-Fetch-Dest: document), or a client
-// that sends no Sec-Fetch-Dest at all, gets the whole page, so a typed,
-// reloaded or bookmarked ?panel=1 is never a bare fragment.
+// script made (Sec-Fetch-Dest: empty, which is what fetch sends). Every
+// other destination gets the whole page: a navigation (document), a
+// frame or embed (iframe, frame, embed, object), and a client that
+// sends no Sec-Fetch-Dest at all. So a typed, reloaded, bookmarked or
+// framed ?panel=1 is never a bare fragment. An allow-list, not a
+// deny-list of "document" (review on #106).
func sharePanelRequest(r *http.Request) bool {
if r.FormValue("panel") != "1" {
return false
}
- dest := r.Header.Get("Sec-Fetch-Dest")
- return dest != "" && dest != "document"
+ return r.Header.Get("Sec-Fetch-Dest") == "empty"
}
// shareBack is where a share mutation's 303 goes: the panel when the
diff --git a/internal/docs/share_panel_test.go b/internal/docs/share_panel_test.go
index 71e9863..cce942e 100644
--- a/internal/docs/share_panel_test.go
+++ b/internal/docs/share_panel_test.go
@@ -49,7 +49,13 @@ func TestSharePanelOnlyForAScriptsRequest(t *testing.T) {
for _, tc := range []struct {
dest string
panel bool
- }{{"empty", true}, {"document", false}, {"", false}} {
+ }{
+ {"empty", true}, {"document", false}, {"", false},
+ // Anything that frames or embeds the URL is a page, not a fetch:
+ // the check is an allow-list of "empty", not a deny-list of
+ // "document" (review on #106).
+ {"iframe", false}, {"frame", false}, {"embed", false}, {"object", false},
+ } {
rec := fetchAs(t, app, alice, http.MethodGet, "/d/"+sqid+"/share?panel=1", "", tc.dest)
if rec.Code != http.StatusOK {
t.Fatalf("dest %q: status %d", tc.dest, rec.Code)