origin

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package origin implements parsing of origins and origin patterns and provides data structures useful for representing a set of origins.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Corpus

type Corpus map[string]radix.Tree

A Corpus represents a set of allowed (tuple) [Web origins]. The keys in this map correspond to origin schemes.

func (Corpus) Add

func (c Corpus) Add(pattern *Pattern)

func (Corpus) Contains

func (c Corpus) Contains(o *Origin) bool

type Host

type Host struct {
	// Value is the origin's raw host.
	Value string
	// AssumeIP indicates whether the origin's host
	// should be treated as an IP address.
	AssumeIP bool
}

Host represents a host, whether it be an IP address or a domain.

type HostPattern

type HostPattern struct {
	// Value is the host pattern's raw value.
	Value string
	// Kind is the host pattern's kind.
	Kind PatternKind
}

func (*HostPattern) IsIP

func (p *HostPattern) IsIP() bool

type Origin

type Origin struct {
	// Scheme is the origin's scheme.
	Scheme string
	// Host is the origin's host.
	Host
	// Port is the origin's port (if any).
	// The zero value marks the absence of an explicit port.
	Port int
}

Origin represents a (tuple) Web origin.

func Parse

func Parse(s string) (Origin, bool)

Parse parses a raw Web origin into an Origin structure. It is lenient insofar as it performs just enough validation for Corpus.Contains to know what to do with the resulting Origin value. In particular, the scheme and port of the resulting origin are guaranteed to be valid, but its host isn't.

type Pattern added in v0.9.0

type Pattern struct {
	// Scheme is the origin pattern's scheme.
	Scheme string
	// Scheme is the origin pattern's host pattern.
	HostPattern
	// Port is the origin pattern's port number (if any).
	// 0 is used as a sentinel value marking the absence of an explicit port.
	// -1 is used as a sentinel value to indicate that all ports are allowed.
	Port int
}

func ParsePattern added in v0.9.0

func ParsePattern(s string) (*Pattern, error)

func (*Pattern) HostIsEffectiveTLD added in v0.9.0

func (s *Pattern) HostIsEffectiveTLD() (string, bool)

func (*Pattern) IsDeemedInsecure added in v0.9.0

func (s *Pattern) IsDeemedInsecure() bool

type PatternKind added in v0.9.0

type PatternKind uint8

PatternKind represents the kind of a host pattern.

const (
	// domain
	PatternKindDomain PatternKind = iota
	// non-loopback IP address
	PatternKindNonLoopbackIP
	// loopback IP address
	PatternKindLoopbackIP
	// arbitrary subdomains of depth one or more
	PatternKindSubdomains
)

Jump to

Keyboard shortcuts

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