openredirect

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package openredirect validates `next=` style redirect targets so a crafted query parameter can't bounce a logged-in user off-host (the canonical phishing primitive). The Safe predicate accepts:

  • relative paths starting with a single `/` (not `//`, not `/\`)
  • absolute URLs whose host matches an operator-approved allow-list

Anything else is rejected. Callers fall back to a known-safe default (typically `/`) on rejection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// AllowedHosts is the exact, case-insensitive host allow-list
	// for absolute redirect targets. Typical content: the deployment's
	// canonical hostname plus any apex/www variants. Empty disables
	// absolute-URL redirects entirely.
	AllowedHosts []string
}

Config governs which absolute redirect targets are allowed. The zero value accepts only relative paths — the safest default for most surfaces.

func (Config) Safe

func (cfg Config) Safe(candidate string) bool

Safe reports whether candidate is a safe redirect target under cfg. Empty input returns false; callers should pre-screen and substitute the default themselves.

func (Config) SafeOr

func (cfg Config) SafeOr(candidate, fallback string) string

SafeOr returns candidate when Safe(candidate), otherwise fallback. The single-call convenience for handlers that want to default to `/` after rejection.

Jump to

Keyboard shortcuts

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