Documentation
¶
Overview ¶
Package cspbuilder provides helper funcs to create Content Security Policy
Index ¶
- Constants
- Variables
- func SetNoncePlaceholder(ph string)
- type Directive
- type HashType
- type Policy
- func (pp *Policy) Build() string
- func (pp *Policy) Map() map[string]string
- func (pp *Policy) MergeBuild(dirs map[string]*Directive) string
- func (pp *Policy) New(name string, sources ...string) *Directive
- func (pp *Policy) Remove(name string)
- func (pp *Policy) With(name string, d *Directive) *Policy
- func (pp *Policy) WithNonce(nonce *string) string
Constants ¶
View Source
const ( // csp v1 Default = "default-src" Connect = "connect-src" Font = "font-src" Frame = "frame-src" Img = "img-src" Media = "media-src" Object = "object-src" Sandbox = "sandbox" Script = "script-src" Style = "style-src" // csp v2 BaseURI = "base-uri" Child = "child-src" FrameAncestors = "frame-ancestors" Plugin = "plugin-types" Form = "form-action" // csp v3 TrustedTypes = "trusted-types" RequireTrustedTypesFor = "require-trusted-types-for" StyleAttr = "style-src-attr" StyleElem = "style-src-elem" ScriptAttr = "script-src-attr" ScriptElem = "script-src-elem" Worker = "worker-src" Prefetch = "prefetch-src" Manifest = "manifest-src" ReportTo = "report-to" SHA256 HashType = 256 SHA384 HashType = 384 SHA512 HashType = 512 )
View Source
const ( None = "'none'" All = "*" Self = "'self'" StrictDynamic = "'strict-dynamic'" UnsafeEval = "'unsafe-eval'" UnsafeInline = "'unsafe-inline'" UnsafeHashes = "'unsafe-hashes'" UnsafeAllowRedirects = "'unsafe-allow-redirects'" ReportSample = "'report-sample'" TrustedScript = "'script'" Blob = "blob:" Data = "data:" Mediastream = "mediastream:" Filesystem = "filesystem:" )
Keyword sources
Variables ¶
Functions ¶
func SetNoncePlaceholder ¶
func SetNoncePlaceholder(ph string)
SetNoncePlaceholder changes the nonce placeholder value $NONCE to your csp middleware's.
Types ¶
type Directive ¶
type Directive struct {
// contains filtered or unexported fields
}
type Policy ¶
type Policy struct { // ReportURI appends "report-uri <string>" ReportURI string // Compiled policy after running Build() Compiled string // UpgradeInsecureRequests appends "'upgrade-insecure-requests'" UpgradeInsecureRequests bool // RequireNonce is set if policy must run WithNonce() RequireNonce bool // contains filtered or unexported fields }
func Starter ¶
func Starter() *Policy
Starter creates new policy with sensible defaults default-src 'none'; script-src 'self'; connect-src 'self'; img-src 'self'; style-src 'self'; base-uri 'self';form-action 'self' https://content-security-policy.com/
func (*Policy) Map ¶
Map exports directives as map[string]string. Does not include nonce source. Meant for middleware like gin-helmet that can only emit static csp strings
func (*Policy) MergeBuild ¶ added in v0.2.0
Directories
¶
Path | Synopsis |
---|---|
Package m provides gin middleware with Content Security Policy
|
Package m provides gin middleware with Content Security Policy |
gincsp
Package gincsp is a gin middleware that supports Content Security Policy
|
Package gincsp is a gin middleware that supports Content Security Policy |
Click to show internal directories.
Click to hide internal directories.