Add WordCraft and DeckCraft office editors with protected server saves

This commit is contained in:
SantaSpeen committed 2026-10-22 19:25:22 +03:00
1 parent bc9709e500
commit 6e36b6c4b7
20 files changed
+582 -40

No files matched your search

+29 -2
View File
@@ -1,7 +1,9 @@
package fbhttp
import (
"bytes"
"encoding/json"
"io"
"net/http"
"os"
"path"
@@ -84,12 +86,18 @@ func addonStaticHandler(manager *addons.Manager) handleFunc {
if !ok {
return http.StatusNotFound, nil
}
file, err := manager.Open(id, vars["build"], name)
bridge := needsOfficeBridge(id) && name == "filebrowser-bridge.js"
lookup := name
if bridge {
lookup = "index.html"
}
file, err := manager.Open(id, vars["build"], lookup)
if err != nil {
return http.StatusNotFound, nil
}
defer file.Close()
if acceptsAddonGzip(r.Header.Get("Accept-Encoding")) {
adaptIndex := needsOfficeBridge(id) && name == "index.html" && r.URL.Query().Get("host") == "parent"
if !bridge && !adaptIndex && acceptsAddonGzip(r.Header.Get("Accept-Encoding")) {
if compressed, e := manager.Open(id, vars["build"], name+".gz"); e == nil {
file.Close()
file = compressed
@@ -107,6 +115,25 @@ func addonStaticHandler(manager *addons.Manager) handleFunc {
w.Header().Set("Cache-Control", "private, max-age=86400")
// Only installed, checksum-verified vendor pages get WASM and framing permissions.
w.Header().Set("Content-Security-Policy", `default-src 'self'; script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; connect-src 'self'; worker-src 'self' blob:; media-src 'self' blob:; frame-src 'none'; object-src 'none'; base-uri 'self'; frame-ancestors 'self'`)
if bridge {
w.Header().Set("Cache-Control", "no-store")
http.ServeContent(w, r, name, info.ModTime(), bytes.NewReader(officeBridge))
return 0, nil
}
if adaptIndex {
content, readErr := io.ReadAll(io.LimitReader(file, (4<<20)+1))
if readErr != nil || len(content) > 4<<20 {
return http.StatusUnprocessableEntity, readErr
}
marker := []byte("</head>")
if !bytes.Contains(content, marker) {
return http.StatusUnprocessableEntity, nil
}
content = bytes.Replace(content, marker, []byte(`<script src="./filebrowser-bridge.js"></script></head>`), 1)
w.Header().Set("Cache-Control", "no-store")
http.ServeContent(w, r, name, info.ModTime(), bytes.NewReader(content))
return 0, nil
}
http.ServeContent(w, r, name, info.ModTime(), file)
return 0, nil
})