httpsec

package
v2.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package httpsec holds the Secure cookie rewriting and the Origin allowlist check.

Index

Constants

View Source
const SecureCookieAttr = "Secure"

SecureCookieAttr is the cookie attribute CookieWriter appends.

Variables

This section is empty.

Functions

func NormalizeOrigins

func NormalizeOrigins(in []string) ([]string, error)

NormalizeOrigins canonicalizes Config.TrustedOrigins entries.

func OriginAllowed

func OriginAllowed(r *http.Request, baseURL string, trusted []string) bool

OriginAllowed implements the CSRF defence for cookie-authenticated state-changing requests. Safe methods and bearer-token requests are exempt. A request that carries cookies must present an Origin (or Referer) in the trusted set; with neither header, Sec-Fetch-Site decides when the browser sent it. SameSite=Lax alone does not stop sibling subdomains, which are same-site.

Types

type CookieWriter

type CookieWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

CookieWriter adds the Secure attribute to every Set-Cookie header at write time, so handlers in internal packages need no per-request flag.

func NewCookieWriter

func NewCookieWriter(w http.ResponseWriter) *CookieWriter

NewCookieWriter wraps w so every Set-Cookie carries Secure.

func (*CookieWriter) Flush

func (w *CookieWriter) Flush()

func (*CookieWriter) Unwrap

func (w *CookieWriter) Unwrap() http.ResponseWriter

Unwrap lets http.ResponseController reach Hijack and deadlines.

func (*CookieWriter) Write

func (w *CookieWriter) Write(b []byte) (int, error)

func (*CookieWriter) WriteHeader

func (w *CookieWriter) WriteHeader(code int)

Jump to

Keyboard shortcuts

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