diff --git a/scripts/dev-fleet.sh b/scripts/dev-fleet.sh index 5ddeca8c2..fd0814200 100755 --- a/scripts/dev-fleet.sh +++ b/scripts/dev-fleet.sh @@ -210,7 +210,7 @@ inpanel curl -sS -m 40 -D "$STATE/setup.hdr" -o /dev/null -X POST "$ADMIN/api/mi -H 'Content-Type: application/json' \ -d "$(jq -nc --arg t "$SETUP_TOKEN" --arg c "$CEREMONY" --arg code "$(totp_code)" '{setupToken:$t, ceremonyId:$c, totpCode:$code}')" grep -q '^HTTP/[0-9.]* 200' "$STATE/setup.hdr" || die "FinishSetup failed: $(head -1 "$STATE/setup.hdr")" -COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(__Host-sid=[^;]*\).*/\1/p' "$STATE/setup.hdr" | tr -d '\r') +COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(\(__Host-\)\{0,1\}sid=[^;]*\).*/\1/p' "$STATE/setup.hdr" | tr -d '\r') [ -n "$COOKIE" ] || die "FinishSetup set no session cookie" api AuthService/Me | jq -e '.admin.id' >/dev/null || die "the session cookie does not work" say "panel up, first admin created" @@ -247,7 +247,7 @@ say "three nodes online (de1, nl1, fi1), a Hysteria2 inbound on each (UDP 4433, # ---------------------------------------------------------------- the owner's session for the token script, and the token umask 077 -( printf 'MG_ADMIN_URL=%s\nMG_OWNER_COOKIE=%s\nMG_TOTP_SECRET=%s\nMG_NETNS=%s\n' "$ADMIN" "${COOKIE#__Host-sid=}" "$TOTP_SECRET" mgdf-panel >"$STATE/owner.env" ) +( printf 'MG_ADMIN_URL=%s\nMG_OWNER_COOKIE=%s\nMG_TOTP_SECRET=%s\nMG_NETNS=%s\n' "$ADMIN" "${COOKIE#*=}" "$TOTP_SECRET" mgdf-panel >"$STATE/owner.env" ) echo say "admin URL: $ADMIN/ (loopback inside the namespace mgdf-panel: reach it with ip netns exec mgdf-panel )" if [ -z "$MCP_E2E" ]; then diff --git a/scripts/e2e-wsl.sh b/scripts/e2e-wsl.sh index 8e37b9389..574d57770 100644 --- a/scripts/e2e-wsl.sh +++ b/scripts/e2e-wsl.sh @@ -817,7 +817,7 @@ curl -sS -m 40 -D "$WORK/setup.hdr" -o /dev/null -X POST "$ADMIN/api/mistgate.ad -H 'Content-Type: application/json' \ -d "$(jq -nc --arg t "$SETUP_TOKEN" --arg c "$CEREMONY" --arg code "$(totp_code)" '{setupToken:$t, ceremonyId:$c, totpCode:$code}')" grep -q '^HTTP/[0-9.]* 200' "$WORK/setup.hdr" || die "FinishSetup failed: $(head -1 "$WORK/setup.hdr")" -COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(__Host-sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r') +COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(\(__Host-\)\{0,1\}sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r') [ -n "$COOKIE" ] || die "FinishSetup set no session cookie" SECRETS+=("${COOKIE#*=}") TOTP_LAST=$(($(date +%s) / 30)) STEPUP_UNTIL=$(($(date +%s) + 280)) # the sign-in just proved a factor: step-up is open for 5 minutes @@ -1597,7 +1597,7 @@ if [ -n "${HOLD:-}" ]; then [ -z "$EDGE" ] || die "--hold is for the VPS edition" ( umask 077 printf 'MG_ADMIN_URL=%s/\nMG_OWNER_COOKIE=%s\nMG_TOTP_SECRET=%s\nMG_NETNS=%s\n' \ - "$ADMIN" "${COOKIE#__Host-sid=}" "$TOTP_SECRET" "${MG_E2E_NS:-}" >"$WORK/owner.env" ) + "$ADMIN" "${COOKIE#*=}" "$TOTP_SECRET" "${MG_E2E_NS:-}" >"$WORK/owner.env" ) step "12. holding: the test panel stays up until Ctrl-C" say "admin $ADMIN/ (in network namespace ${MG_E2E_NS:-none}), owner session and authenticator secret in $WORK/owner.env" say "make an MCP token (from another shell): bash scripts/e2e/mcp-token.sh $WORK/owner.env" diff --git a/scripts/e2e/bridge.sh b/scripts/e2e/bridge.sh index f283c0fd0..67d68f27e 100644 --- a/scripts/e2e/bridge.sh +++ b/scripts/e2e/bridge.sh @@ -435,7 +435,7 @@ start_panel() { -H 'Content-Type: application/json' -d "$(jq -nc --arg t "$token" --arg c "$ceremony" --arg code "$(totp_code)" \ '{setupToken:$t,ceremonyId:$c,totpCode:$code}')" grep -q '^HTTP/[0-9.]* 200' "$WORK/setup.hdr" || die "first-admin setup failed" - COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(__Host-sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r') + COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(\(__Host-\)\{0,1\}sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r') [ -n "$COOKIE" ] || die "no session cookie" OWNER_STEP=$(($(date +%s) / 30)) OWNER_STEPUP_UNTIL=$(api AuthService/Me | jq -r '.stepUpUntilUnix // 0') diff --git a/scripts/e2e/censor.sh b/scripts/e2e/censor.sh index c6e540867..131da9141 100644 --- a/scripts/e2e/censor.sh +++ b/scripts/e2e/censor.sh @@ -303,7 +303,7 @@ inpanel curl -skS -m 30 -D "$WORK/setup.hdr" -o /dev/null -X POST "$ADMIN/api/mi -H 'Content-Type: application/json' -d "$(jq -nc --arg t "$SETUP_TOKEN" --arg c "$CEREMONY" --arg code "$(totp_code)" \ '{setupToken:$t,ceremonyId:$c,totpCode:$code}')" grep -q '^HTTP/[0-9.]* 200' "$WORK/setup.hdr" || die "first-admin setup failed" -COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(__Host-sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r') +COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(\(__Host-\)\{0,1\}sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r') [ -n "$COOKIE" ] || die "first-admin setup did not set a session cookie" ME=$(api AuthService/Me) jq -e '.admin.id' <<<"$ME" >/dev/null || die "the owner session does not work" @@ -440,10 +440,10 @@ python3 "$WORK/vless_to_xray.py" "$WORK/vless.uri" 10809 "$WORK/xray-op-b.json" chmod 600 "$WORK/xray-op-a.json" "$WORK/xray-op-b.json" # Mint the same admin-profile token a separate MCP client receives from the panel owner. -inpanel env MG_ADMIN_URL="$ADMIN" MG_OWNER_COOKIE="${COOKIE#__Host-sid=}" MG_TOTP_SECRET="$TOTP_SECRET" \ +inpanel env MG_ADMIN_URL="$ADMIN" MG_OWNER_COOKIE="${COOKIE#*=}" MG_TOTP_SECRET="$TOTP_SECRET" \ "$BIN/mcptoken" -profile admin -name censor-sim >"$MCP_TOKEN" 2>"$WORK/mcptoken.log" || die "could not mint the lab MCP token" OWNER_STEP=$(( $(date +%s) / 30 )) -printf 'MG_ADMIN_URL=%s\nMG_OWNER_COOKIE=%s\nMG_TOTP_SECRET=%s\n' "$ADMIN" "${COOKIE#__Host-sid=}" "$TOTP_SECRET" >>"$MCP_SECRETS" +printf 'MG_ADMIN_URL=%s\nMG_OWNER_COOKIE=%s\nMG_TOTP_SECRET=%s\n' "$ADMIN" "${COOKIE#*=}" "$TOTP_SECRET" >>"$MCP_SECRETS" chmod 600 "$MCP_TOKEN" "$MCP_SECRETS" say "profiles, owner settings and alice's test subscription are ready" diff --git a/scripts/e2e/edge.sh b/scripts/e2e/edge.sh index f6cbdd5d4..f35fadfdf 100644 --- a/scripts/e2e/edge.sh +++ b/scripts/e2e/edge.sh @@ -576,7 +576,7 @@ PY -H 'Content-Type: application/json' \ -d "$(jq -nc --arg t "$SETUP_TOKEN" --arg c "$CEREMONY" --arg code "$(totp_code)" '{setupToken:$t, ceremonyId:$c, totpCode:$code}')" grep -q '^HTTP/[0-9.]* 200' "$WORK/setup.hdr" || die "FinishSetup failed: $(head -1 "$WORK/setup.hdr")" - COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(__Host-sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r') + COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(\(__Host-\)\{0,1\}sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r') [ -n "$COOKIE" ] || die "FinishSetup set no session cookie" SECRETS+=("${COOKIE#*=}") TOTP_LAST=$(($(date +%s) / 30)) STEPUP_UNTIL=$(($(date +%s) + 280)) diff --git a/scripts/e2e/mcpe2e/main.go b/scripts/e2e/mcpe2e/main.go index 01f9a8b8a..7d2a6e2df 100644 --- a/scripts/e2e/mcpe2e/main.go +++ b/scripts/e2e/mcpe2e/main.go @@ -593,7 +593,7 @@ func (e *env) rpc(cookie, bearer, svc, method string, body any) (int, map[string req, _ := http.NewRequest("POST", e.admin+"api/mistgate.admin.v1."+svc+"/"+method, bytes.NewReader(b)) req.Header.Set("Content-Type", "application/json") if cookie != "" { - req.Header.Set("Cookie", "__Host-sid="+cookie) + req.Header.Set("Cookie", cookieName(e.admin)+"="+cookie) } if bearer != "" { req.Header.Set("Authorization", "Bearer "+bearer) @@ -650,7 +650,7 @@ func (e *env) signup(setupToken string) error { return fmt.Errorf("FinishSetup %d", resp.StatusCode) } for _, c := range resp.Cookies() { - if c.Name == "__Host-sid" { + if c.Name == cookieName(e.admin) { e.cookie = c.Value } } @@ -1306,3 +1306,11 @@ func (e *env) leaks() { } e.check(fmt.Sprintf("no secret in the panel log (%d bytes)", len(log)), len(lhit) == 0, "leaked: %v", lhit) } + +// cookieName is the session cookie of the admin listener: __Host-sid over HTTPS, sid on the plain-HTTP admin listener. +func cookieName(admin string) string { + if strings.HasPrefix(admin, "http://") { + return "sid" + } + return "__Host-sid" +} diff --git a/scripts/e2e/mcptoken/main.go b/scripts/e2e/mcptoken/main.go index b5b327b51..ac41c8654 100644 --- a/scripts/e2e/mcptoken/main.go +++ b/scripts/e2e/mcptoken/main.go @@ -75,7 +75,7 @@ func (c *client) rpc(svc, method string, body any) (int, map[string]any) { b, _ := json.Marshal(body) req, _ := http.NewRequest("POST", c.admin+"api/mistgate.admin.v1."+svc+"/"+method, bytes.NewReader(b)) req.Header.Set("Content-Type", "application/json") - req.Header.Set("Cookie", "__Host-sid="+c.cookie) + req.Header.Set("Cookie", cookieName(c.admin)+"="+c.cookie) resp, err := hc.Do(req) if err != nil { fail(err.Error()) @@ -123,3 +123,11 @@ func fail(msg string) { fmt.Fprintln(os.Stderr, "mcptoken:", msg) os.Exit(1) } + +// cookieName is the session cookie of the admin listener: __Host-sid over HTTPS, sid on the plain-HTTP admin listener. +func cookieName(admin string) string { + if strings.HasPrefix(admin, "http://") { + return "sid" + } + return "__Host-sid" +} diff --git a/scripts/e2e/probe.sh b/scripts/e2e/probe.sh index 485d167d9..b42d78ee9 100644 --- a/scripts/e2e/probe.sh +++ b/scripts/e2e/probe.sh @@ -341,7 +341,7 @@ inpanel curl -skS -m 30 -D "$WORK/setup.hdr" -o /dev/null -X POST "$ADMIN/api/mi -H 'Content-Type: application/json' -d "$(jq -nc --arg t "$SETUP_TOKEN" --arg c "$CEREMONY" --arg code "$(totp_code)" \ '{setupToken:$t,ceremonyId:$c,totpCode:$code}')" grep -q '^HTTP/[0-9.]* 200' "$WORK/setup.hdr" || die "first-admin setup failed" -COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(__Host-sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r') +COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(\(__Host-\)\{0,1\}sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r') [ -n "$COOKIE" ] || die "first-admin setup did not set a session cookie" ME=$(api AuthService/Me) jq -e '.admin.id' <<<"$ME" >/dev/null || die "the owner session does not work" diff --git a/scripts/e2e/sni443.sh b/scripts/e2e/sni443.sh index dabeab8a0..173c2ff2e 100644 --- a/scripts/e2e/sni443.sh +++ b/scripts/e2e/sni443.sh @@ -349,7 +349,7 @@ start_panel() { -H 'Content-Type: application/json' -d "$(jq -nc --arg t "$token" --arg c "$ceremony" --arg code "$(totp_code)" \ '{setupToken:$t,ceremonyId:$c,totpCode:$code}')" grep -q '^HTTP/[0-9.]* 200' "$WORK/setup.hdr" || die "first-admin setup failed" - COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(__Host-sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r') + COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(\(__Host-\)\{0,1\}sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r') [ -n "$COOKIE" ] || die "no session cookie" OWNER_STEP=$(($(date +%s) / 30)) OWNER_STEPUP_UNTIL=$(api AuthService/Me | jq -r '.stepUpUntilUnix // 0') diff --git a/scripts/e2e/trusttunnel.sh b/scripts/e2e/trusttunnel.sh index 421f59712..a1d6f4dd8 100644 --- a/scripts/e2e/trusttunnel.sh +++ b/scripts/e2e/trusttunnel.sh @@ -383,7 +383,7 @@ tt_hold() { MG_OWNER_COOKIE=%s MG_TOTP_SECRET=%s MG_NETNS=%s -' "$ADMIN" "${COOKIE#__Host-sid=}" "$TOTP_SECRET" "${MG_E2E_NS:-}" >"$WORK/owner.env" ) +' "$ADMIN" "${COOKIE#*=}" "$TOTP_SECRET" "${MG_E2E_NS:-}" >"$WORK/owner.env" ) say "the settings of both: $WORK/tt-dev.env; the admin API is $ADMIN, the owner session of this panel in $WORK/owner.env (0600). To switch a person off while a connection is open: POST /api/mistgate.admin.v1.UserService/SetUsersEnabled {"userIds":[TT_ALICE_USER_ID],"enabled":false} with the owner cookie and a fresh authenticator code of MG_TOTP_SECRET (a step-up, as the stand does in E5)" trap 'exit 0' INT TERM FINISHED=1 diff --git a/scripts/e2e/upgrade.sh b/scripts/e2e/upgrade.sh index 95de17d76..b001965c4 100644 --- a/scripts/e2e/upgrade.sh +++ b/scripts/e2e/upgrade.sh @@ -354,7 +354,7 @@ stage_seed() { curl -sS -m 40 -D "$WORK/setup.hdr" -o /dev/null -X POST "$ADMIN/api/mistgate.admin.v1.AuthService/FinishSetup" -H 'Content-Type: application/json' \ -d "$(jq -nc --arg t "$token" --arg c "$ceremony" --arg code "$(fresh_totp)" '{setupToken:$t, ceremonyId:$c, totpCode:$code}')" grep -q '^HTTP/[0-9.]* 200' "$WORK/setup.hdr" || die "FinishSetup failed" - COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(__Host-sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r') + COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(\(__Host-\)\{0,1\}sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r') STEPUP_UNTIL=$(($(date +%s) + 280)) save_state COOKIE ok "old panel up, owner created (password + authenticator code), signed in"