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.