origins

package
v0.1.3 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 a data structure 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)

Add augments c with all Web origins encompassed by pattern.

func (Corpus) Contains

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

Contains reports whether c contains origin o.

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 string      // Value is the host pattern's raw value.
	Kind  PatternKind // Kind is the host pattern's kind.
}

A HostPattern represents a host pattern.

func (*HostPattern) IsIP

func (hp *HostPattern) IsIP() bool

IsIP reports whether the host of p is an IP address (as opposed to a domain).

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(str string) (Origin, bool)

Parse parses str 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

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
}

A Pattern represents an origin pattern.

func ParsePattern

func ParsePattern(str string) (Pattern, error)

ParsePattern parses str into a Pattern structure.

func (*Pattern) HostIsEffectiveTLD

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

HostIsEffectiveTLD, if the host of p is an effective top-level domain (eTLD), also known as public suffix, returns the eTLD in question and true. Otherwise, HostIsEffectiveTLD returns the empty string and false.

func (*Pattern) IsDeemedInsecure

func (p *Pattern) IsDeemedInsecure() bool

IsDeemedInsecure returns true if any of the following conditions is fulfilled:

  • p's scheme is not https,
  • p's host is not a loopback IP address,
  • p's host is not localhost.

Otherwise, IsDeemedInsecure returns false.

type PatternKind

type PatternKind uint8

PatternKind represents the kind of a host pattern.

const (
	PatternKindDomain        PatternKind = iota // domain
	PatternKindNonLoopbackIP                    // non-loopback IP address
	PatternKindLoopbackIP                       // loopback IP address
	PatternKindSubdomains                       // arbitrary subdomains
)

Directories

Path Synopsis
Package radix provides an implementation of a specialized radix tree.
Package radix provides an implementation of a specialized radix tree.

Jump to

Keyboard shortcuts

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