Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-8577 fix(auth): reject unsupported CLI callbacks without web login fallback (#9906)

SUBARUAWA48672f9a391bf00
diff --git a/SELF_HOSTING_ADVANCED.md b/SELF_HOSTING_ADVANCED.md
index 786c4e0907..74509091df 100644
--- a/SELF_HOSTING_ADVANCED.md
+++ b/SELF_HOSTING_ADVANCED.md
@@ -327,6 +327,15 @@ These are configured on each user's machine, not on the server:
| `MULTICA_DAEMON_WS_CLAIM_POLL_INTERVAL` | `3m` | Upper bound for healthy WebSocket claim safety polls, configured independently of `MULTICA_DAEMON_POLL_INTERVAL`; downward jitter keeps normal polls at `2m30s`–`2m45s`, while old servers and uncertain claims retain the ordinary poll interval |
| `MULTICA_DAEMON_HEARTBEAT_INTERVAL` | `15s` | Heartbeat frequency |
+Browser login callbacks accept only `localhost`, `127.0.0.1`, and RFC 1918
+IPv4 addresses. If route detection selects an unsupported virtual-adapter
+address (for example `198.18.0.1`), login stops before opening the browser.
+When the browser and CLI run on the same machine, retry with
+`multica login --callback-host 127.0.0.1`. For a browser on another LAN machine,
+use `--callback-host <CLI-machine-LAN-IPv4>`; SSH-only machines can use token
+login or the printed SSH tunnel instructions. The login page reports invalid
+callback links instead of treating them as ordinary web sign-ins.
+
Agent-specific overrides:
| Variable | Description |
diff --git a/apps/web/app/(auth)/login/page.test.tsx b/apps/web/app/(auth)/login/page.test.tsx
index e80a2f67b8..7c2dd027a8 100644
--- a/apps/web/app/(auth)/login/page.test.tsx
+++ b/apps/web/app/(auth)/login/page.test.tsx
@@ -99,6 +99,30 @@ describe("LoginPage", () => {
mockListMyInvitations.mockResolvedValue([]);
});
+ it.each([null, { id: "u1", email: "[email protected]" }])(
+ "blocks invalid CLI callbacks even with an existing session: %j",
+ (user) => {
+ searchParamsState.params = new URLSearchParams({
+ cli_callback: "http://198.18.0.1:46233/callback",
+ cli_state: "test-state",
+ platform: "desktop",
+ });
+ authStateRef.state.user = user;
+ render(<LoginPage />, { wrapper: createWrapper() });
+ expect(screen.getByText("CLI authorization incomplete")).toBeInTheDocument();
+ expect(screen.queryByLabelText("Email")).not.toBeInTheDocument();
+ expect(mockIssueCliToken).not.toHaveBeenCalled();
+ expect(mockPush).not.toHaveBeenCalled();
+ expect(mockReplace).not.toHaveBeenCalled();
+ },
+ );
+
+ it("blocks an explicitly empty CLI callback", () => {
+ searchParamsState.params = new URLSearchParams({ cli_callback: "" });
+ render(<LoginPage />, { wrapper: createWrapper() });
+ expect(screen.getByText("CLI authorization incomplete")).toBeInTheDocument();
+ });
+
// Shared LoginPage behavior is canonical in
// packages/views/auth/login-page.test.tsx. This wrapper suite only owns web
// platform handoff and redirect behavior.
diff --git a/apps/web/app/(auth)/login/page.tsx b/apps/web/app/(auth)/login/page.tsx
index 57820a276b..e73a724744 100644
--- a/apps/web/app/(auth)/login/page.tsx
+++ b/apps/web/app/(auth)/login/page.tsx
@@ -25,6 +25,7 @@ import {
} from "@multica/ui/components/ui/card";
import { Button } from "@multica/ui/components/ui/button";
import { Loader2 } from "@multica/ui/icons";
+import { CliCallbackError } from "@/features/auth/cli-callback-error";
import { setLoggedInCookie } from "@/features/auth/auth-cookie";
import Link from "next/link";
import { LoginPage, validateCliCallback } from "@multica/views/auth";
@@ -67,8 +68,9 @@ function LoginPageContent() {
const cliCallbackRaw = searchParams.get("cli_callback");
const cliState = searchParams.get("cli_state") || "";
+ const invalidCliCallback = cliCallbackRaw !== null && !validateCliCallback(cliCallbackRaw);
const platform = searchParams.get("platform");
- const isDesktopHandoff = platform === "desktop" && !cliCallbackRaw;
+ const isDesktopHandoff = platform === "desktop" && cliCallbackRaw === null;
// `next` carries a protected URL the user was originally headed to
// (e.g. /invite/{id}). With URL-driven workspaces there is no legacy
// "/issues" default — if `next` is absent we decide after login based on
@@ -94,7 +96,7 @@ function LoginPageContent() {
settledLoggedOutRef.current = true;
return;
}
- if (cliCallbackRaw) return;
+ if (cliCallbackRaw !== null) return;
if (isDesktopHandoff) {
// Desktop opened the browser for login but the web session is already
// authenticated — mint a bearer token from the cookie session and hand
@@ -165,6 +167,8 @@ function LoginPageContent() {
.filter(Boolean)
.join(",") || undefined;
+ if (invalidCliCallback) return <CliCallbackError />;
+
// While the desktop handoff is in progress (or has produced a token/error),
// render a dedicated screen instead of flashing the login form or redirecting
// away to a workspace page.
diff --git a/apps/web/app/auth/callback/callback-error.ts b/apps/web/app/auth/callback/callback-error.ts
index 3f542cd591..05cf1ddeb1 100644
--- a/apps/web/app/auth/callback/callback-error.ts
+++ b/apps/web/app/auth/callback/callback-error.ts
@@ -3,6 +3,7 @@ import { ApiError, clientErrorMessage, errorCode } from "@multica/core/api";
export type CallbackError =
| {
kind:
+ | "invalid_cli_callback"
| "missing_code"
| "access_denied"
| "login_failed"
diff --git a/apps/web/app/auth/callback/page.test.tsx b/apps/web/app/auth/callback/page.test.tsx
index 43f658dddb..b5b1acf983 100644
--- a/apps/web/app/auth/callback/page.test.tsx
+++ b/apps/web/app/auth/callback/page.test.tsx
@@ -396,21 +396,21 @@ describe("CallbackPage", () => {
}
});
- it("falls through to normal web flow when state contains invalid cli_callback", async () => {
- mockSearchParams.set("state", "cli_callback:https://evil.com/callback");
- mockLoginWithGoogle.mockResolvedValue(makeUser());
- mockListWorkspaces.mockResolvedValue([]);
- mockListMyInvitations.mockResolvedValue([]);
-
+ it.each([
+ "cli_callback:https://evil.com/callback",
+ "cli_callback:http://198.18.0.1:46233/callback",
+ "platform:desktop,cli_callback:http://198.18.0.1:46233/callback",
+ "cli_callback:",
+ "cli_callback:%broken",
+ "cli_callback:http://localhost:46233/callback,cli_state:%broken",
+ ])("blocks an invalid CLI OAuth handoff without logging into the web: %s", async (state) => {
+ const { api: mockedApi } = await import("@multica/core/api");
+ mockSearchParams.set("state", state);
renderCallback();
-
- await waitFor(() => {
- // Normal web flow: loginWithGoogle is called (not googleLogin)
- expect(mockLoginWithGoogle).toHaveBeenCalled();
- });
- await waitFor(() => {
- expect(mockPush).toHaveBeenCalledWith(paths.onboarding());
- });
+ expect(await screen.findByText("CLI authorization incomplete")).toBeInTheDocument();
+ expect(mockLoginWithGoogle).not.toHaveBeenCalled();
+ expect(mockedApi.googleLogin).not.toHaveBeenCalled();
+ expect(mockPush).not.toHaveBeenCalled();
});
it("redirects to CLI callback even when state also contains platform:desktop", async () => {
diff --git a/apps/web/app/auth/callback/page.tsx b/apps/web/app/auth/callback/page.tsx
index bdbd8f7795..118051b1fe 100644
--- a/apps/web/app/auth/callback/page.tsx
+++ b/apps/web/app/auth/callback/page.tsx
@@ -19,6 +19,7 @@ import {
import { Button } from "@multica/ui/components/ui/button";
import { useT } from "@multica/views/i18n";
import { Loader2 } from "@multica/ui/icons";
+import { CliCallbackError } from "@/features/auth/cli-callback-error";
import { callbackErrorFrom, type CallbackError } from "./callback-error";
const authLogger = createLogger("auth.callback");
@@ -63,22 +64,26 @@ function CallbackContent() {
// Google auth completes.
const cliCallbackPart = stateParts.find((p) => p.startsWith("cli_callback:"));
const cliStatePart = stateParts.find((p) => p.startsWith("cli_state:"));
- const cliCallbackRaw = cliCallbackPart
- ? decodeURIComponent(cliCallbackPart.slice("cli_callback:".length))
- : null;
- const cliState = cliStatePart
- ? decodeURIComponent(cliStatePart.slice("cli_state:".length))
- : "";
+ let cliCallback: string | null = null;
+ let cliState = "";
+ try {
+ if (cliCallbackPart !== undefined) {
+ cliCallback = decodeURIComponent(cliCallbackPart.slice("cli_callback:".length));
+ if (!validateCliCallback(cliCallback)) {
+ setError({ kind: "invalid_cli_callback" });
+ return;
+ }
+ }
+ if (cliStatePart !== undefined) {
+ cliState = decodeURIComponent(cliStatePart.slice("cli_state:".length));
+ }
+ } catch {
+ setError({ kind: "invalid_cli_callback" });
+ return;
+ }
const redirectUri = `${window.location.origin}/auth/callback`;
- // Validate the CLI callback URL before redirecting — the state parameter
- // passes through Google OAuth and must be treated as attacker-controlled.
- const cliCallback =
- cliCallbackRaw && validateCliCallback(cliCallbackRaw)
- ? cliCallbackRaw
- : null;
-
if (cliCallback) {
// CLI login flow: exchange the Google code for a JWT, then redirect the
// token back to the CLI's local HTTP listener (e.g. WSL2 host).
@@ -160,6 +165,8 @@ function CallbackContent() {
const errorDescription = (() => {
if (!error) return null;
switch (error.kind) {
+ case "invalid_cli_callback":
+ return null;
case "raw":
return error.text;
case "missing_code":
@@ -208,6 +215,8 @@ function CallbackContent() {
);
}
+ if (error?.kind === "invalid_cli_callback") return <CliCallbackError />;
+
if (error) {
return (
<div className="flex min-h-screen items-center justify-center">
diff --git a/apps/web/features/auth/cli-callback-error.tsx b/apps/web/features/auth/cli-callback-error.tsx
new file mode 100644
index 0000000000..e3b6baa407
--- /dev/null
+++ b/apps/web/features/auth/cli-callback-error.tsx
@@ -0,0 +1,27 @@
+"use client";
+
+import {
+ Card,
+ CardHeader,
+ CardTitle,
+ CardDescription,
+} from "@multica/ui/components/ui/card";
+import { useT } from "@multica/views/i18n";
+
+export function CliCallbackError() {
+ const { t } = useT("auth");
+ return (
+ <div className="flex min-h-screen items-center justify-center">
+ <Card className="w-full max-w-sm" role="alert">
+ <CardHeader className="text-center">
+ <CardTitle className="text-display-sm">
+ {t(($) => $.web.cli_callback.failed_title)}
+ </CardTitle>
+ <CardDescription>
+ {t(($) => $.web.cli_callback.invalid_description)}
+ </CardDescription>
+ </CardHeader>
+ </Card>
+ </div>
+ );
+}
diff --git a/packages/views/auth/login-page.test.tsx b/packages/views/auth/login-page.test.tsx
index 358605d4ff..316edcb5f5 100644
--- a/packages/views/auth/login-page.test.tsx
+++ b/packages/views/auth/login-page.test.tsx
@@ -772,6 +772,13 @@ describe("validateCliCallback", () => {
expect(validateCliCallback("http://192.169.1.1:9876/callback")).toBe(false);
});
+ it.each(["198.18.0.1", "100.64.0.1", "169.254.1.1", "[::1]", "[fd00::1]"])(
+ "rejects unsupported callback address %s",
+ (host) => {
+ expect(validateCliCallback(`http://${host}:9876/callback`)).toBe(false);
+ },
+ );
+
it("rejects invalid URLs", () => {
expect(validateCliCallback("not-a-url")).toBe(false);
});
diff --git a/packages/views/locales/en/auth.json b/packages/views/locales/en/auth.json
index 4560ad45bf..9130d4e29b 100644
--- a/packages/views/locales/en/auth.json
+++ b/packages/views/locales/en/auth.json
@@ -36,6 +36,10 @@
"web": {
"prefer_desktop": "Prefer the desktop app?",
"download": "Download",
+ "cli_callback": {
+ "failed_title": "CLI authorization incomplete",
+ "invalid_description": "The CLI callback address is invalid. Return to the terminal and restart login with --callback-host 127.0.0.1 if the browser runs on the CLI machine, or use the CLI machine’s RFC 1918 LAN IPv4 address."
+ },
"desktop_handoff": {
"preparing": "Preparing Desktop sign-in...",
"opening_title": "Opening Multica",
diff --git a/packages/views/locales/fr/auth.json b/packages/views/locales/fr/auth.json
index 44fcf8456c..e7dbad1cea 100644
--- a/packages/views/locales/fr/auth.json
+++ b/packages/views/locales/fr/auth.json
@@ -36,6 +36,10 @@
"web": {
"prefer_desktop": "Vous préférez l'application de bureau ?",
"download": "Télécharger",
+ "cli_callback": {
+ "failed_title": "Autorisation CLI incomplète",
+ "invalid_description": "L’adresse de rappel CLI est invalide. Retournez au terminal et relancez la connexion avec --callback-host 127.0.0.1 si le navigateur et la CLI utilisent la même machine. Sinon, utilisez l’adresse IPv4 LAN RFC 1918 de la machine exécutant la CLI."
+ },
"desktop_handoff": {
"preparing": "Préparation de la connexion à l'application de bureau...",
"opening_title": "Ouverture de Multica",
diff --git a/packages/views/locales/ja/auth.json b/packages/views/locales/ja/auth.json
index 0eba723da8..829f71dc88 100644
--- a/packages/views/locales/ja/auth.json
+++ b/packages/views/locales/ja/auth.json
@@ -36,6 +36,10 @@
"web": {
"prefer_desktop": "デスクトップアプリをご利用ですか?",
"download": "ダウンロード",
+ "cli_callback": {
+ "failed_title": "CLI の認証が完了していません",
+ "invalid_description": "CLI のコールバックアドレスが無効です。ターミナルに戻り、ブラウザーと CLI が同じマシンで動作している場合は --callback-host 127.0.0.1 を指定して再ログインしてください。それ以外の場合は、CLI マシンの RFC 1918 LAN IPv4 アドレスを指定してください。"
+ },
"desktop_handoff": {
"preparing": "デスクトップのログインを準備中...",
"opening_title": "Multicaを開いています",
diff --git a/packages/views/locales/ko/auth.json b/packages/views/locales/ko/auth.json
index 68a7e6baf7..2ee797e18c 100644
--- a/packages/views/locales/ko/auth.json
+++ b/packages/views/locales/ko/auth.json
@@ -36,6 +36,10 @@
"web": {
"prefer_desktop": "데스크톱 앱을 선호하시나요?",
"download": "다운로드",
+ "cli_callback": {
+ "failed_title": "CLI 인증이 완료되지 않았습니다",
+ "invalid_description": "CLI 콜백 주소가 올바르지 않습니다. 터미널로 돌아가 다시 로그인하세요. 브라우저와 CLI가 같은 컴퓨터에서 실행 중이면 --callback-host 127.0.0.1을 사용하고, 그렇지 않으면 CLI 컴퓨터의 RFC 1918 LAN IPv4 주소를 사용하세요."
+ },
"desktop_handoff": {
"preparing": "데스크톱 로그인 준비 중...",
"opening_title": "Multica 여는 중",
diff --git a/packages/views/locales/zh-Hans/auth.json b/packages/views/locales/zh-Hans/auth.json
index a0ff6a2c89..d57903496e 100644
--- a/packages/views/locales/zh-Hans/auth.json
+++ b/packages/views/locales/zh-Hans/auth.json
@@ -36,6 +36,10 @@
"web": {
"prefer_desktop": "想用桌面应用?",
"download": "下载",
+ "cli_callback": {
+ "failed_title": "CLI 授权未完成",
+ "invalid_description": "CLI 回调地址无效。请返回终端重新登录:浏览器与 CLI 在同一台机器时使用 --callback-host 127.0.0.1,否则使用 CLI 所在机器的 RFC 1918 局域网 IPv4 地址。"
+ },
"desktop_handoff": {
"preparing": "正在准备桌面登录...",
"opening_title": "正在打开 Multica",
diff --git a/packages/views/locales/zh-Hant/auth.json b/packages/views/locales/zh-Hant/auth.json
index e1f2e048f3..b7f14d00b0 100644
--- a/packages/views/locales/zh-Hant/auth.json
+++ b/packages/views/locales/zh-Hant/auth.json
@@ -36,6 +36,10 @@
"web": {
"prefer_desktop": "想用桌面應用?",
"download": "下載",
+ "cli_callback": {
+ "failed_title": "CLI 授權未完成",
+ "invalid_description": "CLI 回呼位址無效。請返回終端機重新登入:瀏覽器與 CLI 在同一台機器時使用 --callback-host 127.0.0.1,否則使用 CLI 所在機器的 RFC 1918 區域網路 IPv4 位址。"
+ },
"desktop_handoff": {
"preparing": "正在準備桌面登入...",
"opening_title": "正在開啟 Multica",
diff --git a/server/cmd/multica/cmd_auth.go b/server/cmd/multica/cmd_auth.go
index cb5e7b9f64..7ad45efdf6 100644
--- a/server/cmd/multica/cmd_auth.go
+++ b/server/cmd/multica/cmd_auth.go
@@ -58,12 +58,13 @@ var authLogoutCmd = &cobra.Command{
RunE: runAuthLogout,
}
-// callbackHostFlag lets users override the host/IP that goes into the OAuth
-// cli_callback URL. Useful when the CLI sits behind a reverse proxy or the
-// auto-detected LAN IP isn't the one the browser can reach.
+// callbackHostFlag lets users override the host that goes into the OAuth
+// cli_callback URL when the auto-detected address isn't one the browser can
+// reach. The value must pass isSupportedCallbackHost; hostnames other than
+// localhost are rejected because the web login never accepts them.
const callbackHostFlag = "callback-host"
-const callbackHostFlagHelp = "Host/IP the OAuth callback URL points at when the browser can reach this CLI directly. For SSH-only machines, use the printed tunnel hint instead."
+const callbackHostFlagHelp = "Callback host reachable from the browser: localhost, 127.0.0.1, or an RFC 1918 IPv4 address. For SSH-only machines, use the printed tunnel hint instead."
func init() {
authCmd.AddCommand(authStatusCmd)
@@ -152,16 +153,19 @@ func runAuthLogin(cmd *cobra.Command, args []string) error {
// - self-host, CLI on server box: same as above.
// - self-host, CLI on a different LAN box: the callback URL must point at
// the CLI's own LAN IP, not the server's.
-// - reverse-proxied / FQDN setups: auto-detection can't know the right
-// host — the user supplies it via --callback-host.
+// - routes through a virtual adapter: the detected address may not be a
+// supported callback host; ask the user to supply --callback-host.
//
// detectOutbound is injected so tests can exercise the routing decisions
// without real network calls.
-func resolveCallbackBinding(flagHost, serverURL, appURL string, detectOutbound func(string) net.IP) (callbackHost, bindAddr string) {
+func resolveCallbackBinding(flagHost, serverURL, appURL string, detectOutbound func(string) net.IP) (callbackHost, bindAddr string, err error) {
// Explicit flag always wins. Bind on all interfaces so the browser can
// reach us regardless of which interface the host name resolves to.
if h := strings.TrimSpace(flagHost); h != "" {
- return h, "0.0.0.0"
+ if !isSupportedCallbackHost(h) {
+ return "", "", callbackHostError(h)
+ }
+ return h, "0.0.0.0", nil
}
appIP := urlPrivateIP(appURL)
@@ -169,7 +173,7 @@ func resolveCallbackBinding(flagHost, serverURL, appURL string, detectOutbound f
// Public hostname, FQDN without private-IP mapping, or parse error.
// Loopback is the only safe default — on hosted/public setups the
// browser and CLI live on the same machine.
- return "localhost", "127.0.0.1"
+ return "localhost", "127.0.0.1", nil
}
// app_url is a private LAN IP. Figure out whether the CLI is on that
@@ -180,12 +184,28 @@ func resolveCallbackBinding(flagHost, serverURL, appURL string, detectOutbound f
if cliIP == nil {
// Detection failed (offline, unreachable server, etc.). Fall back to
// the app IP — preserves the pre-existing same-machine behaviour.
- return appIP.String(), "0.0.0.0"
+ return appIP.String(), "0.0.0.0", nil
}
if cliIP.Equal(appIP) {
- return "localhost", "127.0.0.1"
+ return "localhost", "127.0.0.1", nil
+ }
+ if !isSupportedCallbackHost(cliIP.String()) {
+ return "", "", callbackHostError(cliIP.String())
+ }
+ return cliIP.String(), "0.0.0.0", nil
+}
+
+// Keep this host policy aligned with validateCliCallback in packages/views/auth.
+func isSupportedCallbackHost(host string) bool {
+ if host == "localhost" || host == "127.0.0.1" {
+ return true
}
- return cliIP.String(), "0.0.0.0"
+ ip := net.ParseIP(host)
+ return ip != nil && !strings.Contains(host, ":") && ip.To4() != nil && ip.IsPrivate()
+}
+
+func callbackHostError(host string) error {
+ return fmt.Errorf("cannot use %q as the login callback host: the web app accepts only localhost, 127.0.0.1, or RFC 1918 IPv4 addresses. If the browser runs on this machine, retry with --callback-host 127.0.0.1; otherwise use --callback-host <this-machine-LAN-IP> or sign in with multica login --token", host)
}
// urlPrivateIP returns the hostname of rawURL parsed as an RFC 1918 IP, or
@@ -196,7 +216,7 @@ func urlPrivateIP(rawURL string) net.IP {
return nil
}
ip := net.ParseIP(parsed.Hostname())
- if ip == nil || !ip.IsPrivate() {
+ if ip == nil || ip.To4() == nil || !ip.IsPrivate() {
return nil
}
return ip
@@ -240,11 +260,14 @@ func runAuthLoginBrowser(cmd *cobra.Command) error {
appURL := resolveAppURL(cmd)
flagHost := callbackHostFlagValue(cmd)
- callbackHost, bindAddr := resolveCallbackBinding(flagHost, serverURL, appURL, detectOutboundIP)
+ callbackHost, bindAddr, err := resolveCallbackBinding(flagHost, serverURL, appURL, detectOutboundIP)
+ if err != nil {
+ return err
+ }
// Pin to "tcp4" — a bare "tcp" on macOS can produce an IPv6-only socket
// that IPv4 clients (including browsers resolving localhost → 127.0.0.1)
- // cannot reach. The callback URL is always an IPv4 literal or hostname,
+ // cannot reach. The callback host is always localhost or an IPv4 literal,
// so an IPv4 listener is what the browser actually needs.
listener, err := net.Listen("tcp4", bindAddr+":0")
if err != nil {
diff --git a/server/cmd/multica/cmd_auth_test.go b/server/cmd/multica/cmd_auth_test.go
index 3a1ebac4d6..3772425849 100644
--- a/server/cmd/multica/cmd_auth_test.go
+++ b/server/cmd/multica/cmd_auth_test.go
@@ -86,7 +86,7 @@ func TestResolveCallbackBinding(t *testing.T) {
}
failing := func(string) net.IP { return nil }
- cases := []struct {
+ type bindingCase struct {
name string
flagHost string
serverURL string
@@ -94,7 +94,17 @@ func TestResolveCallbackBinding(t *testing.T) {
detect func(string) net.IP
wantCallback string
wantBind string
- }{
+ wantError bool
+ }
+ cases := []bindingCase{
+ {
+ name: "IPv6 app URL uses a supported loopback callback",
+ appURL: "http://[fd00::1]:3000",
+ detect: failing,
+ wantCallback: "localhost",
+ wantBind: "127.0.0.1",
+ },
+
{
name: "public app URL stays on loopback",
appURL: "https://multica.ai",
@@ -137,19 +147,35 @@ func TestResolveCallbackBinding(t *testing.T) {
},
{
name: "--callback-host flag overrides everything",
- flagHost: "cli.internal.example",
+ flagHost: "10.0.0.5",
appURL: "https://multica.ai",
serverURL: "https://api.multica.ai",
detect: fixed("10.0.0.5"),
- wantCallback: "cli.internal.example",
+ wantCallback: "10.0.0.5",
wantBind: "0.0.0.0",
},
}
+ for _, host := range []string{"198.18.0.1", "8.8.8.8", "100.64.0.1", "169.254.1.1", "::1", "fd00::1", "::ffff:192.168.0.1", "cli.internal.example", "localhost:1234", "[email protected]"} {
+ cases = append(cases, bindingCase{name: "unsupported explicit host " + host, flagHost: host, wantError: true})
+ }
+ for _, ip := range []string{"198.18.0.1", "8.8.8.8", "100.64.0.1", "169.254.1.1"} {
+ cases = append(cases, bindingCase{name: "unsupported outbound IP " + ip, appURL: "http://192.168.0.28:3000", detect: fixed(ip), wantError: true})
+ }
+
for _, tc := range cases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
- gotCallback, gotBind := resolveCallbackBinding(tc.flagHost, tc.serverURL, tc.appURL, tc.detect)
+ gotCallback, gotBind, err := resolveCallbackBinding(tc.flagHost, tc.serverURL, tc.appURL, tc.detect)
+ if tc.wantError {
+ if err == nil || !strings.Contains(err.Error(), "--callback-host") {
+ t.Fatalf("expected actionable callback error, got %v", err)
+ }
+ return
+ }
+ if err != nil {
+ t.Fatal(err)
+ }
if gotCallback != tc.wantCallback {
t.Errorf("callback host = %q, want %q", gotCallback, tc.wantCallback)
}