Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support customizing session cookie name. #7072

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion internal/home/authhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ import (
// cookieTTL is the time-to-live of the session cookie.
const cookieTTL = 365 * timeutil.Day

// defaultSessionCookieName is the default name of the session cookie.
const defaultSessionCookieName = "agh_session"

// sessionCookieName is the name of the session cookie.
const sessionCookieName = "agh_session"
var sessionCookieName = defaultSessionCookieName

// loginJSON is the JSON structure for authentication.
type loginJSON struct {
Expand Down
11 changes: 11 additions & 0 deletions internal/home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"path/filepath"
"runtime"
"slices"
"strings"
"sync"
"syscall"
"time"
Expand Down Expand Up @@ -270,6 +271,14 @@ func setupOpts(opts options) (err error) {
return nil
}

// setupAghUISettings sets up some AdGuard Home UI settings.
func setupAghUISettings(opts options) {
cookieName := strings.TrimSpace(opts.sessionCookieName)
if cookieName != "" {
sessionCookieName = cookieName
}
}

// initContextClients initializes Context clients and related fields.
func initContextClients() (err error) {
err = setupDNSFilteringConf(config.Filtering)
Expand Down Expand Up @@ -573,6 +582,8 @@ func run(opts options, clientBuildFS fs.FS, done chan struct{}) {
err = setupOpts(opts)
fatalOnError(err)

setupAghUISettings(opts)

execPath, err := os.Executable()
fatalOnError(errors.Annotate(err, "getting executable path: %w"))

Expand Down
16 changes: 16 additions & 0 deletions internal/home/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ type options struct {
// bindAddr is the address to serve the web UI on.
bindAddr netip.AddrPort

// sessionCookieName is the name of the session cookie for the web UI.
// Customizing this value can prevent cookie key conflict for multiple AdGuardHome instances that have the same domain.
sessionCookieName string

// checkConfig is true if the current invocation is only required to check
// the configuration file and exit.
checkConfig bool
Expand Down Expand Up @@ -196,6 +200,18 @@ var cmdLineOpts = []cmdLineOpt{{
description: "Address to serve the web UI on, in the host:port format.",
longName: "web-addr",
shortName: "",
}, {
updateWithValue: func(o options, v string) (oo options, err error) {
o.sessionCookieName = v

return o, nil
},
updateNoValue: nil,
effect: nil,
serialize: func(o options) (val string, ok bool) { return o.sessionCookieName, o.sessionCookieName != "" },
description: "Customize the session cookie name for the web UI.",
longName: "session-cookie-name",
shortName: "",
}, {
updateWithValue: func(o options, v string) (options, error) {
o.serviceControlAction = v
Expand Down