Skip to content

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

Go

fix(auth): validate cli_callback to localhost and URL-encode callback param

yushen788ba502f621
diff --git a/apps/web/app/(auth)/login/page.tsx b/apps/web/app/(auth)/login/page.tsx
index 1638d29907..ee64ee30b4 100644
--- a/apps/web/app/(auth)/login/page.tsx
+++ b/apps/web/app/(auth)/login/page.tsx
@@ -73,6 +73,19 @@ function LoginPageContent() {
const cliCallback = searchParams.get("cli_callback");
if (cliCallback) {
// CLI browser login: verify code, get JWT, redirect to CLI callback.
+ // Only allow localhost callbacks to prevent open redirect / JWT theft.
+ try {
+ const cbUrl = new URL(cliCallback);
+ if (cbUrl.hostname !== "localhost" && cbUrl.hostname !== "127.0.0.1") {
+ setError("Invalid callback URL");
+ setSubmitting(false);
+ return;
+ }
+ } catch {
+ setError("Invalid callback URL");
+ setSubmitting(false);
+ return;
+ }
const { token } = await api.verifyCode(email, value);
const separator = cliCallback.includes("?") ? "&" : "?";
window.location.href = `${cliCallback}${separator}token=${encodeURIComponent(token)}`;
diff --git a/server/cmd/multica/cmd_auth.go b/server/cmd/multica/cmd_auth.go
index 09734c306d..3f8d98efcc 100644
--- a/server/cmd/multica/cmd_auth.go
+++ b/server/cmd/multica/cmd_auth.go
@@ -6,6 +6,7 @@ import (
"fmt"
"net"
"net/http"
+ "net/url"
"os"
"os/exec"
"runtime"
@@ -55,9 +56,8 @@ func resolveToken() string {
return cfg.Token
}
-func resolveAppURL(cmd *cobra.Command) string {
- val := cli.FlagOrEnv(cmd, "", "MULTICA_APP_URL", "")
- if val != "" {
+func resolveAppURL() string {
+ if val := strings.TrimSpace(os.Getenv("MULTICA_APP_URL")); val != "" {
return strings.TrimRight(val, "/")
}
return "http://localhost:3000"
@@ -92,7 +92,7 @@ func runAuthLogin(cmd *cobra.Command, _ []string) error {
func runAuthLoginBrowser(cmd *cobra.Command) error {
serverURL := resolveServerURL(cmd)
- appURL := resolveAppURL(cmd)
+ appURL := resolveAppURL()
// Start a local HTTP server on a random port to receive the callback.
listener, err := net.Listen("tcp", "127.0.0.1:0")
@@ -103,7 +103,7 @@ func runAuthLoginBrowser(cmd *cobra.Command) error {
port := listener.Addr().(*net.TCPAddr).Port
callbackURL := fmt.Sprintf("http://localhost:%d/callback", port)
- loginURL := fmt.Sprintf("%s/login?cli_callback=%s", appURL, callbackURL)
+ loginURL := fmt.Sprintf("%s/login?cli_callback=%s", appURL, url.QueryEscape(callbackURL))
// Channel to receive the JWT from the browser callback.
jwtCh := make(chan string, 1)