Documentation
¶
Overview ¶
Package embedhosts is the list of origins an HTML asset may frame and load media from (#2069): a video player (Wistia, a deployment's own) or the CDN a clip is served from. The share viewer's Content-Security-Policy and the portal's asset frame both read it, so a clip that plays in the portal plays on a share link, and one removed from the list is blocked on both.
The list is written into a policy, so each entry is held to the one form a policy source takes for a host: https, a host name or a leading `*.` label, an optional port, and nothing else. Anything that could end a directive or widen the policy is refused by name.
Index ¶
- Constants
- Variables
- func Defaults() []string
- func From(ctx context.Context, read func(context.Context) []string) []string
- func Normalize(entries []string) ([]string, error)
- func RegisterSettings(mux *http.ServeMux, wrap func(http.Handler) http.Handler, r *Resolver, ...)
- func Sources(hosts []string) string
- type Config
- type InvalidError
- type Request
- type Resolver
- type Response
- type Section
- type Settings
Constants ¶
const MaxHosts = 50
MaxHosts bounds the list, so the policy header it is written into stays a header.
const SettingsSection = "portal_embeds"
SettingsSection is the platform_settings section an administrator's list is stored under.
Variables ¶
var Default = []string{
"https://fast.wistia.net",
"https://fast.wistia.com",
"https://www.youtube-nocookie.com",
"https://www.youtube.com",
"https://player.vimeo.com",
}
Default is the list a deployment that sets none gets: the Wistia player, which plays inside the asset frame, and the YouTube and Vimeo players, which do not run in its opaque origin and draw as a link card instead (#2069, #2396). Listing them keeps a card's poster and an embed that a later frame can play under one setting.
var ErrInvalid = errors.New("invalid embed host")
ErrInvalid is what every refusal of an entry is (errors.Is).
Functions ¶
func Defaults ¶
func Defaults() []string
Defaults returns a copy of Default, so a caller cannot change it.
func From ¶
From is the list a reader function gives, the default when there is no reader, and never nil, so a list turned off reads as [].
func Normalize ¶
Normalize returns the list in its stored form, each entry `https://host[:port]`, lower case, without duplicates and in the order given. A bare host gains the https scheme. An empty list is valid and turns embeds off.
Types ¶
type Config ¶
type Config struct {
Hosts *[]string `yaml:"hosts"`
}
Config is the `portal.embeds` section of the configuration file. Hosts nil takes Default; an empty list turns embeds off. An administrator's list, once written, is used instead.
func (Config) Configured ¶
Configured returns the configured list in its stored form, or Default when none is configured. An invalid list, which Validate refused at startup, returns Default.
type InvalidError ¶
InvalidError is the refusal of one entry, or of the list when Entry is empty, naming what is wrong with it.
func (*InvalidError) Error ¶
func (e *InvalidError) Error() string
func (*InvalidError) Is ¶
func (*InvalidError) Is(target error) bool
Is reports that the refusal is an ErrInvalid.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver answers the list in force: the administrator's, else the configuration file's, else Default.
func NewResolver ¶
NewResolver builds a resolver over the stored section (nil reads none) and the configuration file's section.
func (*Resolver) Configured ¶
Configured is the list the configuration file gives, which an administrator's list replaces.
type Response ¶
type Response struct {
// Hosts is the list in force.
Hosts []string `json:"hosts" example:"https://fast.wistia.net,https://cdn.example.com"`
// Configured is the list the configuration file gives (portal.embeds.hosts,
// else the platform's default), which a saved list replaces.
Configured []string `json:"configured" example:"https://fast.wistia.net"`
}
Response is what the settings routes answer.
type Section ¶
type Section interface {
// Read returns the stored settings and whether an administrator has
// written them.
Read(ctx context.Context) (Settings, bool, error)
Write(ctx context.Context, s Settings, author string) error
}
Section is the stored administrator list as the resolver reads and writes it. settingsjson.Section satisfies it through an adapter in the wiring.