csp

package
v0.0.0-...-60192f8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package csp provides simple tools to create and modify a Content Security Policy.

Index

Constants

View Source
const (
	HeaderName = "Content-Security-Policy"

	None          = "'none'"
	Self          = "'self'"
	Data          = "data:"
	ReportSample  = "'report-sample'"
	StrictDynamic = "'strict-dynamic'"
	UnsafeEval    = "'unsafe-eval'"
	UnsafeHashes  = "'unsafe-hashes'"
	UnsafeInline  = "'unsafe-inline'"
)

CSP source values.

Variables

This section is empty.

Functions

func MakeNonce

func MakeNonce() string

MakeNonce returns a random nonce value. It's a 128bit hex string based on a random UUIDv4.

Types

type Policy

type Policy map[string][]string

Policy is a map of CSP directives. It's the same data structure as http.Header, with a different serialization.

func (Policy) Add

func (p Policy) Add(name string, values ...string)

Add adds values to an existing directive, or creates it if it does not exist.

func (Policy) Clone

func (p Policy) Clone() Policy

Clone returns a copy of the policy.

func (Policy) Set

func (p Policy) Set(name string, values ...string)

Set creates or replaces a directive.

func (Policy) String

func (p Policy) String() string

String returns the policy suitable for an http.Header value.

func (Policy) Write

func (p Policy) Write(h http.Header)

Write sets the CSP header to an http.Header.

Jump to

Keyboard shortcuts

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