Help us shape the future of Go! Take the 2026 Go Developer Survey

security

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSecureCookie

func NewSecureCookie(name, value string, options CookieOptions) *http.Cookie

NewSecureCookie creates a cookie with secure defaults.

func SetSecureCookie

func SetSecureCookie(w http.ResponseWriter, name, value string, options CookieOptions)

SetSecureCookie writes a secure cookie to the response.

Types

type CSP

type CSP struct {
	// contains filtered or unexported fields
}

CSP builds a Content-Security-Policy header value.

func NewCSP

func NewCSP() *CSP

NewCSP creates a CSP builder.

func (*CSP) Add

func (c *CSP) Add(directive string, values ...string) *CSP

Add appends values to an existing directive.

func (*CSP) BaseURI

func (c *CSP) BaseURI(values ...string) *CSP

BaseURI sets the base-uri directive.

func (*CSP) ConnectSrc

func (c *CSP) ConnectSrc(values ...string) *CSP

ConnectSrc sets the connect-src directive.

func (*CSP) DefaultSrc

func (c *CSP) DefaultSrc(values ...string) *CSP

DefaultSrc sets the default-src directive.

func (*CSP) FontSrc

func (c *CSP) FontSrc(values ...string) *CSP

FontSrc sets the font-src directive.

func (*CSP) FormAction

func (c *CSP) FormAction(values ...string) *CSP

FormAction sets the form-action directive.

func (*CSP) FrameAncestors

func (c *CSP) FrameAncestors(values ...string) *CSP

FrameAncestors sets the frame-ancestors directive.

func (*CSP) ImgSrc

func (c *CSP) ImgSrc(values ...string) *CSP

ImgSrc sets the img-src directive.

func (*CSP) ObjectSrc

func (c *CSP) ObjectSrc(values ...string) *CSP

ObjectSrc sets the object-src directive.

func (*CSP) ScriptSrc

func (c *CSP) ScriptSrc(values ...string) *CSP

ScriptSrc sets the script-src directive.

func (*CSP) Set

func (c *CSP) Set(directive string, values ...string) *CSP

Set replaces a directive with the provided values.

func (*CSP) String

func (c *CSP) String() string

String returns the policy string.

func (*CSP) StyleSrc

func (c *CSP) StyleSrc(values ...string) *CSP

StyleSrc sets the style-src directive.

func (*CSP) UpgradeInsecureRequests

func (c *CSP) UpgradeInsecureRequests() *CSP

UpgradeInsecureRequests adds the upgrade-insecure-requests directive.

type CookieOptions

type CookieOptions struct {
	DisableDefaults bool
	Path            string
	Domain          string
	MaxAge          int
	Expires         time.Time
	Secure          bool
	HTTPOnly        bool
	SameSite        http.SameSite
	Partitioned     bool
}

CookieOptions configures secure cookie defaults.

Jump to

Keyboard shortcuts

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