Help us shape the future of Go! Take the 2026 Go Developer Survey

web

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package web serves the embedded single-page app and sets security headers.

Index

Constants

View Source
const ContentSecurityPolicy = "default-src 'self'; " +
	"script-src 'self'; " +
	"style-src 'self' 'unsafe-inline'; " +
	"img-src 'self' data: https:; " +
	"font-src 'self' data:; " +
	"connect-src 'self'%s; " +
	"worker-src 'self' blob:; " +
	"child-src 'self' blob:; " +
	"object-src 'none'; " +
	"base-uri 'self'; " +
	"form-action 'self'; " +
	"frame-ancestors 'none'"

ContentSecurityPolicy is applied to every response. Scripts must come from our origin only; inline styles are allowed because Radix/sonner set them at runtime. Avatars may be loaded from IdPs over https. Workers may be spawned from self or blob: URLs (e.g. browser extensions, client background jobs). connect-src is completed per request (see SecurityHeaders): same-origin WebSockets for the web client, plus configured hbbs/hbbr WebSocket origins.

Variables

This section is empty.

Functions

func SecurityHeaders

func SecurityHeaders(hsts bool, connect ConnectSources) func(http.Handler) http.Handler

SecurityHeaders sets defensive headers on every response. HSTS is only sent when the panel is served over https (public URL scheme).

func WSOrigin added in v0.11.0

func WSOrigin(raw string) string

WSOrigin returns the ws(s)://host[:port] origin of a WebSocket URL, or "".

Types

type ConnectSources added in v0.12.0

type ConnectSources struct {
	// Origins are WebSocket URLs (only their ws(s)://host[:port] is used).
	Origins []string
	// AnyWSS allows every wss: origin (users may enter their own servers).
	AnyWSS bool
}

ConnectSources are the extra places the web client may open WebSockets to.

type SPA

type SPA struct {
	// contains filtered or unexported fields
}

SPA serves static files from fsys with an index.html fallback for client routes. Hashed assets under /assets/ are cached immutably; index.html is never cached so deployments take effect immediately.

func NewSPA

func NewSPA(fsys fs.FS) *SPA

NewSPA builds the handler. When fsys has no index.html (UI not built), a placeholder page is served instead.

func (*SPA) Built

func (s *SPA) Built() bool

Built reports whether a real UI build is embedded.

func (*SPA) ServeHTTP

func (s *SPA) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL