Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(auth): strictly whitelist dynamic client registration redirect URIs (#20033)

Danny Xuedb237016951
diff --git a/backend/api/oauth2/oauth2.go b/backend/api/oauth2/oauth2.go
index 22a0b4a492..a4e0572006 100644
--- a/backend/api/oauth2/oauth2.go
+++ b/backend/api/oauth2/oauth2.go
@@ -179,10 +179,31 @@ func isLocalhostURI(uri string) bool {
if err != nil {
return false
}
+ if parsed.Scheme != "http" && parsed.Scheme != "https" {
+ return false
+ }
host := parsed.Hostname()
return host == "localhost" || host == "127.0.0.1" || host == "::1"
}
+func isAllowedDynamicClientRedirectURI(uri string) bool {
+ parsed, err := url.Parse(uri)
+ if err != nil {
+ return false
+ }
+
+ switch parsed.Scheme {
+ case "http", "https":
+ return isLocalhostURI(uri)
+ case "cursor", "vscode", "vscode-insiders":
+ return true
+ case "jetbrains":
+ return parsed.Host == "gateway" && parsed.Path != "" && parsed.Path != "/"
+ default:
+ return false
+ }
+}
+
func oauth2Error(c *echo.Context, statusCode int, errorCode, description string) error {
return c.JSON(statusCode, map[string]string{
"error": errorCode,
diff --git a/backend/api/oauth2/register.go b/backend/api/oauth2/register.go
index 6121c4cd44..5df68f7502 100644
--- a/backend/api/oauth2/register.go
+++ b/backend/api/oauth2/register.go
@@ -2,7 +2,6 @@ package oauth2
import (
"net/http"
- "net/url"
"slices"
"github.com/labstack/echo/v5"
@@ -45,13 +44,8 @@ func (s *Service) handleRegister(c *echo.Context) error {
return oauth2Error(c, http.StatusBadRequest, "invalid_client_metadata", "redirect_uris is required")
}
for _, uri := range req.RedirectURIs {
- parsed, err := url.Parse(uri)
- if err != nil {
- return oauth2Error(c, http.StatusBadRequest, "invalid_redirect_uri", "invalid redirect URI format")
- }
- // Reject plain HTTP except for localhost (allow HTTPS and custom schemes like cursor://, vscode://)
- if parsed.Scheme == "http" && !isLocalhostURI(uri) {
- return oauth2Error(c, http.StatusBadRequest, "invalid_redirect_uri", "http:// redirect URIs are only allowed for localhost")
+ if !isAllowedDynamicClientRedirectURI(uri) {
+ return oauth2Error(c, http.StatusBadRequest, "invalid_redirect_uri", "redirect URI must be a localhost URL or a whitelisted app scheme (cursor://, vscode://, vscode-insiders://, jetbrains://gateway/...)")
}
}