Skip to content
Closed
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
33 changes: 20 additions & 13 deletions app/controlplane/internal/service/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ type AuthService struct {
orgInvitesUseCase *biz.OrgInvitationUseCase
AuthURLs *AuthURLs
auditorUseCase *biz.AuditorUseCase
devMode bool
}

func NewAuthService(userUC *biz.UserUseCase, orgUC *biz.OrganizationUseCase, mUC *biz.MembershipUseCase, inviteUC *biz.OrgInvitationUseCase, authConfig *conf.Auth, serverConfig *conf.Server, auc *biz.AuditorUseCase, opts ...NewOpt) (*AuthService, error) {
Expand Down Expand Up @@ -151,6 +152,7 @@ func NewAuthService(userUC *biz.UserUseCase, orgUC *biz.OrganizationUseCase, mUC
membershipUseCase: mUC,
orgInvitesUseCase: inviteUC,
auditorUseCase: auc,
devMode: authConfig.DevUser != "",
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Development-mode detection is tied to DevUser, so the cookie fix is not applied in the default dev config where dev_user is empty.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At app/controlplane/internal/service/auth.go, line 155:

<comment>Development-mode detection is tied to `DevUser`, so the cookie fix is not applied in the default dev config where `dev_user` is empty.</comment>

<file context>
@@ -151,6 +152,7 @@ func NewAuthService(userUC *biz.UserUseCase, orgUC *biz.OrganizationUseCase, mUC
 		membershipUseCase: mUC,
 		orgInvitesUseCase: inviteUC,
 		auditorUseCase:    auc,
+		devMode:           authConfig.DevUser != "",
 	}, nil
 }
</file context>
Fix with Cubic

}, nil
}

Expand Down Expand Up @@ -223,13 +225,13 @@ func loginHandler(svc *AuthService, w http.ResponseWriter, r *http.Request) *oau

// Store a random string to check it in the oauth callback
state := base64.URLEncoding.EncodeToString(b)
setOauthCookie(w, cookieOauthStateName, state)
svc.setOauthCookie(w, cookieOauthStateName, state)

// Store the final destination where the auth token will be pushed to, i.e the CLI
setOauthCookie(w, cookieCallback, r.URL.Query().Get(oauth.QueryParamCallback))
svc.setOauthCookie(w, cookieCallback, r.URL.Query().Get(oauth.QueryParamCallback))

// Wether the token should be short lived or not
setOauthCookie(w, cookieLongLived, r.URL.Query().Get(oauth.QueryParamLongLived))
svc.setOauthCookie(w, cookieLongLived, r.URL.Query().Get(oauth.QueryParamLongLived))

authorizationURI := svc.authenticator.AuthCodeURL(state)

Expand Down Expand Up @@ -433,16 +435,21 @@ func generateUserJWT(userID, passphrase string, expiration time.Duration) (strin
return b.GenerateJWT(userID)
}

func setOauthCookie(w http.ResponseWriter, name, value string) {
http.SetCookie(w, &http.Cookie{
Name: name,
Value: value,
Path: "/",
Expires: time.Now().Add(10 * time.Minute),
HttpOnly: true,
Secure: true,
SameSite: http.SameSiteLaxMode,
})
func (svc *AuthService) setOauthCookie(w http.ResponseWriter, name, value string) {
c := &http.Cookie{
Name: name,
Value: value,
Path: "/",
Expires: time.Now().Add(10 * time.Minute),
}

if !svc.devMode {
c.HttpOnly = true
c.Secure = true
c.SameSite = http.SameSiteLaxMode
}

http.SetCookie(w, c)
}

func generateAndLogDevUser(userUC *biz.UserUseCase, log *log.Helper, authConfig *conf.Auth) error {
Expand Down
Loading