security

package
v1.80.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package security is the dashboard + per-route surface for nexus's two web-security defenses — security response headers and CSRF.

GLOBAL enforcement does NOT live here. The framework applies security headers by default and enables CSRF from [runtime.middleware.security] in nexus.toml (see nexus.Config's Middleware.Security field) — no Go required, and no risk of the middleware being installed twice. This package adds the two things the core path can't:

  1. Plugin() — a dashboard "Security" tab showing what's active.
  2. NewHeadersMiddleware / NewCSRFMiddleware — per-route bundles for an app that mixes cookie-authenticated and stateless-token routes.

The header/CSRF logic itself lives in middleware/secure, shared with the framework core. The config types below are aliases of that package.

CSRF uses the double-submit-cookie pattern with the same cookie/header names (csrftoken / X-CSRFToken) the generated client SDK already uses, so an existing frontend needs no change.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Module added in v1.44.0

func Module() nexus.Option

Plugin adds a dashboard "Security" tab that reports whether the built-in headers / CSRF middleware are active. It installs no global middleware — configure that via [runtime.middleware.security] in nexus.toml (or Config.Middleware.Security). Load this only for the dashboard surface. Module is the canonical entry point, matching every configurable nexus extension (auth.Module, maskid.Module, oauth2.Module, …). Plugin remains as an alias.

func NewCSRFMiddleware

func NewCSRFMiddleware(cfg CSRFConfig) middleware.Middleware

NewCSRFMiddleware returns the CSRF check as a per-route bundle. Use when only some routes are cookie-authenticated and the rest are a stateless token API you'd rather not touch. A token size below the safe minimum yields an always-500 guard so the misconfig is loud.

func NewHeadersMiddleware

func NewHeadersMiddleware(cfg HeadersConfig) middleware.Middleware

NewHeadersMiddleware returns the security-headers middleware as a per-route bundle, for a subset of routes needing a different header policy than the global one.

func Plugin

func Plugin() nexus.Option

Types

type CSRFConfig

type CSRFConfig = secure.CSRFConfig

The config types are aliases of the shared secure package, so callers import only this package while the implementation stays single-sourced.

type HSTSConfig

type HSTSConfig = secure.HSTSConfig

The config types are aliases of the shared secure package, so callers import only this package while the implementation stays single-sourced.

type HeadersConfig

type HeadersConfig = secure.HeadersConfig

The config types are aliases of the shared secure package, so callers import only this package while the implementation stays single-sourced.

Jump to

Keyboard shortcuts

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