middleware

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: GPL-3.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DomainValidator

func DomainValidator(domain string) gin.HandlerFunc

func SameOrigin added in v1.8.2

func SameOrigin(opt Options) gin.HandlerFunc

Mounted on the cookie-authenticated group only. apiv2 authenticates with a Token header, which a cross-site page cannot set without a CORS preflight the panel never answers.

Types

type Options added in v1.8.2

type Options struct {
	// BehindProxy is the webNginx setting: something in front wrote the Host
	// header, so it is not by itself the browser's statement of where it went.
	BehindProxy bool
	// PanelDomain is webDomain, "" when unset.
	PanelDomain string
	// Port is webPort. Together with an address no browser out on the internet
	// could have dialled, it is what tells the panel's own upstream socket from
	// a name something in front forwarded; see hostIsOwnSocket.
	Port int
}

SameOrigin rejects state-changing requests that did not come from the panel's own pages.

The session is a cookie, so without this any page the operator visits while logged in can post to the panel in their name -- add a client, change the password, import a database. SameSite on the cookie already covers current browsers; this is the half that does not depend on the browser being current, and it is what answers a request that arrives with an Origin from somewhere else.

Only the hostname is compared -- never a hardcoded scheme, and never the port. The panel has to work on plain HTTP as well as HTTPS, and behind a TLS-terminating proxy the scheme the browser used and the one the panel sees differ anyway, so requiring https here would reject every legitimate request in two of the three deployments. The port is dropped for the same kind of reason: nginx's $host, which the vhost this panel generates forwards as Host, carries no port, while the browser's Origin carries the one it actually dialled -- so comparing them whole rejects every write on a proxied panel reachable on anything but 443. DomainValidator already strips the port before its own comparison, for the same deployment.

Options carries what the panel knows about its own public identity. All of it is read once when the router is built, the way DomainValidator is: changing any of these already needs a panel restart, since that is what rebuilds the router.

Jump to

Keyboard shortcuts

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