policy

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package policy decides whether a document or frame may use camera, microphone and display capture under Permissions-Policy (the response header) and the iframe allow attribute.

Rules implemented (Permissions Policy spec, the parts these three features need): the default allowlist is 'self'; the header can widen it to "*" or a list of origins or close it with (); a cross-origin frame may use a feature only when its parent's policy allows the frame's origin AND the iframe's allow attribute names the feature (bare name means 'src', the frame's own origin).

Note on this engine: iframes do not run scripts yet, so only the top-level document ever asks. FrameAllowed is the rule the engine will apply when frames get their own JavaScript; it is tested here so that does not have to be written later under pressure.

Index

Constants

View Source
const (
	Camera         = "camera"
	Microphone     = "microphone"
	DisplayCapture = "display-capture"
)

Features this package knows by their policy names.

Variables

This section is empty.

Functions

func FrameAllowed

func FrameAllowed(feature string, parent Policy, parentOrigin string, attr AllowAttr, frameOrigin, srcOrigin string, frame Policy) bool

FrameAllowed decides for a frame whose document origin is frameOrigin and whose <iframe src> origin is srcOrigin. parent is the parent document's header policy and parentOrigin its origin.

Types

type AllowAttr

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

AllowAttr is a parsed iframe allow attribute.

func ParseAllowAttr

func ParseAllowAttr(attr string) AllowAttr

ParseAllowAttr parses allow="camera; microphone 'none'; display-capture https://meet.example".

type Policy

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

Policy is a parsed Permissions-Policy header: for each feature, its allowlist.

func ParseHeader

func ParseHeader(h string) Policy

ParseHeader reads a Permissions-Policy header value ("camera=(self \"https://a.example\"), microphone=()"). The legacy Feature-Policy syntax ("camera 'self' https://a.example; microphone 'none'") is accepted too. Unknown features are ignored.

func (Policy) Allowed

func (p Policy) Allowed(feature, origin string) bool

Allowed reports whether the document at origin may use feature under its own header policy.

Jump to

Keyboard shortcuts

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