Skip to content
Merged
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
17 changes: 17 additions & 0 deletions workspace-server/internal/handlers/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

"github.com/Molecule-AI/molecule-monorepo/platform/internal/db"
"github.com/Molecule-AI/molecule-monorepo/platform/internal/middleware"
"github.com/Molecule-AI/molecule-monorepo/platform/internal/provisioner"
"github.com/Molecule-AI/molecule-monorepo/platform/internal/registry"
"github.com/Molecule-AI/molecule-monorepo/platform/internal/wsauth"
Expand Down Expand Up @@ -329,6 +330,22 @@ func validateDiscoveryCaller(ctx context.Context, c *gin.Context, workspaceID st
if !hasLive {
return nil // legacy / pre-upgrade
}

// Try session cookie auth first (SaaS canvas path).
// verifiedCPSession returns (valid, presented):
// - (false, false) = no cookie, fall through to bearer
// - (true, true) = valid session, allow
// - (false, true) = cookie presented but invalid, 401
if cookieHeader := c.GetHeader("Cookie"); cookieHeader != "" {
if ok, presented := middleware.VerifiedCPSession(cookieHeader); presented {
if ok {
return nil // session verified, allow
}
c.JSON(http.StatusUnauthorized, gin.H{"error": "invalid session"})
return errors.New("invalid session")
}
}

tok := wsauth.BearerTokenFromHeader(c.GetHeader("Authorization"))
if tok == "" {
c.JSON(http.StatusUnauthorized, gin.H{"error": "missing workspace auth token"})
Expand Down
8 changes: 8 additions & 0 deletions workspace-server/internal/middleware/session_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,11 @@ func verifiedCPSession(cookieHeader string) (valid, presented bool) {
sessionCachePut(key, true)
return true, true
}

// VerifiedCPSession is the exported alias for handlers/discovery.go.
// Internal-only deployments (self-hosted / dev) where CP_UPSTREAM_URL
// is unset get (false, true) so the session path is skipped and the
// bearer token path runs as normal.
func VerifiedCPSession(cookieHeader string) (valid, presented bool) {
return verifiedCPSession(cookieHeader)
}
Loading