secure

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package secure sets security headers on every response of a Tern app:

ternApp(kit.WithPlugins(secure.New()))

The defaults are safe for most apps: pages cannot be framed by other sites, referrers are trimmed for cross-origin requests, powerful browser features are off, and the page gets its own browsing context group. HTTPS-only (HSTS) is opt-in with HSTS, because it is hard to undo. For a Content-Security-Policy, use kit.WithContentSecurityPolicy, which handles nonces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Plugin)

Option configures the plugin.

func AllowFraming

func AllowFraming() Option

AllowFraming lets same-origin pages frame the app (X-Frame-Options: SAMEORIGIN) instead of forbidding all framing.

func HSTS

func HSTS(maxAge time.Duration, includeSubdomains bool) Option

HSTS tells browsers to use HTTPS only for maxAge, including subdomains when includeSubdomains is set. Only enable it on sites served over HTTPS.

func Header(name, value string) Option

Header sets any header, or removes one of the defaults when value is "".

type Plugin

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

Plugin sets security headers. Create it with New.

func New

func New(opts ...Option) *Plugin

New returns the security headers plugin.

func (*Plugin) Name

func (*Plugin) Name() string

Name implements kit.Plugin.

func (*Plugin) Setup

func (p *Plugin) Setup(s *kit.Setup) error

Setup implements kit.Plugin.

Jump to

Keyboard shortcuts

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