securityprofile

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package securityprofile provides security posture defaults.

Package securityprofile composes secure middleware defaults. EXPERIMENTAL: This package is not yet API-stable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorWriter

type ErrorWriter func(http.ResponseWriter, int, httpx.Problem)

ErrorWriter allows overriding how security profile errors are written.

type Option

type Option func(*options)

Option customizes the security profile.

func WithAuthAllowlist

func WithAuthAllowlist(paths ...string) Option

WithAuthAllowlist sets paths that bypass auth checks.

func WithAuthCheck

func WithAuthCheck(fn func(*http.Request) bool) Option

WithAuthCheck sets a function that determines whether a request is authenticated.

func WithDevBypassHeader

func WithDevBypassHeader(header string, allow bool) Option

WithDevBypassHeader sets a development-only auth bypass header.

func WithErrorWriter

func WithErrorWriter(fn ErrorWriter) Option

WithErrorWriter overrides the error writer.

func WithMaxBodyBytes

func WithMaxBodyBytes(n int64) Option

WithMaxBodyBytes sets the maximum request body size.

func WithQueryLimits

func WithQueryLimits(opts querylimits.Options) Option

WithQueryLimits overrides query limits middleware options.

func WithQueryLimitsDisabled

func WithQueryLimitsDisabled() Option

WithQueryLimitsDisabled disables query limits enforcement.

func WithRateLimitDisabled

func WithRateLimitDisabled() Option

WithRateLimitDisabled disables rate limiting.

func WithRateLimitOptions

func WithRateLimitOptions(opts ratelimit.Options) Option

WithRateLimitOptions configures rate limiting options.

func WithRequireAuth

func WithRequireAuth(required bool) Option

WithRequireAuth sets whether authentication is required by default.

func WithResolver

func WithResolver(resolver identity.Resolver) Option

WithResolver sets the identity resolver for trusted proxy checks.

func WithRouteOverrides

func WithRouteOverrides(overrides ...RouteOverride) Option

WithRouteOverrides sets per-route limit overrides.

func WithSecureOptions

func WithSecureOptions(opts ...securemw.Option) Option

WithSecureOptions appends secure header middleware options.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets a per-request timeout.

func WithTimeoutDisabled

func WithTimeoutDisabled() Option

WithTimeoutDisabled disables request timeouts.

type Profile

type Profile struct {
	Middlewares []func(http.Handler) http.Handler
}

Profile describes a composed security middleware stack.

func New

func New(opts ...Option) (Profile, error)

New builds a security profile using the provided options.

func OWASPBaseline

func OWASPBaseline(opts ...Option) (Profile, error)

OWASPBaseline returns a security profile that aligns with OWASP API resource limits.

func (Profile) Apply

func (p Profile) Apply(r ports.HTTPRouter)

Apply attaches the profile middlewares to the router.

type RouteOverride

type RouteOverride struct {
	Pattern string
	Methods []string

	MaxBodyBytes       *int64
	QueryLimits        *querylimits.Options
	QueryLimitsEnabled *bool
	Timeout            *time.Duration
	TimeoutEnabled     *bool
	RateLimit          *ratelimit.Options
	RateLimitEnabled   *bool
}

RouteOverride customizes limits for matching requests.

Jump to

Keyboard shortcuts

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