Add nested rules Add backend action, allow wildcard in backends Remove poison from tree, update README with action table Allow defining pass/fail actions on challenge, Remove redirect/referer parameters on backend pass Set challenge cookie tied to host Rewrite DNSBL condition into a challenge Allow passing an arbitrary path for assets to js challenges Optimize programs exhaustively on compilation Activation instead of map for CEL context, faster map access, new network override Return valid host on cookie setting in case Host is an IP address. bug: does not work with IPv6, see https://github.com/golang/go/issues/65521 Apply TLS fingerprinter on GetConfigForClient instead of GetCertificate Cleanup go-away cookies before passing to backend Code action for specifically replying with an HTTP code
42 lines
920 B
Go
42 lines
920 B
Go
package utils
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
var CookiePrefix = ".go-away-"
|
|
|
|
// getValidHost Gets a valid host for an http.Cookie Domain field
|
|
// TODO: bug: does not work with IPv6, see https://github.com/golang/go/issues/65521
|
|
func getValidHost(host string) string {
|
|
ipStr, _, err := net.SplitHostPort(host)
|
|
if err != nil {
|
|
return host
|
|
}
|
|
return ipStr
|
|
}
|
|
|
|
func SetCookie(name, value string, expiry time.Time, w http.ResponseWriter, r *http.Request) {
|
|
http.SetCookie(w, &http.Cookie{
|
|
Name: name,
|
|
Value: value,
|
|
Expires: expiry,
|
|
SameSite: http.SameSiteLaxMode,
|
|
Path: "/",
|
|
Domain: getValidHost(r.Host),
|
|
})
|
|
}
|
|
|
|
func ClearCookie(name string, w http.ResponseWriter, r *http.Request) {
|
|
http.SetCookie(w, &http.Cookie{
|
|
Name: name,
|
|
Value: "",
|
|
Expires: time.Now().Add(-1 * time.Hour),
|
|
MaxAge: -1,
|
|
SameSite: http.SameSiteLaxMode,
|
|
Domain: getValidHost(r.Host),
|
|
})
|
|
}
|