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 ¶
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 ¶
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 ¶
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.