secureecho

package
v0.0.0-...-6774cfe Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package secureecho wires a complete set of hardening middlewares into an Echo server. It is intended for “localhost” utility apps that handle personal data.

go get github.com/you/secureecho

Usage:

e := echo.New()
opts := secureecho.Options{
    AllowedHosts: []string{"localhost:8585", "127.0.0.1:8585"},
    Auth: secureecho.BasicAuth("admin", "S3cret!"), // or secureecho.APIKeyAuth("X-My-Token", "abcd")
}
secureecho.Harden(e, opts)

if err := secureecho.StartLocal(e, ":8585"); err != nil {
    e.Logger.Fatal(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIKeyAuth

func APIKeyAuth(headerName, token string) echo.MiddlewareFunc

APIKeyAuth enforces a constant token in a header (or query param).

func BasicAuth

func BasicAuth(user, pass string) echo.MiddlewareFunc

BasicAuth returns a middleware that enforces a fixed username/password.

func Harden

func Harden(e *echo.Echo, o Options)

Harden attaches all middlewares to the supplied Echo instance.

func StartLocal

func StartLocal(e *echo.Echo, addr string) error

StartLocal is a helper that refuses to listen on non‑loopback addresses.

func StartLocalTLS

func StartLocalTLS(e *echo.Echo, addr, certFile, keyFile string) error

StartLocalTLS is the same as StartLocal but serves HTTPS.

Types

type Options

type Options struct {
	// AllowedHosts are the only Host header values accepted (anti‑DNS‑rebinding).
	// If empty, defaults to localhost on any port.
	AllowedHosts []string

	// Auth provides a middleware factory implementing the authentication layer.
	// Use BasicAuth(), APIKeyAuth(), or nil to disable (NOT recommended).
	Auth echo.MiddlewareFunc

	// EnableCSRF allows you to turn CSRF protection off; default true.
	EnableCSRF bool

	// CORSOrigins lists origins to allow.  Leave nil/empty to deny all cross‑origin reads.
	CORSOrigins []string
}

Options groups all configurable pieces.

Jump to

Keyboard shortcuts

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